Skip to content

Building with agents, lesson 2.2

Research, plan, implement

An agent that codes first builds on its first guess. This lesson walks through the order that works: read the code, write a spec, have a person check it, then build and prove it against the spec.

What do you run?

Every example below changes to fit what you pick. The businesses are made up for teaching.

The picture, one step at a time

Each box is one stage. The picture lights up as you scroll.

Step 1 of 6

Why not just start?

An agent that starts writing code at once builds on its first guess. If the guess is wrong, every line after it is wrong too, and you find out at the end. For a job like adding parcel tracking to the support agent, three short stages before any code save most of that waste: read, plan, and let a person check the plan.

Step 2 of 6

Research: read, change nothing

First the agent reads. Which files does this touch? What already exists that it could reuse? Where else does the same pattern appear? It can run commands to look around, but it edits nothing. The output is what it found, not code.

Claude Code has a plan mode for this (as of November 2026): it reads files and runs commands to explore, writes a plan, and cannot edit your code until you approve. Shift+Tab switches to it.

Step 3 of 6

Write the spec

Next, the plan goes in a file: the goal in one sentence, what done looks like, what is out of scope, the edge cases, and the checks that will prove it works. If you have not decided some of it yet, have the agent ask you questions until it can write the spec.

Anthropic's Claude Code guide gives a prompt for this: "Interview me until you could write the spec, then write it to SPEC.md."

Step 4 of 6

A person reads the plan

This is the cheapest place to catch a mistake. A wrong plan costs a minute to fix in a file, and a day to fix in code. Read it for one thing above all: would the result be what you actually want?

The plan looks right, but it never says what the agent must not touch. What do you do?

Step 5 of 6

Implement from the spec

Now the code. Start a fresh session pointed at the spec, so the build begins with a clean slate and a written target. It builds what the spec says, and only that. If the spec turns out to be wrong, stop and fix the spec first, then carry on.

Anthropic's guide recommends exactly this: once SPEC.md exists, start a fresh session to build from it, "so the build begins with a clean context and a written definition of done".

Step 6 of 6

Check against the spec

Last, prove it. Run the checks the spec names: a test, a build, a linter, anything that comes back pass or fail. Ask for evidence, the command and its output, not "all tests pass". Then have a reviewer that did not write the code compare it to the spec, line by line.

Who makes the better reviewer of the finished code?

Where did it go wrong?

Here are four jobs that went wrong in your business. Sort each one into the stage that should have caught it.

  1. 1The agent wrote a new parcel tracker from scratch. Your codebase already had one, used by the order emails.

  2. 2The new tool refunds any lost parcel on its own, including a £300 one. Your rule is that a person approves anything over £50.

  3. 3The plan said "add track_parcel". The change also renamed a column in the orders table.

  4. 4It said "done". The tracking tool returns yesterday's status, and no test ever ran.

0 of 4 right so far, 4 to go.

A spec template

This is what you keep: the sections of a spec, in order. Copy them into a file at the start of any job bigger than a one-line change.

A spec template

  1. The goal: one sentence on what changes, and for whom.
  2. What the research found: the files involved, what already exists to reuse, and anything surprising.
  3. What done looks like: the checks that must pass, written so a machine can run them.
  4. Out of scope: what it must not touch or change.
  5. Edge cases and open questions, each with an answer or the name of who decides.
  6. The steps, in order, each small enough to check on its own.

No code until a person has read the plan, and no "done" until the checks in the spec have run, with proof.

Next: Lesson 3.1: MCP fundamentals: servers, clients, tools. How one standard way of connecting lets an agent reach your systems.