AnyLearn
All lessons
Programmingintermediate

Spec-Driven Development: Writing the Contract an AI Agent Builds To

Coding agents fill every gap in a request with a guess. Learn how spec-driven development closes those gaps with testable EARS requirements, a technical plan and small traceable tasks, and how to tell when the method earns its overhead.

Updated · AI-authored, review-gated · how lessons are made

Progress1 / 10

Every gap gets filled, by a guess

Ask a coding agent to "add password reset" and it will ship something. Behind that one sentence sit dozens of decisions nobody made: how long the reset link lives, whether old links die when a new one is sent, what the page says when the email is unknown, whether attempts are rate-limited. The agent does not stop to ask. It resolves each gap with the most typical answer and moves on, so the unmade decisions surface later as bugs or security holes.

GitHub's write-up introducing its Spec Kit toolkit puts the diagnosis in one line: language models are "exceptional at pattern completion, but not at mind reading." Spec-driven development (SDD) is the response. You write the decisions down before any code exists, in a form the agent can follow and a reviewer can check.

Key idea: An agent's output can only be as precise as its input. A spec moves decisions out of the agent's guesswork and into a document a human approved.

Sign in free to save your progress and earn certificates.

Full lesson text

All 10 steps on one page, for reading, reference, and search.

Show

1. Every gap gets filled, by a guess

Ask a coding agent to "add password reset" and it will ship something. Behind that one sentence sit dozens of decisions nobody made: how long the reset link lives, whether old links die when a new one is sent, what the page says when the email is unknown, whether attempts are rate-limited. The agent does not stop to ask. It resolves each gap with the most typical answer and moves on, so the unmade decisions surface later as bugs or security holes.

GitHub's write-up introducing its Spec Kit toolkit puts the diagnosis in one line: language models are "exceptional at pattern completion, but not at mind reading." Spec-driven development (SDD) is the response. You write the decisions down before any code exists, in a form the agent can follow and a reviewer can check.

Key idea: An agent's output can only be as precise as its input. A spec moves decisions out of the agent's guesswork and into a document a human approved.

2. The pipeline from intent to merged code

Each stage narrows the space of possible programs. Spec Kit runs it as specify, plan, tasks, implement; Kiro writes the same layers to requirements.md, design.md and tasks.md. When verification finds a mismatch, the fix starts at the spec, not in the code.

flowchart LR
  A["Intent"] --> B["Spec: what and why"]
  B --> C["Plan: how"]
  C --> D["Tasks: small units"]
  D --> E["Implement"]
  E --> F["Verify against the spec"]
  F --> B

3. Spec, plan, tasks: what goes where

The layers stay useful only if each holds one kind of decision. Mixing them is the commonest failure: a spec that names the database invites the agent to treat a guess as a requirement.

LayerAnswersContainsKiro file
SpecWhat and whyUser journeys, acceptance criteria, edge cases, success outcomesrequirements.md
PlanHowStack, architecture, data models, interfaces, error handling, testing strategydesign.md
TasksIn what orderDiscrete units, each with an expected outcome and its dependenciestasks.md

GitHub's guidance for the spec stage is explicit that it is "not about technical stacks or app design." That separation lets you change the plan, say by swapping a queue library, without reopening what the feature must do. It also lets a product owner review the spec without reading any architecture.

4. EARS: requirements an agent can test

Free-prose requirements are where ambiguity hides. The Easy Approach to Requirements Syntax (EARS), developed by Alistair Mavin and colleagues at Rolls-Royce and presented at the IEEE Requirements Engineering conference in 2009, constrains each requirement to a fixed clause order with a few keywords:

PatternTemplate
UbiquitousThe system shall response
Event-drivenWHEN trigger, the system shall response
State-drivenWHILE state, the system shall response
Unwanted behaviourIF condition, THEN the system shall response
Optional featureWHERE feature is included, the system shall response

