# Spec-Driven Development

**Also known as:** Spec-first · SDD  
**Category:** AI Patterns (Model in the loop)  
**Complexity:** 3/5  
**Guide:** https://layra4.dev/architectures/ai/spec-driven-development

*Agree on what to build before the agent builds it.*

An agent writes in an afternoon what a team once wrote in a sprint, and one person must review the diff. Reading two thousand generated lines is skimming, not review. Prompting and re-prompting also fails: the intent lives in a chat that the next session never sees.

Spec-driven development reverses the order. First write the requirements, each with a testable “done means”, as a file in the repo. A person reviews that page. Then the agent implements it task by task, and the criteria check the result. Each spec covers one change, so it stays small and cheap to revise.

> **In one sentence.** Agents made writing code cheap and review the bottleneck. So review the spec — a page that fits in your head — before any code exists.

## Origin (2025)

AWS Kiro (July 2025) made specs the main artifact, and GitHub Spec Kit and OpenSpec followed within months. Its roots are requirements-first process and Specification by Example.

## The artifacts

### The spec

What to build and why, short enough for a reviewer to hold in their head. It states behaviour and limits, never implementation, and it lives in the repo next to the code it governs.

- Covers one change, not the whole system
- Reviewed through the same pull requests as code
- Readable by the agent in every future session

> specs/refund-flow/spec.md: nine requirements, each with a testable “done means”

### Acceptance criteria

The “done means” for each requirement, written before any code exists. They describe the intent, so nobody can reverse-engineer them from whatever the code does. They are the agent's stop condition and the reviewer's checklist.

- Each becomes a test or an eval
- Specific about the awkward cases: the expired window, the double retry

### The review gate

A person approves the spec before implementation starts. These are the most valuable minutes in the whole flow: a wrong sentence here becomes a wrong module later. The diff still gets a lighter check against the spec.

- Catches wrong scope and intent, which diff review cannot recover
- Cheap to repeat: rejecting a paragraph costs nothing

### The task list

The spec split into steps, each small enough for one agent session. Progress lives in the file, not in anyone's memory, so the work can resume across sessions, agents and models.

- One task fits one context window
- Ticked off in the file as work completes

## Design rules

### Spend review time on the spec, not the diff

A page of intent is where human judgement works best, so put your careful minutes there. Diff review then becomes a simple check: does the code match what we agreed?

### Make every requirement testable

“Handles errors well” is a wish, and an agent will meet it in the cheapest way. Add a “done means” to each requirement: the exact error code, the expired window, the retry that must not pay twice.

### Write one spec per change, in the repo

Spec the change, not the whole system; a whole-system spec goes stale like an old wiki. In the repo, the spec survives what the context window does not: compaction, new sessions, another agent.

### Update the spec before you change course

When implementation shows the spec is wrong, fix the spec first and re-review it briefly. Match the process to the risk: a typo fix needs no spec, an auth change does.

## A change, spec first

```
repo/
specs/                          # one folder per change, archived when shipped
  refund-flow/                  # the change being made
    spec.md                     # requirements, each with a testable “done means”: the reviewed file
    design.md                   # limits the code must respect: boundaries, data, non-goals
    tasks.md                    # the steps: one per session, in dependency order
src/                            # built task by task, against spec.md
tests/                          # acceptance criteria, made executable
```

The spec is source code and lives with it. spec.md gets the careful review; tasks.md lets any session, human or agent, see how far the change has got.

## Examples

### A requirement with a clear “done means”

```markdown
## Requirement: Refund a paid order

The system SHALL refund a paid order within its refund window.

#### Done means
- A refund past the 30-day window is rejected with `REFUND_WINDOW_EXPIRED`
- A partial refund never exceeds the remaining refundable amount
- A refund emits `order.refunded` exactly once; a retried request must not pay twice

#### Non-goals
- Store credit and gift cards (separate change)
```

Behaviour without implementation, a “done means” the result can be checked against, and a non-goals line: the cheapest scope control there is. A reviewer reads this in a minute.

