Spec-Driven Development for AI Coding Agents
-
446
-
0
-
Your engineers already prompt coding agents, and the results depend on who wrote the prompt. Spec-driven development (SDD) fixes the input: the spec comes first, and the agent writes code against it. For production work a spec has to do more than describe a feature. It has to say what the agent may touch, what proves the change is done, and who signs it off.
This guide lists the seven parts a spec needs before an AI coding agent writes code, gives a template you can copy, and shows where the spec sits in a software factory.
What spec-driven development is
Spec first, code second
In spec-driven development the written spec is the source of truth and the code is its output. A person (or a person with an agent) writes down what the change should do and how to tell that it works. The agent plans and implements against that document. When the result is wrong, you fix the spec and run again.
The idea is older than agents. What changed is how much it matters: an agent turns a vague request into a lot of plausible code, and review cannot keep up.
What a spec is not
- A long prompt. A prompt is a message to one session. A spec lives in the repo, is reviewed like code and outlives the session.
- A design document nobody updates. A spec that drifts from the code is decoration.
What the spec must contain before the agent writes code
A spec for a demo can stop at goal and tasks. For code that goes to production, a security lead or an auditor will ask three more questions: what was the agent told, what could it reach, and who checked the result. Seven parts answer all of them.
1. Goal and scope
One paragraph on the outcome, then an explicit list of what is out of scope. The list is an input for the gates: a change that touches files outside the scope fails the gate, whatever the agent was told.
2. Acceptance tests, including scenarios the agent does not see
Write the acceptance criteria as executable tests before the agent starts, then split them in two. The agent sees the first set and can run it as often as it likes. The second set stays outside its workspace and runs only in the gate.
An agent optimizes for the checks it can see. If every test is visible, code that passes them proves only that the agent can pass them. Hidden scenarios test the behavior you described in the spec, not the agent’s reading of it. Treat these hidden acceptance scenarios as part of the spec, even though the agent never reads them.
Here is an example from our own work. We were updating how a payments flow handles partial refunds, and the public tests were green. The agent had tied idempotency to the order ID alone: once an order had a refund, later ones were ignored. The held-back scenario sent two different partial refunds for the same order in parallel, plus a duplicate webhook, and the code failed. Without that scenario, the second refund would have been dropped silently, or the money sent twice, and we would have found out only at the month-end reconciliation.
3. Constraints
Language and framework versions, public contracts that must not change, and the directories and services the agent may modify. Name them as paths and service names, rather than adjectives. “Do not change anything under /billing or the orders schema” can be checked by a diff. “Be careful with payments” cannot.
4. Access
State what the agent runs with: a sandbox without production credentials, a scoped account with least privilege, short-lived credentials, no write access to the main branch. Put it in the spec because “what could the agent reach” is the first question a security team asks. The detail belongs in an access policy, and the spec says which policy applies to this change.
5. Risk lane
Decide the lane in the spec, before work starts. The table below shows three lanes: the agent does routine work behind gates, the agent does and the engineer reviews by risk, or the engineer leads and the agent assists. In every lane a named engineer signs off.
6. Gates and sign-off
List the checks that must pass: tests, static analysis, secrets scan, dependency and license checks, policy as code. Then name the engineer who signs. The rule that matters: the agent never approves its own work. Every change gets a named engineer’s sign-off, and the record shows who and when. What changes between lanes is how deep that engineer looks, not whether one signs.
7. Rollback and stop
Say how the change is undone (a feature flag, a canary with automatic rollback, a revert) and how the agent is stopped if it misbehaves. A single action that halts the agent belongs in the design from the start. If you cannot describe the rollback in two lines, the change is too big for the lane you picked.
A spec template you can copy
Keep the spec in the repo next to the code and short enough to read in five minutes.
# Spec: <short title>
Owner: <named engineer> Lane: 1 | 2 | 3 Date: <YYYY-MM-DD>
## 1. Goal and scope
Goal: <one paragraph, the outcome>
In scope: <list>
Out of scope: <list>
## 2. Acceptance tests
Visible to the agent: <path to tests>
Held back (run in the gate only): <path to hidden scenarios, kept outside the agent workspace>
## 3. Constraints
Stack and versions: <...>
Public interfaces that must not change: <...>
Agent may modify: <paths, services>
Agent must not modify: <paths, services>
## 4. Access
Environment: <sandbox name>
Credentials: <scoped account, expiry>
Network: <allowed destinations>
## 5. Risk lane
Lane: <1 routine, behind gates | 2 agent does, engineer reviews | 3 engineer leads>
Reason: <one line>
## 6. Gates and sign-off
Checks: <tests, static analysis, secrets scan, license check, policy checks>
Signed off by: <named engineer>. The agent does not sign.
## 7. Rollback and stop
Rollback: <how the change is undone>
Stop: <how the agent is halted>
# Added in our factory (see "Where spec-driven development breaks"):
## 8. Limits on volume and memory
Data volume: <expected rows, file size, request rate>
Ceiling: <memory and time ceiling per request or job>
## 9. Fields that must never be logged
Never log: <personal data, credentials, tokens, raw request payloads>
## 10. Anti-patterns
Do not: <patterns the agent must avoid, for example loading a whole table into memory>
A filled example for a routine change, a minor library upgrade:
# Spec: upgrade the HTTP client library from 4.2 to 4.3
Owner: <named engineer> Lane: 1 Date: 2026-11-24
Goal: move to 4.3 for a security patch; no behavior change.
Out of scope: refactoring call sites, changing timeouts, other dependencies.
Visible tests: tests/unit, tests/integration
Held back: scenarios for retry, timeout and TLS error handling, run in the gate
Agent may modify: dependency manifest, lockfile, adapter module for the client
Agent must not modify: public API handlers, database schema
Access: sandbox, scoped repo credential, no production credentials
Checks: tests, static analysis, secrets scan, license check
Signed off by: <named engineer>, on the gate results
Rollback: revert the commit; canary release with automatic rollback
Stop: revoke the agent's credential
With an agent such as Claude Code, keep the spec as a markdown file, point the agent at it in the task, and add a short standing rules file (CLAUDE.md or the equivalent for your tool) that says “work only from a spec file and stay inside its constraints”. The agent reads the spec itself, with no paraphrase in between.
Spec-driven development by lane
A change that renames an internal variable and a change that touches authorization do not need the same spec. Match the weight of the spec, and the depth of the engineer’s review, to the risk. Every lane ends in a named engineer’s sign-off:
| Lane | What goes through it | How much spec | What the engineer does |
|---|---|---|---|
| 1. Routine, behind gates | Dependency updates behind tests, test generation, documentation, drift reports, library patches | Short spec: goal, scope, tests, rollback | Signs off on the gate results, including held-back scenarios; no line-by-line review |
| 2. Agent does, engineer reviews | Features in non-critical modules, migrations with a preview, Terraform changes and infrastructure drift fixes | Full spec; the plan or preview is part of the review | Reviews the diff by risk and approves |
| 3. Engineer leads | Authorization, billing, data deletion, production schemas, security code | Full spec plus a design note | Leads the change, reviews every line; separation of duties so an auditor can see who approved |
Your lanes depend on your product. Write them down once and name the lane in every spec.
After the spec: what the gates check and what the engineer checks
A spec is only useful if something checks the result against it. That check has two halves, and the two are easy to confuse in talk about AI code review.
The automated gates check what a machine can decide the same way every time: the visible and hidden tests, static analysis and security scans, secrets in the diff, dependency and license policy, and the constraints from the spec (did the diff stay inside the allowed paths?). They run on every change and leave a record.
The engineer checks what a machine cannot: whether the change does what the spec meant, whether the lane was right, and what the tests do not cover. In lane 1 that is the gate results and the record. In lane 3 it is a full review.
The agent that wrote the change never approves it. Author, gate and approver are different parties, which is also what an auditor looks for. We help prepare the evidence, and auditors decide what counts.
Where the spec sits in a software factory
A spec is the first of five parts in the AI software factories we build and run: Spec, Build, Gates, Release, Run. Spec fixes the task. Build is where agents write code and tests. Gates run the checks and collect sign-off. Release adds a canary, rollback and a log of every change. Run is monitoring and incident response.
Our factory runs on our own SaaS product first. A named engineer signs off every change there, and every change goes through gates.
See AI software factories for the whole structure, and what an AI software factory is and how it runs for the parts around the spec. A spec makes the process checkable. It does not make a change safe on its own.
Spec-driven development tools
You do not need a tool to start: a markdown file in the repo and a pull request template will do. If you want structure, these are four tools. Descriptions are from each project’s own documentation, read on 24.11.2026. We do not rank them.
| Tool | What it is, in its own words | Shape of the workflow |
|---|---|---|
| GitHub Spec Kit | “Open source toolkit that gives AI coding agents structured processes”, with templates | Commands in the agent’s chat: a project constitution, then specify, plan, tasks, implement |
| OpenSpec | “Spec-driven development (SDD) for AI coding assistants” | Each change gets a folder with proposal, specs, design and tasks; finished changes are archived into the project specs |
| Kiro | Specs are “structured artifacts that formalize the development process for features and bug fixes” | Three documents per spec: requirements, design, tasks |
| BMAD Method | “Agile Ai Driven Development”, an open-source method | Planning depth scales with the size of the change |
Tools structure the spec. The production half (access, risk lane, hidden tests, sign-off) is a decision your team owns, whichever tool you choose.
Where spec-driven development breaks
- The spec goes stale. The code changes and the spec does not, so the next agent works from a document that lies. Fix: the spec changes in the same pull request as the code, and the reviewer checks both.
- The spec is longer than the task. Three pages for a two-line change will be skimmed. Fix: size the spec by lane.
- There are no tests. A spec without executable acceptance tests is a wish that the agent and the reviewer read differently.
- Nobody owns it. Each spec needs a named owner who answers for the result. If the owner is “the team”, the sign-off is empty.
A spec can also fail by being silent. For a CSV export of reports, ours described the business logic and the columns but said nothing about data volume or personal data. The agent wrote a synchronous endpoint that loaded the whole database into memory, and on validation errors it wrote the raw request payload to the logs. On a test set of 500 rows everything was fast. On production data we would have hit an out-of-memory crash and put personal data into the logs. Since then our spec template has three more mandatory blocks: limits on volume and memory, a list of fields that must never be logged, and a list of anti-patterns. If any of them is empty, the factory will not start the task. These three are blocks 8 to 10 of the template above.
SDD does not replace test-driven development. It sits above it: the spec defines the behavior, and the tests make it executable.
Questions teams ask
Does the spec replace code review?
No. The spec tells the agent and the reviewer what to expect, and the gates check the result against it. A named engineer still signs off every change, and in the highest-risk lane reads the code.
Can we use this with Claude Code, Cursor or Copilot?
Yes. The spec is a file in your repo, so it works with any agent that can read the repo. The tool decides how the agent loads it, and your access policy decides what it can do.
Next step
If your team already uses coding agents and the blocker is a security review or an auditor, a spec format and the gates behind it are where we would start. Book a call and we will look at your current setup.