Kiro's documentation writes acceptance criteria in this form, for example "WHEN a user submits an email that already exists THE SYSTEM SHALL display 'Email already registered' error". The payoff for agent work is mechanical: every EARS line names a trigger and an observable response, which is exactly the shape of a test case. A requirement you cannot phrase this way is usually one you have not decided yet.

5. Worked example: password reset

Here is the vague request turned into numbered EARS requirements. The IDs matter later, when tasks and tests cite them.

## Requirements: password reset

R1. WHEN a user submits a registered email on the reset form,
    the system shall send a single-use reset link valid for 30 minutes.
R2. WHEN a user submits an unregistered email,
    the system shall show the same confirmation message as in R1.
R3. WHEN a new reset link is issued,
    the system shall invalidate all earlier links for that account.
R4. IF a reset link is expired or already used,
    THEN the system shall reject it and offer to send a new one.
R5. IF more than 5 reset requests arrive for one email within an hour,
    THEN the system shall stop sending emails to that address for one hour.
R6. WHEN a password is changed through a reset link,
    the system shall end all other active sessions for the account.

R2 and R5 are the lines a bare prompt rarely produces. R2 prevents account enumeration, where an attacker learns which emails have accounts. R5 stops the form being used to flood someone's inbox. Both are security decisions, and both are now reviewable before a line of code exists.

6. The plan, and the constitution above it

The plan translates the spec into technical choices: which framework, where tokens are stored, how they are hashed, what the email service interface looks like, how errors propagate. An agent is genuinely useful as a drafter here, because it can survey the codebase and propose a design faster than a person can. It is also where human approval matters most, since a wrong architectural choice is expensive to unwind once twenty tasks have built on it.

Spec Kit adds a layer above every plan, a constitution. In Birgitta Böckeler's description on martinfowler.com, it holds "high level principles that are 'immutable' and should always be applied, to every change." Typical entries: every feature ships with tests, no new runtime dependency without approval, all user input is validated at the boundary.

Gotcha: Decisions that are hard to reverse, such as a new external dependency, a schema change or an authentication mechanism, belong in the plan explicitly. Left implicit, the agent makes them inside a task, where no reviewer is looking for them.

7. Tasks: one reviewable diff each

GitHub's guidance is that each task should be "something you can implement and test in isolation." A practical size rule follows: one task, one diff a reviewer can read in a single sitting. Each task names the requirements it satisfies, which gives traceability in both directions.

## Tasks

- [ ] T1. Add reset_tokens table: token hash, user_id, expires_at, used_at (R1, R3)
- [ ] T2. Token service: issue, invalidate earlier tokens, verify single use (R1, R3, R4)
      depends on: T1
- [ ] T3. Rate limiter keyed by email, 5 per hour (R5)
- [ ] T4. Reset form endpoint with a uniform response (R1, R2, R5)
      depends on: T2, T3
- [ ] T5. Revoke other sessions after a successful reset (R6)
      depends on: T2

The dependency lines are not decoration. Kiro builds a dependency graph from its task list and groups independent tasks into waves that run concurrently; here T1 and T3 could start in parallel. A requirement with no task is a gap you can see before implementation, and a line of code with no requirement is scope nobody asked for.

8. Does a spec bind the agent?

Predict first

You hand an agent an approved spec and task list. Will the code it writes satisfy every requirement?

This is why acceptance criteria have to become something executable. Each EARS line maps to at least one test: R4 becomes a test that replays a used link and expects rejection, R2 a test that compares the responses for a registered and an unregistered email. The spec states intent; the tests are what actually hold the agent to it. GitHub's own framing of the human role in SDD says the same: "your role isn't just to steer. It's to verify." Making that verification hard to fake is a discipline of its own.

9. Spec-first, spec-anchored, spec-as-source

Böckeler distinguishes three levels of SDD by what happens to the spec after the code is written:

LevelThe spec after mergeMain risk
Spec-firstWritten for the task, then left behindSpec and code drift apart immediately
Spec-anchoredKept and updated as the feature evolvesDiscipline: every change must touch the spec too
Spec-as-sourceThe main artifact; humans edit only the spec and code is regeneratedRegeneration must be reliable and reviewable

