Skip to content
stacks

Spec-driven development with Claude Code

Use spec-driven development with Claude Code by writing requirements before code, reviewing a plan, and turning acceptance criteria into runnable checks.

Published 8 min read

Spec-driven development with Claude Code starts with written requirements and acceptance criteria before code. Ask Claude to propose a plan, review its tasks, then implement against checks you can run yourself.

A hand-written PRD.md is enough to begin. Use Claude Code's planning tools to inspect the repository before approving changes, and give each requirement an observable result. The part that needs care is verification: a sentence saying the feature works still needs a test or a recorded manual check.

What is spec-driven development with Claude Code?

A spec gives the agent a written target for its decisions. Requirements describe the behavior you need; the plan explains the implementation approach. Tasks divide that plan into work you can review. Acceptance criteria define the evidence you expect before calling the work complete.

Claude Code's Plan mode lets you review an approach before edits begin. Ask it to read the relevant code and identify open decisions, then propose tasks against your spec. Review those tasks for missing behavior before authorizing implementation. A plan that omits error handling has already lost part of the requirement.

Project instructions can point Claude toward the spec. Run /init to draft a starting CLAUDE.md from the repository, then review the generated instructions. Anthropic's project memory documentation explains this setup. Keep ongoing conventions in that file and tell Claude which feature spec to read for the current job.

Existing spec tools add structure if you want it. GitHub Spec Kit's workflow carries a specification through planning and tasks into implementation and convergence. Kiro organizes feature specs into requirements, design and task documents. You can also write those documents yourself and ask Claude to work through them. The choice affects how you organize the work; you still need evidence for the acceptance criteria, which is what making Claude Code run tests before it's done is about.

What should a spec for a coding agent include?

A useful spec resolves the choices that would otherwise interrupt implementation. Describe who needs the feature and what they should be able to do. Set scope boundaries explicitly, including behavior you are deferring. Specify inputs and outputs precisely enough that another developer could write a test without asking what you meant.

A small log-filtering CLI makes a concrete example. Suppose you need to select error records from a local file and pipe the results into another command. A PRD template for Claude Code could look like this; the command behavior is a proposed requirement, not output from an existing tool.

PRD.md
# Filter error records from a log file

## Goal
Let a developer extract error records without opening the whole file.

## Inputs and outputs
Read a UTF-8 file of newline-delimited JSON objects.
Each object has a string level field.
Write records whose level is exactly "error", one per line, in input order.
Preserve each matching record's original text.

## Scope
Support local files only. Defer stdin and compressed files.
Write diagnostics to stderr so stdout remains usable in a pipeline.

## Failure behavior
An unreadable file exits nonzero with a diagnostic.
A malformed record exits nonzero and identifies its line number.

## Acceptance criteria
A mixed fixture emits only its error records, unchanged and in order.
A file with no error records produces empty stdout and exits zero.
Malformed input and a missing file exercise the failure behavior above.

## Decisions
Confirm the executable name before implementation.

## Plan and tasks
Ask Claude to propose these after reading the existing project.

Error semantics deserve their own review. The example leaves open whether valid records written before a malformed line remain on stdout. Decide that before implementing the parser: buffering the entire result and streaming records have different consequences for large files. Record the choice in the spec and add a fixture that tests it.

The agent's plan should connect work to requirements. For this CLI, parsing and filtering need focused tests, while exit status and stream handling need tests that invoke the executable. Reject a task such as "finish CLI" if it hides those separate behaviors. A task is easier to review when its completion points to a specific test result.

How do you write acceptance criteria an agent can run?

Turn each observable requirement into an assertion in the project's test suite. The mixed fixture should compare exact output, including order. The missing-file case should check the exit status and stderr, with an assertion about stdout too. "Tests pass" means little if the tests never exercise the failure behavior promised in the spec.

Keep prose and execution connected through the project's normal commands. Ask Claude to implement the tests and run the same commands you would use during review. Save the commands alongside the spec, and inspect the assertions when reviewing the diff. A passing process can only establish what its checks actually cover.

stacks (@steamfield/stacks) records that split in two generated files. .stacks/BRIEF.md is the build spec the agent reads. .stacks/manifest.json records the commands that stacks verify executes. The brief includes a definition-of-done table, but verify reads the manifest. Editing the brief changes nothing verify checks.

The brief combines the stack's guidance with selected fragments, which add instructions for capabilities such as CI or git hooks. It includes decisions with defaults and sections for dependencies and tools. Under the default preset, it tells the agent to ask about decisions once in one message. With --yes or --sandbox, it tells the agent to use the defaults.

