Spec-Driven Development
Why This Matters
The quality of an agent’s work is limited by the quality of the request. For anything bigger than a small change, a short written spec beats a long prompt: it is reviewable before work starts, it gives the agent a stable reference, and it becomes the source for tests and the definition of done.
What a spec for an agent looks like
Keep specs in the repository, for example in docs/specs/, and use the same sections every time:
# Spec: <feature>
## Goal
One or two sentences: who gets what, and why.
## Acceptance criteria
Numbered, observable, testable. One behaviour per line.
## Out of scope
What we deliberately do not build now.
## Done when
Which criteria are covered by which tests, and which gates must be green.
And this is that spec implemented, on the solution branch solution/lesson-22-flaky-history:
Write specs an agent can execute reliably
- Observable criteria: “panel closes with Esc”, not “panel is user-friendly”.
- Numbers and examples: “last 20 runs”, “pass rate with one decimal”, “No runs recorded yet”.
- Edges included: empty, error, too much data, no permission.
- Out of scope stated: the best protection against scope drift (lesson 12, Failure Modes of AI-Generated Code).
- Tests mapped to criteria: so you can see which criterion is not covered yet.
From spec to tested change
- Draft the spec with the agent. Ask it to interview you and propose criteria, then edit them yourself. You own the spec.
- Review the spec with a tester or product owner before any code. This is the cheapest review in the whole process.
- Plan from the spec (plan mode): “Plan the implementation of docs/specs/flaky-history.md.”
- Tests from the criteria first (lesson 13, Test-First with an Agent (TDD)), then implementation.
- Close the loop: in the PR, list each criterion with the test that covers it.
Hands-on
- Write a spec for your next feature using the template.
- Ask the agent which criteria are ambiguous or untestable, and fix them.
- Generate tests from the criteria, then implement.
- Add the spec template to your repository, and a rule to CLAUDE.md: “For features larger than one file, ask for or write a spec in docs/specs/ first.”
Walkthrough in TestRun Board
- Compare the three specs in
docs/specs/. Each follows_template.md: goal, numbered acceptance criteria, out of scope, done when, open questions. - Use the
write-specskill for a new feature: “Write a spec for a suite filter (unit, api, e2e) on the runs page.” It should ask you questions first and stop after writingdocs/specs/suite-filter.md. - Review the spec: are the criteria observable (“shows Unit (2)”), are the empty and URL cases covered, is “Out of scope” filled?
- Ask a second session to find ambiguities: “Which criteria in docs/specs/suite-filter.md are ambiguous or untestable?” Fix them yourself.
- Look at how the worked solution for the flaky history panel closes the loop:
docs/solutions/lesson-22-flaky-history.mdmaps every acceptance criterion to the unit, component and e2e tests that cover it.
Key Takeaways
- A short spec in the repository beats a long prompt for anything non-trivial.
- Acceptance criteria must be observable, concrete and include edge cases.
- “Out of scope” prevents scope drift; “Done when” maps criteria to tests.
- The spec review is the cheapest quality gate you have.

