◆ AI All-in-One

Level 2 Agentic Coding · Agentic Coding

Planning and Specs: Telling an Agent What to Build

Most bad agent output comes from an unclear request, not a weak model. This chapter teaches the explore, plan, code, verify workflow, how to write a short spec with acceptance criteria, how to use plan mode, how to break work into small tasks, and how to let the agent interview you before it builds.

Level
●●●●● Easy
Reading
12 min
To learn it well
45 minutes to read, an afternoon to practise
↗ Plan a path here

Read first

What Is Agentic Coding?Prompt Engineering

This leads to

Project Context and Memory Files
The full path from zero — 7 concepts before this one
  1. What Is AI?
  2. How Machines Learn
  3. Large Language Models, Explained Simply
  4. AI Fluency: Working Well with AI
  5. Prompt Engineering
  6. Asking Well: Everyday Prompting
  7. What Is Agentic Coding?
  8. Planning and Specs: Telling an Agent What to Build

Read them roughly in this order. See it on the concept map →

Why it matters

Ask an agent to "add budgets to tally" and it will add budgets to tally. But what is a budget here: per month or per week? Per category or overall? Where is it stored? What does the report show when you go over? What if no budget is set? Every question you didn't answer, the agent answers for you, silently and confidently. Some of its answers will be different from yours, and you will find out only when you read the code, or worse, when you use the program.

This is the most common reason agent output disappoints, and it isn't a model problem. A brilliant human contractor given the same one-line brief would also guess. The difference is that the contractor would ask questions first, and an agent usually won't unless you make it.

The fix is old software-engineering practice, made cheap by AI: decide what to build before building it. Write down what "done" looks like, have the agent plan before it codes, and break big jobs into small, checkable ones. This chapter builds on the general advice in Prompt Engineering, and applies it to the specific job of directing a coding agent.

The idea

Explore, plan, code, verify

Anthropic's 2025 best-practices article for Claude Code popularised the rhythm "explore, plan, code, commit". This guide uses a variant that suits every agent, with verify in place of commit, because verifying is the step people skip (committing is covered in Git for Agent Work):

  1. Explore. The agent reads the relevant code and answers your questions about it. No edits. You both learn how things currently work.
  2. Plan. The agent proposes what it will change: which files, which functions, what tests, what risks. You correct the plan. Changing a plan costs a sentence. Changing code costs a review and a redo.
  3. Code. The agent implements the plan, ideally one small step at a time, with a commit after each (Git for Agent Work).
  4. Verify. Tests pass, and you check each requirement yourself. If something is wrong, go back to the plan, not just the code.
1. Explore read the code, ask questions, no edits yet plan mode 2. Plan steps, files, tests, risks you correct it SPEC.md / plan 3. Code one small task at a time, commit each manual / acceptEdits 4. Verify tests pass, each acceptance criterion checked by hand tests, diff, run it a criterion fails or the plan was wrong: back to planning mistakes cheap to fix mistakes expensive to fix
Fig. 1 Explore, plan, code, verify. Mistakes are cheapest to fix on the left. Failed checks send you back to planning, not just to more coding.

The phases are not bureaucracy. For a one-line typo fix, skip straight to code. The rule of thumb: if you could describe the whole change in one sentence, and you'd recognise the right diff at a glance, skip the plan. Otherwise, plan.

Key idea Time spent before the agent writes code is the cheapest time in the whole process. A two-minute plan review regularly saves a twenty-minute code review and a full redo.

Plan mode

Most agents have a mode that enforces the explore and plan steps: the agent may read but not edit. In Claude Code, plan mode is entered with Shift+Tab (until the status bar shows ⏸ plan mode on), with the /plan command, or by starting with claude --permission-mode plan. The agent explores, then presents a plan and asks for approval. You can accept it, keep refining it, or press Ctrl+G to open the plan in your text editor and change it directly. Codex CLI, Gemini CLI and Cursor all have a comparable plan mode. Without one, simply say: "Read the relevant code and propose a plan. Don't edit any files yet."