## When to use

- An agent writes most of the code and the diffs are too big to review
- The work spans several sessions or agents
- Requirements exist before the code: a contract, a rule, a customer ask

## When not to use

- You do not know what you want yet — build a prototype first
- The change is smaller than its spec would be
- Nobody will really read the spec

## Benefits

- Review moves to the place where judgement works
- Intent survives sessions, model changes and compaction
- “Done” becomes checkable through tests and evals

## Costs

- Extra process on every change that uses it
- Two documents to keep in sync: the spec and the code
- A wrong spec, built faithfully, still fails — with approval on record

## Pitfalls

- Skimming the spec the way people used to skim diffs.
- A whole-system spec that nobody updates. Spec the change, and archive it when shipped.
- Requirements with no test, met in the cheapest possible way.
- Silent drift: the code departs from the spec, and the truth moves back into people's heads.

## Similar patterns, compared

One pattern in this category also writes the work down first, another starts from the same spec but stops reading the code, and a design pattern elsewhere shares the name. The differences are who the document is for, whether it runs, and who checks the result.

### Spec-Driven Development vs Software Factory

Both start from a reviewed spec. Here a person still checks the diff against it; a factory drops that check and lets hidden scenarios decide. — [Software Factory](https://layra4.dev/architectures/ai/software-factory)

**What is genuinely the same**

- A written, approved spec comes before any code
- Agents write the implementation

**What actually differs**

- Here a person reviews the change; there nobody reads the code
- Here one change moves at a time; there many jobs run unattended

**Pick Spec-Driven Development when:** People can still read the diffs, and you want their judgement on the code as well as on the intent.

### Spec-Driven Development vs Planner–Executor

Both split deciding from doing. The spec is the team's document for a change; the plan is the machine's document for one run. — [Planner–Executor](https://layra4.dev/architectures/ai/planner-executor)

**What is genuinely the same**

- A written document exists before any work happens
- Both define what done looks like before starting

**What actually differs**

- A spec says what and why — behaviour and criteria; a plan says how — ordered steps
- People write and review a spec, and it lives for the change; a model writes a plan, and it lives for one run

**Pick Spec-Driven Development when:** People must agree on the intent before any run starts, and that agreement must outlive every context window.

### Spec-Driven Development vs Specification

Only the name is shared: DDD's Specification is a predicate object inside the domain model; this is a document that guides an agent's work. — [Specification](https://layra4.dev/architectures/tactical/specification)

**What is genuinely the same**

- Both write a requirement down once, explicitly
- Both make “does this meet the rule?” a checkable question

**What actually differs**

- Specification is code, evaluated at run time; a spec here is prose, reviewed by people
- One decides whether an object qualifies; the other decides what gets built

## Related patterns

- [Planner–Executor](https://layra4.dev/architectures/ai/planner-executor) — the machine's version of deciding before doing
- [Human in the Loop](https://layra4.dev/architectures/ai/human-in-the-loop) — the same gate, moved from the action to the intent
- [Evaluation Harness](https://layra4.dev/architectures/ai/eval-harness) — where acceptance criteria become executable
- [Multi-Agent Orchestration](https://layra4.dev/architectures/ai/multi-agent) — one agreed spec keeps parallel agents from colliding
- [Specification](https://layra4.dev/architectures/tactical/specification) — the DDD pattern this shares only a name with
- [Software Factory](https://layra4.dev/architectures/ai/software-factory) — the next step, once nobody reviews the diff

## Further reading

- *Spec-driven development with AI: Get started with a new open source toolkit* — GitHub (2025) — Spec Kit: specify, plan, tasks, implement, with the spec under version control.
- *Specification by Example* — Gojko Adzic (2011) — The pre-LLM ancestor: requirements as concrete examples the team agrees on first.
- *The New Code* — Sean Grove (2025) — The argument in full: specifications, not prompts or code, as the lasting artifact.
