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.

IntentSpecPlanTasksCode + testsWhen code and spec disagree, fix the spec first, then regenerateThe spec is the source of truth
The spec is the source of truth; code is generated from it and checked against 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

  1. Intent: a human writes the goal and constraints.
  2. Spec: AI expands it; humans edit and approve.
  3. Plan: AI proposes a technical plan of files, steps and risks. A human approves.
  4. Tasks: the plan splits into small, independently testable tasks.
  5. 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

AI-era lifecycle

AI-DLC: the AI-Driven Development Lifecycle

What AI-DLC is, how its three phases work, and how to adopt it without losing control of quality.

AI-era lifecycle

SDLC vs AI-DLC: what actually changes

A side-by-side comparison of the traditional lifecycle and the AI-driven one, and what it means for your team.

AI-era lifecycle

Secure SDL: building security into every phase

The Security Development Lifecycle in plain language, plus the new threats that come with AI-generated code and LLM features.