Specs and acceptance criteria

A specification (spec) is a written description of what to build, for a feature too big to describe in one prompt. For agent work it doesn't need to be formal. Half a page in a Markdown file is usually right, and it has a huge advantage over a chat message: it survives /clear, it can be committed with the code, and a reviewer (human or agent) can check the result against it later.

The most important part of a spec is its acceptance criteria: a list of concrete, observable behaviours that must be true when the work is done. "Budgets work well" is not an acceptance criterion. "tally budget food 200 prints Budget for food set to 200.00 per month" is. Good criteria are testable: each one can become an automated test or a command you run by hand.

A vague task A task an agent can finish and you can check "Add budgets to tally." The agent must guess: per month? per week? stored where? shown how? warned how? what if none is set? how do we know it works? Goal what and why, one sentence Context files, existing patterns to copy Constraints libraries, style, what not to touch Acceptance criteria observable behaviour, examples Out of scope what not to build (yet) How to verify commands to run, tests to add Monthly budget per category, shown in report copy parse_amount(); store like expenses.csv standard library only; Decimal; keep CLI style food 150.00 / 200.00 50.00 left weekly budgets, rollover, currencies pytest; tally budget food 200; report --month
Fig. 2 The anatomy of a task. A one-line request leaves the agent to guess six things. A short spec answers them: the goal, the context to copy, constraints, acceptance criteria with examples, what is out of scope, and how to verify.

A useful spec has six parts, as in the figure:

  • Goal: what and why, in one or two sentences. The why helps the agent make sensible small decisions.
  • Context: which files matter and which existing code to imitate. "Validate amounts the way parse_amount() does" stops the agent inventing a second validator.
  • Constraints: languages, libraries (or "no new dependencies"), style, and what must not change.
  • Acceptance criteria: behaviours, with real example inputs and outputs.
  • Out of scope: what not to build. Agents love to add extras, and this is where you stop them.
  • How to verify: the commands to run and the tests to add.

Turning specs into a formal practice is called spec-driven development: the spec is the primary artefact, and code is generated and regenerated from it. Tools such as GitHub's open-source Spec Kit and AWS's Kiro editor (both 2025) structure the whole flow, from spec to technical plan to task list to code. They are worth knowing about, but they add ceremony. For small projects a single SPEC.md gives you most of the benefit.

Let the agent interview you

What if you don't know the answers yet? Then make the agent ask the questions. Claude Code's best-practices guide suggests a prompt like:

I want to add monthly budgets to tally but haven't thought it through yet.
Interview me until you could write the spec, then write it to SPEC.md.

The agent comes back with questions, often multiple choice: monthly or weekly? Shown in every report or only with --month? Warn when over budget, or refuse to record the expense? You answer, it asks more, and it writes the spec. Then start a fresh session to build from that spec, so the implementation starts with a clean context and a written definition of done instead of a long, meandering conversation.

Small tasks

Agents are much more reliable on small, well-bounded tasks than on large ones, for the same reason as people: each step has fewer ways to go wrong, and mistakes are caught before later steps build on them. It is the compounding error problem in practical form. A feature that needs 300 lines across five files should usually be three to six tasks, each ending with passing tests and a commit. Good splits follow the structure of the work: storage first, then the command, then the display. Ask the agent to propose the split, and check that each step leaves the program working.

In practice

Good and bad task descriptions

Vague Clear
"Fix the report." "tally report crashes with KeyError: 'category' when expenses.csv has only a header line. Make it print nothing in that case, and add a test."
"Make tally faster." "tally report takes 4 seconds on a 200,000-row file. Profile it, tell me where the time goes, and propose a fix before changing anything."
"Add export." "Add tally export --json that prints all expenses as a JSON list of objects with keys date, amount (string), category. Don't change the CSV format."
"Clean up the code." "Split main() into one function per subcommand. Behaviour must not change: all existing tests must pass unchanged."
"Add login." Too big for one task. Ask for a spec and a plan first.

