Write the Spec, Not the Prompt: Briefing an AI Coding Agent
How to write a spec for an AI coding agent in six short sections. Stop the rewrite loop, name failure modes upfront, and copy a one-page brief that ships.
Contents
You type two lines into Cursor, Claude Code, or Codex: "Add an offline reading shelf with a lending tracker." Thirty seconds later, files are streaming across the screen. Five minutes later, there is a working page.
Then you spend the next two hours undoing decisions you never asked for. The agent invented a login screen you didn't want, pulled in a state library you don't use, reshaped a shared layout, and silently stored the same field in two places. By message fourteen, you are fixing fixes.
The agent wasn't ignoring you. It was filling in the blanks you left open. Every blank in a prompt is a product decision delegated to a coin flip — and agents are very fast at building on top of a coin flip.
Learning how to write a spec for an AI coding agent is not about writing corporate documentation. It is about making six short decisions before the first file is touched so you don't spend the evening reversing them. In How to Review AI-Generated Code Before It Ships, we looked at catching silent failures after an agent finishes. A one-page spec is the first half of the same discipline: keeping bad assumptions out of the repository in the first place.
Why prompts drift and specs hold
A prompt is a turn in a conversation. A spec is a boundary written down in one place. They behave completely differently once a feature gets past its first draft.
Implicit defaults always win. Ask an agent for "a browser image editor" and its training data reaches for file uploads, cloud buckets, and user accounts. When we built Darkroom, the first line of the brief was not a list of filters — it was a constraint: 100% client-side, files never leave the device, edits live in a reversible stack instead of overwriting the image. One sentence ruled out an entire backend before a single file existed.
Chat context decays; files do not. Ten turns into a session, the nuance you mentioned in message two is buried behind tool logs and half-reverted attempts. A SPEC.md sitting in the repo can be re-read verbatim on turn one and turn forty — or handed to a fresh session tomorrow without re-explaining the project.
Scope creep hides inside being helpful. Agents want to be thorough. Without a written boundary, they tidy adjacent components, rename helpers, and install packages to solve problems you haven't hit yet. Every extra line is code you now have to review and maintain.
How to write a spec for an AI coding agent
If a spec takes forty minutes to write, you will skip it on Tuesday afternoon and go back to winging prompts. Keep it to one screen — six short sections, five minutes of plain English.
- State the single outcome in one sentence. Describe what a person can do when this ships, in behaviour terms, not implementation details.
- Draw the hard boundary with non-goals. List three to five things the agent must not build, refactor, or install.
- Define the inputs, outputs, and source of truth. Name where data starts, where it lives, and what shape comes out — with one authoritative place per piece of state.
- Spell out the failure modes and empty states. Say what happens when there is no data, no network, an invalid payload, or a slow response.
- Anchor to existing patterns in the repository. Point at one or two real files the agent must imitate instead of inventing a parallel style.
- Write the proof of done. List the exact pages, screen widths, counts, or checks the agent must report back before calling the task finished.
Those six sections cover almost every class of rewrite. Notice that none of them require writing code yourself — they require deciding what the product should do and what it must refuse to do.
The two sections most people skip (and pay for later)
When a spec still produces a messy pull request, it is almost always because section two or section four was left vague.
Non-goals do more work than goals. Telling an agent what you want leaves an infinite field of acceptable extras. Telling it what is off-limits collapses the search space immediately. When we scoped Bookkeeper — a cozy book shelf, e-book library, and lending log — the most valuable lines in the brief were the refusals: no accounts, no remote server, works offline from the first load, no third-party UI kit. Those four refusals shaped every component cleanly without micromanaging how any of them were coded.
Failure modes beat happy-path descriptions. Coding agents are already strong at the happy path. Where they invent quietly broken behaviour is at the edges: an empty array, a dropped connection, a malformed request, a missing image. On Graphly, the happy path fits in six words — POST JSON, get back a graph. The real spec lives in the edge cases: what status and message come back on invalid JSON, what happens when a payload exceeds the node limit, and how the visual editor behaves before the user types a single character.
Compare how an agent responds to a vague instruction versus a stated failure mode:
Vague: "Handle errors gracefully if the CMS is down."
Specific: "If the CMS is unreachable during a production build, fail the build loudly instead of generating an empty site. At runtime, serve the last cached list and log one warning."
The first sentence invites the agent to return [] everywhere and quietly publish an empty site. The second sentence gives it the exact trade-off between build time and runtime in two lines.
The one-page spec template
Save this as SPEC.md (or paste it at the start of a session) and fill in only the lines that matter for the task in front of you. Delete anything that doesn't apply.
# Feature: <short name>
## 1. Outcome (one sentence)
When this ships, a user can <observable action> on <route or screen>.
## 2. Non-goals (do not do these)
- Do not add authentication, remote storage, or new dependencies.
- Do not modify <unrelated files or shared layouts>.
- Do not redesign <existing component>.
## 3. Inputs, outputs & source of truth
- Input: <user action, form fields, or API payload>
- Source of truth: <localStorage / IndexedDB / Sanity / Postgres table>
- Output: <rendered UI, file download, or response shape>
## 4. Failure modes & empty states
- No data yet: <show specific empty state copy and action>
- Invalid input: <inline error message; never fail silently>
- Offline or slow network: <acceptable worst case>
## 5. Reference files (match these patterns)
- Follow layout & styling from: <path/to/existing-component.tsx>
- Follow data fetching / validation from: <path/to/existing-helper.ts>
## 6. Proof of done
Before finishing, run lint and typecheck, open <routes> at 390px and
1440px, verify the empty state, and report:
- Files changed (and why)
- Checks run and results
- Anything not tested or still assumedKeep the file disposable. Once the feature ships and passes review, either delete SPEC.md or move its lasting constraints into your project's AGENTS.md so future sessions inherit them automatically.
The two-step briefing ritual
Writing a spec is half the habit. The other half is stopping the agent from sprinting before it has absorbed what you wrote.
Step 1 — Ask for a restatement and questions, not code. Hand over the spec with this exact opening turn:
Read SPEC.md and the reference files listed in it. Do not edit any files yet. Restate the boundary in three bullets, list every file you plan to touch, and ask me about any ambiguity, edge case, or hidden assumption you spotted.This single turn saves more time than any prompt trick. If the agent's file list includes a layout it has no business touching, or its restatement misses an offline requirement, you catch a two-hour detour in twenty seconds of plain English.
Step 2 — Lock the answers back into the spec before building. When the agent asks three sharp questions, answer them and tell it to update SPEC.md first, then start implementing. That way the spec stays the single source of truth — not a thread of scattered clarifications buried halfway up the chat.
When a spec is overkill (and when it saves the week)
You do not need a spec for everything. If you are fixing a typo, nudging spacing, or patching a single-file bug whose entire diff fits on one screen, just ask directly and look at the result. Ceremony for trivial edits slows you down without buying safety.
Write the one-page spec whenever a change crosses any of these lines:
- It touches more than three files or introduces a new route.
- It adds new state, persistence, caching, or an external API.
- It has an empty state, error state, or offline behaviour users could silently hit.
- It matters enough that you would be annoyed to throw the branch away and start over.
This is the exact same principle behind how we run fixed-scope MVP sprints at kakade.dev: two days spent writing a tight boundary before writing production code removes weeks of guesswork later. Whether you are briefing a small studio or briefing an AI coding agent, clarity upfront is always the cheapest hour in the build.
Before you hit Enter: the six-check test
Take thirty seconds to scan your brief before letting the agent touch the repo.
- A stranger could read section one and know what ships.
- At least three things are explicitly ruled out in non-goals.
- Every piece of data has one stated source of truth.
- Empty, invalid, and offline states each have an expected outcome.
- At least one existing file is named as the pattern to copy.
- Proof of done names concrete routes, widths, or checks — not "make sure it works".
Once the build finishes, run the second half of the workflow: review the shipped behaviour instead of trusting the green checkmarks.
Prompts optimise for how fast you start. Specs optimise for whether you actually finish.