You can inspect a composed brief before creating a project. This command previews the Go CLI recipe with the sandbox preset; it writes no project and starts no processes. The validation reference explains the preview's fixed context and composition options.

Preview the brief
stacks validate --brief go-cli --sandbox

The scripted demo below shows excerpts captured with stacks 0.7.0. It previews the brief, then reads an already-generated project's definition-of-done table and manifest commands. The preview and the generated project use the same composition. No verification checks run in this recording.

Agent + stacks
Demo

You: Show me the build instructions and checks before we implement the log tool.

Agent: I’ll preview the composed brief first.

●Bash(stacks validate --brief go-cli --sandbox)
# Build project: Go CLI
## Your job
## Decisions
## Dependencies and tools
## Stack: Go CLI (`go-cli`)
## Fragment: AGENTS.md and agent guardrails (`agent-ops`)
## Fragment: GitHub Actions CI (`ci-github`)
## Fragment: Git hooks (lefthook) (`git-hooks`)
Output abbreviated

Agent: The brief includes stack guidance and each fragment’s instructions. Its definition of done lists the checks.

You: Where are those checks recorded for the project?

●Bash(cat log-scan/.stacks/BRIEF.md)
## Definition of done
| Step | Phase | Layer |
|---|---|---|
| `install` | setup | install |
| `build` | check | build |
| `lint` | check | lint |
| `test` | check | test |
Output abbreviated
●Bash(cat log-scan/.stacks/manifest.json)
"verify": [
"name": "install",
"run": "make install",
"phase": "setup",
"name": "lint",
"run": "make lint",
"name": "test",
"run": "make test",
Output abbreviated

Agent: The generated brief lists the steps; .stacks/manifest.json records their commands. I’ll implement against those checks and use stacks verify to run them.

Example agent conversation. Playback can be paused.

Previewing a Go CLI brief, then inspecting the verify steps and commands recorded for the same composition.

The manifest keeps those checks available after the build instructions have served their purpose. Commit it with the project; the brief is git-ignored. Someone who clones the repository can run stacks verify without the brief or the registry. The brief and manifest documentation explains what each file contains.

Green verification covers the recorded checks, so feature-specific tests still need to be written. A recipe's lint and build steps cannot establish that log filtering preserves record order. The brief defines done as verify exiting zero with outcome green; review the behavior tests and perform any manual QA alongside that result.

How long should the spec be?

Spec length should follow the number of decisions the agent needs to make. A local CLI can start with a short document like the example above. A feature involving permissions or persistent data needs more detail about failure cases and existing contracts. Add detail where two competent developers could implement different behavior from the same sentence.

Reusable project guidance can make a generated brief longer than a feature PRD. stacks allows up to 6,000 words in a composed brief, including its fixed instructions, or 9,000 with an app. Those are validation limits, not targets for your own spec. The authoring guide describes how to write reusable stack and fragment guidance within the budgets.

Repeated instructions are a reason to shorten the document. Link to an existing convention where it applies, and write the current feature's decisions next to its requirements. Review the spec for contradictions after the plan changes. Keeping an obsolete paragraph "for context" gives the agent another plausible instruction to follow.

What happens when the spec is wrong?

Correct a wrong requirement before asking the agent to work around it. If users need stdin after all, update the scope and agree on its acceptance tests. Keep the reason with the change so the reviewer can distinguish a deliberate requirement update from an implementation that wandered outside the original task.

Generated stacks briefs have a place to record these problems. The agent adds ambiguities and incorrect instructions under ## Findings in .stacks/NOTES.md; questions it asked belong under ## Asked. Fix reusable guidance in the stack or fragment that produced it. Changing BRIEF.md alone leaves the manifest's checks untouched.

Changes to recorded verify steps require separate acceptance. Verify compares their digest with the manifest and the project's local state record before running. If they disagree, it runs nothing. A person can review the change and accept it at their terminal; the CLI refuses acceptance under a detected agent. The verify reference covers this process and its limits, including the weaker check on a fresh clone.

The digest leaves test contents and the code behind commands outside its coverage. An agent could weaken a test while keeping the same test command. Review those diffs even when verification is green, especially after a requirement changes.

Do I need Spec Kit to work this way?

Start with a hand-written spec when the main problem is an unclear feature request. You can review requirements and a plan directly in Claude Code. Add Spec Kit when its structured artifacts help your team manage that work. Kiro is another option if you want its spec workflow in your development environment.

Spec-driven development with Codex can use the same requirements and acceptance tests. The example PRD describes executable behavior independently of the agent. If you use stacks, its --agents option selects the agent files to write; every target gets AGENTS.md. Keep the feature's tests runnable through ordinary project commands so a change of agent leaves your acceptance evidence usable.