Topic 4 of 5 · 6 min read
A plan-build-review task end to end
Goal: Follow a full task through plan, build and review and name the point where the loop should have stopped.
The loop is: explore, plan, then repeat build, check, review, commit for each step. Seeing it on one real task shows where it earns its keep.
Check yourself · 1 of 3
In the coupon example, the agent changed an existing test's expected total from 19.99 to 20.0. What is the right reaction?
The task
"Let customers enter a coupon code at checkout." The codebase is a Node shop with calculateTotal, an orders table and tests with Vitest.
Explore and plan
You start in a read-only mode: "Read src/checkout and src/db. Explain how totals are computed. Do not edit." The agent answers and mentions that discounts exist for staff, in applyStaffDiscount. You ask for a plan. It returns three steps:
- Add a
couponstable and model. - Apply a coupon inside
calculateTotal. - Add the coupon field to the checkout API and test it.
You add one correction: reuse applyStaffDiscount's rounding helper. Then you approve.
Step 1: model and migration
The diff is two files plus a test. The migration runs. You commit.
Step 2: apply in calculateTotal
Here it nearly goes wrong. git diff --stat shows four files, not two. The agent also edited formatPrice.ts, and one existing test now expects different rounding.
- expect(calculateTotal(cart)).toBe(19.99)
+ expect(calculateTotal(cart)).toBe(20.0)
This is the stop point. A passing test was changed to fit new behaviour, and nobody asked for new rounding. You do not approve. You tell the agent to revert formatPrice.ts and the test, and to use the rounding helper from applyStaffDiscount. The diff shrinks to two files and the old test passes unchanged. You commit.
Step 3: API field
The agent adds couponCode to the endpoint. The review finds that an unknown code returns HTTP 500. You ask for a 422 with a clear message and a test. Fixed inside the same step, then committed.
What the example shows
- The read-only start found a rule (staff discount rounding) the agent would have missed.
- The review at step 2 caught a changed test, which a pass-or-fail check alone would not catch.
- Each commit made a rollback possible, but none was needed.
What goes wrong
- Skipping the explore step. The agent invents rounding that conflicts with the existing helper.
- Treating green tests as proof. The test went green because it was edited.
- Not stopping. If you approve at step 2 to keep momentum, step 3 builds on wrong rounding.
Examples
The stat that gave it away
$ git diff --stat
src/checkout/calculateTotal.ts | 18 ++++---
src/checkout/calculateTotal.test.ts | 6 +--
src/lib/formatPrice.ts | 9 ++-
src/lib/formatPrice.test.ts | 4 +-
Step 2 should touch only the first two files. The last two are the drift.
The error that was a 500
An unknown coupon code made the API crash with a 500. The review caught it because the step's plan said "test the failure path" and the diff had no such test.
Key points
- The loop is explore, plan, then build, check, review and commit for each step.
- Reading the existing code first finds rules the agent would otherwise invent over, such as a rounding helper.
- A test changed to match new behaviour is a stop point, even when the whole suite is green.
- Fix problems inside the step where they appear, then commit the clean result.
- Each commit is a rollback point, even when you never use it.
Common mistakes
- Approving step 2 because the full test suite passed.
- Starting step 3 before the problem from step 2 was fixed.
- Skipping exploration, so the plan ignores existing helpers.
- Not committing between steps.
Check yourself · 2 of 3
Why was exploring the code before planning useful in the coupon task?
Check yourself · 3 of 3
What does git diff --stat tell you at the start of a step review?
Practice items, not counted towards your mastery.
Start here
- Best practices for Claude Code (Claude Code docs) (opens in a new tab)DocsFree
A vendor's own advice: explore and plan first, give the agent a way to verify, and clear context when it drifts.
- Checkpointing (Claude Code docs) (opens in a new tab)DocsFree
How to rewind code and conversation to an earlier point in a session, and what checkpoints do not cover.
- Exploring Generative AI (martinfowler.com) (opens in a new tab)ArticleFree
Field notes from Thoughtworks on working with AI in small steps and reviewing every output.
More for this topic
- Small CLs (Google Engineering Practices) (opens in a new tab)ArticleFree
Why small changes get better reviews, and how to split a large change into reviewable steps.