Opening

In this post

  1. 1. Plan before the agent writes code
  2. 2. Settle the open decisions first
  3. 3. Write the spec as a file in the repo
  4. 4. Write acceptance criteria a test can check
  5. 5. Split the work into tasks the agent can finish
  6. 6. Build from the spec, and check against it
  7. The playbook in six lines

Article

AI engineering · Engineering practice · Guides

Write a Spec an Agent Can Build From: A Step-by-Step Guide

An agent builds what you asked for, not what you meant. Six steps, with the setup for Claude Code and Codex, that turn a request into a short spec, checkable criteria and tasks an agent can finish.

Author
Lovenish Singh Panwar
Published
Reading time
11 min read
Start reading

As of October 2026. Every setting and source below links to the page it comes from.

You ask an agent for an export button. It builds one, the tests pass, and it is the wrong feature. Nobody said who the export was for, which rows it should include, or what happens to data the user is not allowed to see. The agent did not ask. It decided.

That is not carelessness. A study accepted at ICLR 2026 ran coding agents on deliberately vague versions of real GitHub issues and found that models “struggle to distinguish between well-specified and underspecified instructions”. When the agents were allowed to ask questions, results improved by up to 74%. Both vendors give the same advice in their own guides. Anthropic warns that “letting Claude jump straight to coding can produce code that solves the wrong problem”, and OpenAI describes plan mode as the place where Codex can “ask clarifying questions, and build a stronger plan before implementation.”

So write the decisions down before the agent starts. Not for everything: Anthropic’s own rule is “if you could describe the diff in one sentence, skip the plan,” and a bug fix needs no spec. This is for features and changes that touch several files. Be clear about the evidence, too. The studies show that asking questions helps. None shows that a spec file on its own makes agents better. The rest is vendor practice and judgment.

Cheaper Code Moves the Bottleneck covers what to settle before generating anything. This post covers how to hand it to an agent. Six steps, each with the setup for Claude Code and Codex, and each useful on its own.

1. Plan before the agent writes code

Both tools have a mode that reads and proposes but does not edit. In Claude Code, press Shift+Tab until you reach plan mode, or start a single prompt with /plan. Claude reads files and runs commands to explore, then writes a plan. Unless your session runs with bypass permissions available, edits stay blocked until you approve it.

In Codex, type /plan, or press Shift+Tab. plan_mode_reasoning_effort raises the effort only while it plans.

Claude Code · In the session

Press Shift+Tab until the mode reads plan, then describe the task.
Or plan a single prompt:

/plan Add a filtered CSV export to the monthly view. Read the code first.

Codex · In the session, and ~/.codex/config.toml

/plan Add a filtered CSV export to the monthly view. Read the code first.

# Optional, in ~/.codex/config.toml: think harder only while planning
plan_mode_reasoning_effort = "high"

Make it a habit per task, not a default for every session. Most changes are small enough to skip the plan. If you want Claude to plan on the top tier and build on the mid tier, the opusplan alias does that; the setup guide covers when it is worth it. Only a repository where nearly every task touches several files earns defaultMode set to plan.

One catch: Claude Code saves its plan files under ~/.claude/plans/ by default, outside the repository. A plan in your home folder helps this session, not the next person. Step 3 puts the result where it lasts.

2. Settle the open decisions first

The export example failed on questions nobody asked. Make the agent ask them. Anthropic’s guide suggests having Claude interview you before a larger feature, using its AskUserQuestion tool, and only then writing the spec. OpenAI’s says the same for Codex: if you have only a rough idea, ask Codex to question you first.

Ask for questions in a form you can answer quickly: each open decision with a few options and a recommended one. Anything you cannot answer yet is marked as open, not guessed. GitHub’s Spec Kit does the same with a [NEEDS CLARIFICATION] marker.

Claude Code · Prompt, in plan mode

I want to add <feature>. Before you write anything, read the relevant code, then
interview me with AskUserQuestion. Ask only about decisions the code cannot answer:
who it is for, what is in and out of scope, edge cases, and how we will know it works.
Give each question two to four options and mark the one you recommend.
When we are done, write the spec to specs/<feature>.md using the template there.
Mark anything still open as [OPEN] instead of guessing.