The clear versions share a pattern. They name the symptom or the behaviour, give an example, say what must not change, and say how to check.

Phrases that help

  • "Read X and Y first." Pointing at files saves the agent searching and stops it guessing.
  • "Follow the pattern in parse_amount()." Imitation beats description.
  • "Don't change anything outside tally.py," "Don't modify existing tests," "No new dependencies."
  • "If something in this spec is ambiguous, ask me instead of guessing."
  • "Before you finish, check each acceptance criterion in SPEC.md and tell me how you verified it."

Steering mid-task

Watch the first minute of any task. If the agent heads somewhere you didn't intend, press Esc: it stops and keeps what it has done so far, and you can redirect it. Claude Code's guide gives a sharp rule: if you have corrected the same thing twice and it's still wrong, don't try a third time. Run /clear and write one better prompt that includes what you learned. A conversation full of failed attempts keeps pulling the agent back towards them.

Worked example: budgets for tally

1. Interview. In a fresh session, in plan mode, you ask the agent to interview you about budgets. After five or six questions it writes this SPEC.md, which you edit by hand in two places:

# Spec: monthly budgets

## Goal
Let me set a monthly spending limit per category and see, in the
monthly report, how much is left or how far over I am.

## Context
- tally.py: CLI built with argparse; money is Decimal; amounts are
  validated by parse_amount(). Expenses live in expenses.csv.
- report --month YYYY-MM already filters by month (filter_month()).

## Constraints
- Standard library only. Decimal for all money.
- Store budgets in budgets.json next to expenses.csv: {"food": "200.00"}.
- Don't change the format of expenses.csv or existing output without --month.

## Acceptance criteria
1. `tally budget food 200` prints `Budget for food set to 200.00 per month`
   and saves it. Setting it again replaces the old value.
2. Categories are case-insensitive: `budget Food 200` sets "food".
3. Invalid amounts (0, -5, abc) are rejected exactly as `add` rejects them.
4. `tally report --month 2026-11` shows, for categories with a budget:
   `food            150.00 /   200.00  50.00 left`
   and when over: `rent            450.00 /   400.00  OVER by 50.00`.
   Categories without a budget show just the total, as now.
5. `tally report` without --month is unchanged.
6. With no budgets.json, everything works as before.

## Out of scope
Weekly or yearly budgets, rollover, warnings when adding an expense, currencies.

## How to verify
- python -m pytest -q: all existing tests pass unchanged, new tests cover 1–6.
- Manually: set two budgets, add expenses over and under, run report --month.

2. Plan. In a new session: "Read SPEC.md and tally.py. Propose a plan as a list of small steps, each ending with passing tests." The agent replies:

Plan (3 steps, commit after each):
1. Storage: load_budgets(path) and set_budget(path, category, amount)
   using json; budgets stored as strings to keep Decimal exact.
   Tests: round trip, replace existing, lower-casing, missing file -> {}.
2. Command: `budget CATEGORY AMOUNT` subparser reusing parse_amount().
   Tests: criteria 1–3 via main([...]) with tmp_path.
3. Display: format_line(category, total, budget) used by report only
   when --month is given. Tests: under, exactly at, over, no budget.
Risk: main() uses module-level DATA_FILE; tests must not write real
files. I'll monkeypatch BUDGET_FILE to tmp_path.

That plan is good, and it caught something you hadn't thought of: "exactly at budget". You decide that food 200.00 / 200.00 0.00 left is fine, add it to criterion 4, and approve.

3. Code and verify, step by step. Each step ends with tests and a commit. Tests as Guardrails picks up this exact feature and shows the test-first version. At the end you run the manual check from the spec:

$ python tally.py budget food 200
Budget for food set to 200.00 per month
$ python tally.py budget Rent 400
Budget for rent set to 400.00 per month
$ python tally.py report --month 2026-11
coffee           12.00
food            150.00 /   200.00  50.00 left
rent            450.00 /   400.00  OVER by 50.00
$ python tally.py report
coffee           12.00
food            150.00
rent            450.00

Every criterion is checked, and you can see that criterion 5 holds. Finally, a cheap extra check: in a fresh session, ask "Compare the diff on this branch against SPEC.md. List any criterion that isn't implemented or tested." A reviewer with a clean context and the spec in hand catches what the implementing session talked itself out of.

Common mistakes

  • Specifying the solution instead of the problem. "Add a budgets table with columns…" ties the agent's hands before you know the best design. Describe behaviour, and let the plan propose the design.
  • Criteria nobody can check. "Should be user-friendly" can't be tested. Rewrite it as a behaviour: "error messages name the bad value".
  • Skipping "out of scope". Without it, expect extra features, extra configuration options and extra files.
  • Approving a plan you didn't read. A plan you skim is worse than no plan, because it feels like a check.
  • One giant task. If the plan has more than about six steps, split the work into separate tasks, each with its own session.
  • Letting the spec rot. When you change your mind mid-build, update SPEC.md first, then tell the agent. Otherwise the code and the spec disagree, and the next session will "fix" the code back.

Tip Keep specs in the repository, for example as docs/specs/budgets.md, and commit them with the feature. Six months later, when you or an agent wonder why the report works the way it does, the answer is there.

Where it leads

Try it

  1. Take the vague request "add a way to delete expenses to tally" and write a full spec with the six parts. Include at least five acceptance criteria with exact example commands and output.
  2. Give an agent the vague request and, separately in a fresh session, your spec. Compare the two results. How many of your criteria did the vague version meet by luck?
  3. Ask an agent to interview you about a small tool you actually want. Stop after it writes the spec, and mark which questions you would never have thought to answer.

Hint for 1: the hard questions are identity ("which expense?", since there are no IDs yet), safety ("can I undo it?") and output ("what is printed?"). A good spec decides each one, and says in "out of scope" what it isn't deciding yet.

Check your understanding

5 quick questions. Pick an answer to see whether you were right and why. Your best score is saved on this device.

  1. Which of these is a good acceptance criterion for a budgets feature?

  2. When does the chapter say it is fine to skip the plan step and go straight to code?

  3. You have corrected the agent on the same point twice in one session and it is still wrong. What does Claude Code's guidance suggest?

  4. Without an "Out of scope" section in your spec, what should you expect?

  5. You don't yet know how budgets should behave. What workflow does the chapter recommend?

Finished this chapter?

Learn more

Hand-picked courses, books, videos and tutorials for going deeper. See all resources →

Article

Claude Code: Best practices for agentic coding

Anthropic · 2025 · Beginner · Free

Concrete workflows for coding agents: CLAUDE.md files, explore-plan-code-commit, test-driven loops, course-correcting early, and running agents safely.

Course

Spec-Driven Development with Coding Agents

Paul Everitt (DeepLearning.AI with JetBrains) · 2026 · Beginner · Free

A short course on writing specifications first and having coding agents implement, check and update against them, instead of steering by ad-hoc prompts.

Docs

Claude Code common workflows

Anthropic · Beginner · Free

Step-by-step recipes for everyday jobs: understanding a new codebase, fixing bugs, refactoring, plan mode, writing tests, making pull requests and running parallel sessions in git worktrees.

Tool

Spec Kit

GitHub · Intermediate · Free

An open-source toolkit for spec-driven development with coding agents: commands that walk an agent from a written specification to a technical plan, a task list and an implementation.

Article

Here's how I use LLMs to help me write code

Simon Willison · 2025 · Beginner · Free

Practical, hype-free advice: set expectations, account for training cut-offs, give context, tell the model exactly what to write, and always test what it produces.

Facts checked as of 30 November 2026. Fast-moving details (products, prices, laws) change often. · Source: content/entries/agentic/specs-and-planning.md