In her evaluation, the tools she tested worked mostly at the spec-first level, with only one explicitly aiming for spec-anchored. The level you choose sets the maintenance contract. A spec-first document is a planning aid with a short shelf life. Treating it as current documentation six months later is how teams end up trusting a description the code no longer matches.

10. When the overhead pays, and when it does not

SDD has a real cost. Böckeler describes a small bug fix that Kiro expanded into 4 user stories with 16 acceptance criteria, "like using a sledgehammer to crack a nut," and says she would rather review code than a pile of markdown files. The method pays when the cost of a wrong guess is high:

SituationApproach
One-line fix with a clear reproductionPrompt plus a failing test; no spec
Small change inside one moduleShort task description with acceptance criteria
New feature across several components or stakeholdersFull spec, plan and tasks
Security, payments, data deletion, complianceFull spec with explicit unwanted-behaviour requirements
Exploratory prototype you will discardSkip the spec; write one if the prototype survives

In practice: Scale the spec to the blast radius of a mistake, not to the size of the request. A two-line change to an authorization check deserves more written intent than a new admin page.

Check your understanding

The lesson ends with a 5-question quiz. Take it in the player above to see your score.

  1. Which of these belongs in the spec rather than in the plan?
    • Storing reset tokens in PostgreSQL
    • Unregistered emails get the same confirmation message as registered ones
    • Hashing tokens with SHA-256 before storage
    • Splitting the work into five tasks
  2. Which EARS pattern fits: "If a payment authorization times out, the system shall release the reserved stock"?
    • Event-driven (WHEN)
    • State-driven (WHILE)
    • Optional feature (WHERE)
    • Unwanted behaviour (IF ... THEN)
  3. Why should each task cite the requirement IDs it satisfies?
    • It traces code back to an approved decision and exposes requirements with no task
    • Agents refuse to run tasks without IDs
    • It makes the spec executable on its own
    • It removes the need for code review
  4. A team approves a detailed spec and lets an agent implement it. What is the main remaining gap?
    • Agents cannot read markdown specs
    • Specs always make agents slower than plain prompts
    • Nothing checks the code meets the spec unless acceptance criteria become tests
    • The plan always overrides the spec
  5. In Böckeler's terms, a team that keeps the spec in the repo and updates it whenever the feature changes is practicing:
    • Spec-first
    • Spec-anchored
    • Spec-as-source
    • Vibe coding

Related lessons

Programming
intermediate

Securing AI-Generated Code: Insecure Defaults, Phantom Packages, Poisoned Context

Generated code that works is often not code that is safe. Learn what studies show about vulnerabilities in AI-written code, how hallucinated package names become a supply-chain attack, how hidden instructions hijack agents, and the controls that catch each risk.

10 steps·~15 min
Programming
intermediate

Verifying Agent-Written Code: When Passing Tests Is Not Proof

A green test suite is the agent's claim, not your proof. Learn the documented ways coding agents game tests, the controls that measurably reduce it, and a layered verification stack: frozen tests, property-based tests, mutation testing and diff review.

10 steps·~15 min
Programming
intermediate

Benchmarks That Hold Up, and Knowing When to Stop

A benchmark is an experiment, and most are badly designed enough to produce confident wrong answers. This lesson covers what a measurement must control to mean anything, the ways microbenchmarks lie including code the compiler deletes, how to catch regressions in continuous integration despite noisy machines, and how to recognise the point where optimising stops paying.

7 steps·~11 min
Programming
intermediate

Measure First: The Arithmetic That Decides What to Optimise

Most optimisation effort is spent on code that was never the problem, and the reason is that intuition about where time goes is reliably wrong. This lesson covers why guessing fails, the arithmetic that caps what any optimisation can buy, the difference between latency and throughput, and how to set a target that tells you when to stop.

7 steps·~11 min