Codex · Prompt, after /plan

I want to add <feature>. Before you plan, read the relevant code, then ask me
about the decisions the code cannot answer: who it is for, what is in and out of
scope, edge cases, and how we will know it works. Give each question two to four
options and mark the one you recommend. When we are done, write the spec to
specs/<feature>.md using the template there. Mark anything still open as [OPEN].

3. Write the spec as a file in the repo

Keep it to one screen and five sections. Anthropic’s guide says the most useful specs are “self-contained”: they name the files and interfaces involved, say what is out of scope, and end with a check that proves the feature works. OpenAI’s ExecPlans recipe, now archived, also asks for a plan that is “fully self-contained”, with a section on validation and acceptance, and calls it “a living document”. It changes as the work teaches you things.

Template · specs/_template.md

# <Feature name>

## Problem
Who has it, what they do today, and what changes for them. Two or three sentences.

## Scope
- In: <what this change does>
- Not in: <what it deliberately does not do>
- Touches: <files, modules and interfaces>

## Decisions
- <decision>: <the answer>, because <reason>.
- [OPEN] <anything not yet settled, and who decides>

## Acceptance criteria
- AC1: When <trigger>, the <system> shall <observable result>. Check: <test name or manual step>
- AC2: ...

## Tasks
- [ ] T1: <one task> (depends on: none; done when: AC1 passes)
- [ ] T2: ...

Instruction file · CLAUDE.md or AGENTS.md

## Specs

- Features and multi-file changes start from a spec in specs/, using specs/_template.md.
- Bug fixes and one-sentence changes do not need one.
- A spec with an [OPEN] item is not ready to build. Ask about it first.

“Not in” is the line that saves the most rework, in my experience. An agent that is not told where to stop tends to keep going: a settings page, a migration, a refactor nobody asked for. Naming what is out of scope gives it, and the reviewer, a fence.

Commit the spec beside the code, in specs/<feature>.md. Heavier tools use the same idea with more files. Spec Kit writes spec.md, plan.md and tasks.md through commands like /speckit-specify (older docs spell them /speckit.specify). Kiro splits a spec into requirements, design and tasks. Try them on a large feature, but start small. Thoughtworks put spec-driven development at “Assess” in November 2025 and called the workflows “elaborate and opinionated”. Reviewing these tools for Martin Fowler’s site, Birgitta Böckeler found Kiro on a small bug “like using a sledgehammer to crack a nut”, and wrote: “I’d rather review code than all these markdown files.”

4. Write acceptance criteria a test can check

A criterion is checkable when it names what triggers the behaviour, who or what responds, and a result you can observe. Without that, Anthropic’s guide puts it bluntly: “‘looks done’ is the only signal available.”

A simple way to get there is EARS, the Easy Approach to Requirements Syntax. Rolls-Royce engineers built it for aero-engine requirements and published it in 2009. It has five sentence patterns and a combined form. The one you will use most is the event pattern: When <trigger>, the <system> shall <response>. Kiro writes its acceptance criteria in this form. Given/When/Then from behaviour-driven testing works just as well. Pick one and use it everywhere.

Vague Checkable What a test can assert
Users can export their data. When a user exports the monthly view, the system shall download a CSV of the rows on screen, with the current filters applied. The file’s rows match the filtered table
Export should be secure. When a user exports, the system shall leave out rows that user is not allowed to view. A restricted row never appears in the file
Large exports should work. If an export has more than 10,000 rows, then the system shall email a link instead of downloading. The 10,001st row triggers the email path

Give each criterion its check: a test name, or a named manual step if no test can reach it. The spec should end with one check that proves the whole feature works end to end.

5. Split the work into tasks the agent can finish

A good task fits in one session and one pull request a person can read in one sitting, the size rule from the reviewable pull requests guide. Each task says what it depends on and which criteria prove it is done. Order them so each one leaves the code working.

