Plan Before Code: a Five-Part Brief, Plan Mode and /goal for a Spring Boot Feature
'Add overdue tasks to the API' makes the agent decide that due today is late. A five-part brief with a quality gate, plan mode, three answered questions and a /goal give an overdue endpoint with a fixed clock and six passing tests.
What you will learn
- See what a one-line ask makes the agent guess
- Write a five-part brief: role, ask, strict rules, quality gate, plan first
- Use plan mode to get a plan and questions before any file changes
- Turn the quality gate into a /goal the output can prove
Before you start
- The Project Context File: AGENTS.md and CLAUDE.md
- Java records and java.time
One habit saves a lot of time with a coding agent: before it writes a single line, give it a brief, read its plan and answer its questions. We'll do it on a small Spring Boot task API, for one small wish: which tasks are overdue?
The data: due date and done
package org.studyeasy.tasks;
import java.time.LocalDate;
// A record: the data and nothing else - equals, hashCode and toString come for free
public record Task(long id, String title, String assignee, LocalDate dueDate, boolean done) {
}
Every task has a due date and a done flag; false means still open. The service holds four tasks. If today is 28 October 2026: task 1 is due in five days, task 2 was due eight days ago, task 3 is done, and task 4 is due today. Overdue needs three things: the due date, done, and today.
The wish hides three questions. The sprint demo is due today: is it late already? The onboarding guide is done: late or not? And in which order should the list come? The code is a few lines. The decisions are the real work.
A one-line ask: the agent guesses
Add overdue tasks to the API.
Sent like this, the agent goes straight in and edits two files at once. No plan, no questions. It reports that it added /api/tasks/late, and it picked a rule for us: due today counts as late. Nobody asked for that, and no test was run. Every guess is a question it never asked.
The five-part brief
ROLE
You are a senior backend developer pairing with me on task-api. Write code a new
team member can read line by line, with short comments that say WHY.
ASK
I want the API to tell me which tasks are overdue. Each task has a dueDate and a
done flag (see Task.java): a task is open while done is false. You decide the URL,
the method names and where the logic lives, as long as you keep to the strict rules.
STRICT RULES
- Follow the house rules in AGENTS.md.
- "Today" comes from a clock we pass in, never read straight from the system.
- Change only TaskService, TaskController, TaskApplication and the tests.
- No new dependencies.
QUALITY GATE (done only when every line is true)
[ ] GET /api/tasks/overdue answers 200 with a JSON list.
[ ] A task due today is not overdue yet. A done task is never overdue.
[ ] Tests fix the date with a fixed clock, so they pass on any day.
[ ] The test command in AGENTS.md: the 3 old tests and the new ones pass.
PLAN FIRST
Before you write any code: list the files you will change, one line each, and
ask me every question you need answered. Then STOP and wait for my OK.
The role sets the bar for readable code. The ask is open: you say what you want and let the agent pick names. The strict rules are the few things it must not decide: house rules, a clock passed in, only these files, no new dependencies. The quality gate says what done means, line by line. Plan first asks for the file list and every question, then a stop.
Plan mode: plan, questions, answers, then code
In Claude Code, type /plan and paste the brief, or simply ask it to plan first and wait for your OK. The agent sends back a plan, and the project tree shows nothing changed. Until you say OK, nothing is edited. Here's that session:
EXAMPLE SESSION - the plan the agent sent back, and my answers (before any code)
PLAN
1. TaskApplication: add a clock (the system clock), so tests can replace "today".
2. TaskService: take the clock in the constructor; add overdue(): open tasks whose
due date is before today.
3. TaskController: add GET /api/tasks/overdue that returns service.overdue().
4. Tests: a unit test for the rule with a fixed clock, and one test for the
endpoint.
QUESTIONS
1. Is a task that is due today overdue?
2. Should the list be sorted, and by what?
3. Which time zone is "today" in?
MY ANSWERS
1. No. Overdue starts the day after the due date.
2. Yes, oldest due date first.
3. The server's default zone is fine for now.
OK, go ahead.
The three questions are exactly the rules the brief forgot to write. Now check the plan against the gate: the URL, the due-today rule, the fixed clock, the tests. Every line gets a tick, so you say OK. If the plan had touched a fifth file or skipped the tests, the answer would be "no, keep planning". Good answers go back into the brief, so next time the agent doesn't need to ask.
What the agent built
package org.studyeasy.tasks;
import java.time.Clock;
import java.time.LocalDate;
import java.util.Comparator;
import java.util.List;
import java.util.Optional;
import org.springframework.stereotype.Service;
@Service
public class TaskService {
// In memory on purpose: the lectures are about the workflow, not the database
private final List<Task> tasks = List.of(
new Task(1, "Write release notes", "Emma Clark", LocalDate.of(2026, 11, 2), false),
new Task(2, "Fix login timeout", "James Walker", LocalDate.of(2026, 10, 20), false),
new Task(3, "Update onboarding guide", "Olivia Bennett", LocalDate.of(2026, 10, 28), true),
new Task(4, "Prepare sprint demo", "Daniel Hughes", LocalDate.of(2026, 10, 28), false));
private final Clock clock;
// The clock is injected, so a test can say what "today" is
public TaskService(Clock clock) {
this.clock = clock;
}
public List<Task> findAll() {
return tasks;
}
public Optional<Task> findById(long id) {
return tasks.stream().filter(task -> task.id() == id).findFirst();
}
// Open tasks whose due date has passed: due today is not overdue yet
public List<Task> overdue() {
LocalDate today = LocalDate.now(clock);
return tasks.stream()
.filter(task -> !task.done())
.filter(task -> task.dueDate().isBefore(today))
.sorted(Comparator.comparing(Task::dueDate))
.toList();
}
}
The clock comes in through the constructor, so a test can say what "today" is. isBefore(today) is the answered rule: due today is not overdue yet. The controller gets one more mapping, @GetMapping("/overdue") returning service.overdue(). And the gate becomes tests:
package org.studyeasy.tasks;
import java.time.Clock;
import java.time.LocalDate;
import java.time.ZoneId;
import java.util.List;
import org.junit.jupiter.api.Test;
import static org.assertj.core.api.Assertions.assertThat;
// The quality gate as tests: a plain unit test, no Spring needed
class TaskServiceTest {
private static TaskService on(String day) {
ZoneId zone = ZoneId.systemDefault();
return new TaskService(Clock.fixed(LocalDate.parse(day).atStartOfDay(zone).toInstant(), zone));
}
private static List<Long> ids(List<Task> tasks) {
return tasks.stream().map(Task::id).toList();
}
@Test
void dueTodayIsNotOverdueYet() {
// Daniel's demo is due on 28 Oct: on that day only James's task is overdue
assertThat(ids(on("2026-10-28").overdue())).containsExactly(2L);
}
@Test
void doneTasksAreNeverOverdue() {
// On 5 Nov Olivia's guide is past its date too, but it is done: oldest first, without it
assertThat(ids(on("2026-11-05").overdue())).containsExactly(2L, 4L, 1L);
}
}
Running the test command from AGENTS.md on the finished project:
[INFO] Tests run: 1, Failures: 0, Errors: 0, Skipped: 0 ... in org.studyeasy.tasks.OverdueEndpointTest
[INFO] Tests run: 3, Failures: 0, Errors: 0, Skipped: 0 ... in org.studyeasy.tasks.TaskControllerTest
[INFO] Tests run: 2, Failures: 0, Errors: 0, Skipped: 0 ... in org.studyeasy.tasks.TaskServiceTest
[INFO] Tests run: 6, Failures: 0, Errors: 0, Skipped: 0
[INFO] BUILD SUCCESS
Swap the filter for !task.dueDate().isAfter(today) and "due today" counts as overdue again; dueTodayIsNotOverdueYet fails and tells you so.
Two ways to write the ask
TWO WAYS TO WRITE THE ASK - same feature, same due-date rule
(Only the ASK part changes. ROLE, STRICT RULES, QUALITY GATE and PLAN FIRST stay as in ex02.)
WAY 1 - POINT AT THE CODE (you already know where it goes)
ASK
In TaskService, add a method overdue(). It returns the open tasks whose dueDate is
before today, oldest due date first. Expose it in TaskController as
GET /api/tasks/overdue.
WAY 2 - NAME THE FEATURE AND THE DUE-DATE RULE (the agent picks the code)
ASK
Feature: overdue tasks.
Rule: a task is overdue from the day AFTER its due date. Due today is not overdue
yet. A done task is never overdue.
You decide the URL, the method names and where the logic lives.
WHICH ONE?
- Way 1 when you know the code well: fewer questions, less freedom.
- Way 2 when you know the feature, not the code: the agent proposes the names in
its plan, and you check them before you say OK.
- Either way, write the due-date rule in words. "Overdue" alone is a guess.
Point at the code when you know it well; name the feature and the rule when you don't. Either way, the word "overdue" alone is a guess, so write the due-date rule in words. You can also add an optional requirements part with use cases and test cases ("due soon: open, due today or within 7 days"), and each test case becomes a gate line.
/goal: the gate becomes the finish line
TURN THE QUALITY GATE INTO A GOAL (Claude Code)
Type these in the agent's input, right after you approve the plan.
STRONG GOAL - something the output can show (the due-soon use case, ex06)
/goal all tests pass with 0 failures, and the output shows the TC1, TC2 and TC3 tests
The same for the overdue feature (ex02)
/goal all tests pass with 0 failures, and the output shows the overdue tests
SEE THE STATUS, OR STOP IT
/goal
/goal clear
WEAK GOAL - nothing in the output can prove it, so the checker can never say done
/goal make it better
After you approve the plan, /goal in Claude Code keeps the agent working turn after turn until a checker reads the output and sees the condition met. A strong goal is something the output can show: tests pass, a count, a URL that answers. "Make it better" can never be proven, so it never finishes. Other agents have their own plan mode, so check your tool's help.
StudyEasy AI Community
Learn AI engineering, share what you build, and connect with other learners.
Free resources: lesson files, notebooks and code
Ask questions and join engineering discussions
Meet real people learning and building with AI
Related course on Udemy
FULL STACK JAVA : JAVA + JSP + SPRING BOOT AI + REACT + VIBE
Java 25, JSP, Hibernate, Spring Boot 4, REST APIs, React and Spring AI.View on Udemy ↗: FULL STACK JAVA : JAVA + JSP + SPRING BOOT AI + REACT + VIBE (paid course, opens in a new tab)Related posts
CLAUDE.md, settings.json and Plugins: Which Claude Code File Advises, Which Enforces, Which Packages
Three needs in one repo: a test command, a rule that Claude must never read .env, and a shared deploy skill. See which file each belongs in, how the settings layers merge, and what a plugin manifest carries.
Authoring a Claude Skill: SKILL.md, Frontmatter, Progressive Disclosure and the Description That Triggers It
Pack a support team's ticket-triage routine into one skill folder, then watch three requests load one, two or all three levels: the catalog, the SKILL.md body, and a script whose code never enters the context.
One Change, Four Environments: Where a Claude Config Edit Lands in Dev, Staging, Prod and CI
Change one line in a repo and ask where it lands. A small resolver for bookshop-bot shows that a new model id in settings.json reaches only CI, a prompt bump reaches dev and CI, and a prod block edit reaches only prod.
Claude in the SDLC: Prompts in Git, a Change Gate by Path, a Claude Review That Advises and a Person Who Merges
Follow one prompt edit from a branch to a merge: version prompts and the model pin like code, keep the API key in GitHub Secrets, gate changes by path, let Claude review the diff, and leave the merge to a person.
