Spec-driven development with AI agents
Write the spec first, let AI plan and build from it, and keep the spec as the source of truth.
Key takeaways
- A clear spec is the best prompt you can write.
- Flow: intent, spec, plan, tasks, then code and tests.
- When code and spec disagree, update the spec first, then regenerate.
AI agents are excellent at doing exactly what you ask, which is a problem when you ask vaguely. Spec-driven development fixes that: you invest in a short, precise specification, and the AI plans and builds from it.
#What goes in a good spec
Keep it to one or two pages:
- Goal: the user problem, in one sentence.
- Scope: what's in and, just as important, what's out.
- Behavior: acceptance criteria as Given/When/Then examples.
- Constraints: performance, security, compatibility, libraries to use or avoid.
- Interfaces: API shapes, data models, events.
- Open questions: what you haven't decided yet.
## Feature: Password reset
Goal: Users who forget their password can regain access in < 2 minutes.
Out of scope: SMS reset, admin-initiated reset.
Given a registered email
When the user requests a reset
Then a single-use link valid for 30 minutes is emailed
And previous reset links are invalidated
Constraints: rate-limit 5 requests/hour/email; no user enumeration.
#The workflow
- Intent: a human writes the goal and constraints.
- Spec: AI expands it; humans edit and approve.
- Plan: AI proposes a technical plan of files, steps and risks. A human approves.
- Tasks: the plan splits into small, independently testable tasks.
- Code and tests: AI implements task by task; CI and humans verify.
AI tip: Ask the agent to write the acceptance tests before the implementation, and to show you the failing tests first. It's the quickest way to check it understood the spec.
#Why it works
- Fewer wrong turns: ambiguity gets resolved in text, where it's cheap.
- Better review: reviewers compare code to an agreed spec, not to a feeling.
- Reusable context: future changes start from an up-to-date description.
- Onboarding: new team members (and new agents) learn the system faster.
#Pitfalls
- Specs as novels. Long specs get skimmed by humans and AIs alike. Prefer examples to prose.
- Spec drift. If you fix behavior in code only, the next generation will "fix" it back. Update the spec.
- Specifying implementation. Describe behavior and constraints. Let the plan decide the how, then review it.
Keep reading
What AI-DLC is, how its three phases work, and how to adopt it without losing control of quality.
A side-by-side comparison of the traditional lifecycle and the AI-driven one, and what it means for your team.
The Security Development Lifecycle in plain language, plus the new threats that come with AI-generated code and LLM features.