Keep the task list in the spec, not only in the tool. Claude Code’s built-in checklist is off by default on its newest models, which track multi-step work without a written list. The file is the record that survives a new session, a teammate or a different tool.

One feature, from request to merged tasks

  1. Step 1

    State the request and the outcome

    Person

    One or two sentences on who it is for and how you will know it worked. The rest comes out in the interview.

  2. Step 2

    Read the code and interview the person

    Planning agentTop tierClaude Code: Opus 5.5Codex: gpt-6-astra

    In plan mode, nothing is edited. Every decision the code cannot answer becomes a question with a recommended option.

  3. Step 3

    Write the spec and commit it

    Planning agentTop tierClaude Code: Opus 5.5Codex: gpt-6-astra

    specs/<feature>.md holds the scope, the decisions, the criteria and the tasks. A person reads it before any code exists.

  4. Step 4

    Build one task in a fresh session

    Builder agentMid tierClaude Code: Sonnet 5.5Codex: gpt-6.1-sol

    The spec is the whole brief, so the session starts clean and cheap. One task, one pull request.

  5. Step 5

    Check the task against its criteria

    CI

    The tests named in the spec run. A criterion with no passing check is not done.

  6. Step 6

    Review the diff against the spec

    Reviewer

    Is every criterion for this task met, and did nothing outside its scope change? The spec makes that a short read.

  7. Step 7

    Tick the task and take the next

    Builder agentMid tierClaude Code: Sonnet 5.5Codex: gpt-6.1-sol

    The tick goes into the spec file in the same pull request, so the next session knows where things stand.

Each step names who does it and what it reads or writes. Planning runs once on the top tier; every task after that starts fresh on the mid tier, with the spec as its brief.

6. Build from the spec, and check against it

Start each task in a fresh session that reads the spec. Anthropic’s guide recommends exactly that once a spec is done. My reason for following it: the planning conversation is long, and the spec should now carry everything the builder needs.

Then tell the agent how to treat the spec. The important rule is the last one. When the spec and the code disagree, the agent stops and asks, and the spec gets updated, not quietly worked around. A spec that drifts from the code is worse than none.

Claude Code · CLAUDE.md

## Working from a spec

- Read the spec in full before you start. Work on one task at a time, in order.
- Change only what the task needs. Anything under "Not in" stays untouched.
- A task is done when its criteria pass. Tick it in the spec in the same pull request.
- If the spec and the code disagree, or a decision is missing, stop and ask.
  Then update the spec. Do not work around it.

Codex · AGENTS.md

## Working from a spec

- Read the spec in full before you start. Work on one task at a time, in order.
- Change only what the task needs. Anything under "Not in" stays untouched.
- A task is done when its criteria pass. Tick it in the spec in the same pull request.
- If the spec and the code disagree, or a decision is missing, stop and ask.
  Then update the spec. Do not work around it.

Before the pull request goes out, run one review of the diff against the spec. Anthropic’s guide gives a model prompt: check that every requirement is implemented, the listed edge cases have tests, and nothing outside the task’s scope changed. It also warns that a reviewer asked to find gaps will usually report some, so tell it to flag only gaps that affect correctness or a stated requirement. Expect to need this. Böckeler saw agents not follow every instruction even with a full spec in hand.

The criteria then become the evidence. Paste them into the “How it was checked” section of the pull request template, each with the check that proved it, and the reviewer starts from a list instead of a guess.

The playbook in six lines

  1. Plan mode first, for anything bigger than a one-sentence change.
  2. Let the agent interview you, with options and a recommended answer for each decision.
  3. A one-screen spec in specs/, committed with the code, with “Not in” filled in.
  4. Acceptance criteria in one checkable form, each with its test.
  5. Tasks that each fit one session and one pull request, listed in the spec.
  6. A fresh session per task, a stop-and-ask rule, and a review against the spec.

An agent will always fill the gaps you leave. The spec is where you decide which ones it gets to fill.

Related posts

Get an email when a new post is out

Used only to email you when a new post is out. Held by Kit. Unsubscribe anytime. Privacy

All posts

↑ ↓ moveEnter openEsc closeTap a result to open it