Spec-Driven Development

Write a clear spec that an agent implements: goals, scope, acceptance criteria, and constraints as the source of truth.

TL;DR

  1. For larger work, write a spec the agent implements: goals, scope, acceptance criteria, constraints.
  2. Acceptance criteria make 'done' checkable, so you can verify the result against the spec.
  3. The spec is the source of truth; refine it, not the code, when requirements change.

Why Spec First

    Right Thing

    A clear spec aligns the build with what you actually need.

    Spec defines the target before
    any code is written.
    Checkable Done

    Acceptance criteria let you verify success objectively.

    Done = all criteria pass,
    not "looks finished".
    Source Of Truth

    The spec, not the code, is what you refine as needs evolve.

    Change requirements -> change spec
    -> reconcile code.

Anatomy Of A Spec

    Goal & Why

    State the outcome and the reason it matters.

    "Let users export orders to CSV so
    they can reconcile in Excel."
    Scope

    What is included and, explicitly, what is not.

    In: CSV export of filtered orders.
    Out: PDF, scheduling, email.
    Constraints

    Stack, performance, security, and compatibility limits.

    "Stream for >10k rows; owner-only;
    no new deps."

Acceptance Criteria

    Testable Statements

    Write given/when/then so each is verifiable.

    "Given 0 orders, when I export,
    then I get a header-only CSV."
    Cover Edges

    Include empty, large, and error cases, not just the happy path.

    "Given a failed query, then a 500
    with a safe message."
    Doubles As Tests

    Criteria map directly to the tests that prove done.

    Each criterion -> one test.

Drive The Build

    Hand Over The Spec

    Give the agent the spec and ask for a plan against it.

    "Here's the spec. Plan the
    implementation against it first."
    Verify Against It

    Check the build criterion by criterion.

    "For each acceptance criterion,
    show it is met."
    Keep Spec Current

    When scope shifts, update the spec and re-reconcile.

    Edit spec -> "reconcile the code
    to the updated spec."

Tips

  1. Write acceptance criteria as testable statements ('given X, when Y, then Z').
  2. State what is explicitly out of scope so the agent does not gold-plate.

Warnings

  1. A vague spec yields a confident wrong feature; ambiguity in the spec becomes bugs in the build.
  2. Skipping acceptance criteria leaves 'done' undefined, so you cannot tell if the agent succeeded.

In Practice

FAQ