Guide

The AI Spec File: Anatomy and a Template

An AI spec file is a short, reviewable document that tells a coding agent exactly what to build and how you'll judge it, the single highest-leverage piece of context per task. Here is what goes in one, a full copyable example, and where it lives.

By Kylian Migot · Updated July 2026 · 11 min read

Quick answer

An AI spec file is a short, written, reviewable document that tells a coding agent exactly what to build and how you will judge whether it succeeded. It sits between a vague prompt and a full PRD, bigger than a one-liner, smaller than a design doc, and it is scoped to a single task. Unlike an AGENTS.md, which is durable project context, a spec file is per-task and ships with the change it describes.
One-line definition
A per-task document: what to build, what not to touch, how success is judged
Where it sits
Prompt < spec file < PRD
The core sections
Goal · scope · non-scope · files · acceptance criteria · test plan · risks
The heart of it
Acceptance criteria a reviewer or test can mark true or false
01

What an AI Spec File Is, and Where It Sits

An AI spec file is a short, written, reviewable document that tells a coding agent exactly what to build and how you will judge whether it succeeded. It is the single highest-leverage piece of context you can attach to a task: not a paragraph of hopeful prose, but a bounded contract that names the goal, the scope, the files in play, and a set of checkable acceptance criteria. Give an agent a good spec file and it works toward something verifiable; give it a bare prompt and it infers all of that, usually wrong.

The easiest way to place it is by size. A prompt is a sentence or two, fast to write and fine for throwaway work, but it leaves scope, boundaries, and definition of done to the model. A PRD is a full product requirements document: personas, rationale, rollout, metrics, written for a team over weeks. A spec file sits between them, bigger than a one-liner, smaller than a design doc, scoped to one concrete change and written to be read in two minutes. The methodology of working this way, why the plan comes before the code at all, is its own topic; this page is about the artifact itself.

One distinction trips people up constantly: a spec file is not the same thing as your CLAUDE.md or AGENTS.md. Those are durable project context, the conventions and commands that apply to every task and rarely change. A spec file is per-task and disposable. You keep one AGENTS.md for the repo and write a fresh spec for each story; the agent reads both.

DimensionAGENTS.md / CLAUDE.mdSpec filePRD
ScopeWhole projectOne task / one changeA product or feature area
LifespanDurable, evolves slowlyDisposable, dies with the mergeWeeks to months
AudienceEvery agent, every sessionOne agent + its reviewerTeam, stakeholders, PM
ContainsCommands, conventions, boundariesGoal, scope, files, acceptance criteriaPersonas, rationale, metrics, rollout
Written bySet up once, generated + tunedPer story, drafted then approvedProduct, over multiple drafts
02

The Anatomy of a Good Spec File

A useful spec file is short and has a fixed shape, so it is skimmable and nothing important gets forgotten. Seven sections cover almost every task; drop the ones that do not apply, but never drop the acceptance criteria.

Goal / why

One or two sentences on what changes and the reason it matters. The reason is not decoration, it lets the agent make sensible micro-decisions the spec did not anticipate.

Scope (in)

The concrete work that is in bounds: the behavior to add, the endpoint to change, the exact mechanism. Specific enough that the agent is not guessing at how deep to go.

Non-scope (out)

What must stay untouched, named explicitly. Often the most valuable section: it is what stops a refactor from leaking into the payment module or the auth schema.

Affected files / interfaces

The files to create, modify, or read, and any interface that changes. Naming the files kills the hallucinated-scope failure mode, the agent cannot wander into what is not listed.

Acceptance criteria

A checklist of statements a reviewer or a test can mark true or false. This is the reviewer's contract and the agent's target. Covered in detail below.

Test plan

How the change gets verified: which unit tests, which integration path, what to check manually. Gives the agent something to run before you ever see the diff.

The seventh section is risks and rollback: the one or two things that could go wrong (a dependency that must fail open, a migration that is hard to reverse) and how you would back the change out. On small changes it is a single line; on anything touching data or auth it earns its place. Keep the whole file shorter than the diff it describes, if the spec is longer than the change, you are over-specifying.

03

A Full, Copyable Spec File

Here is a complete spec file for a realistic, self-contained task, adding per-IP rate limiting to POST /api/login. Copy it, change the nouns, and you have a template for most tasks. Note how every acceptance criterion is a checkbox you could tick during review, and how the non-scope section does as much work as the scope section.

# Spec: per-IP rate limiting on POST /api/login

## Goal / why
Brute-force attempts against POST /api/login are unthrottled. Add
per-IP rate limiting so an attacker cannot try passwords at machine
speed. Success = a single IP is capped at 5 login attempts per minute.

## Scope (in)
- Add a rate-limit check to the POST /api/login handler only.
- Use a fixed window of 5 attempts / 60s, keyed by client IP.
- Store counters in the existing Redis client (src/lib/redis.ts).
- Return 429 with a Retry-After header when the limit is exceeded.

## Non-scope (out) — do NOT touch
- Any route other than POST /api/login.
- The password-hashing or session logic (src/lib/auth.ts).
- The User schema or any migration.
- Global/CDN-level rate limiting (handled at the edge separately).

## Affected files / interfaces
- src/app/api/login/route.ts   (modify: add limiter call)
- src/lib/rate-limit.ts        (create: fixedWindow(key, max, windowSec))
- No public interface changes; response shape unchanged except 429.

## Acceptance criteria (checkable)
- [ ] 5 valid-shaped POSTs from one IP within 60s all return normally.
- [ ] The 6th POST from that IP within the window returns 429.
- [ ] The 429 response includes a Retry-After header in seconds.
- [ ] A different IP is unaffected by the first IP's counter.
- [ ] After the 60s window elapses, that IP can attempt again.

## Test plan
- Unit: fixedWindow() increments, expires, and isolates by key.
- Integration: hit the route 6x in a loop, assert 200x5 then 429.
- Manual: confirm Retry-After decreases on repeated blocked calls.

## Risks / rollback
- Risk: Redis outage should fail OPEN (allow), not lock users out.
  Wrap the check in try/catch; on error, log and permit the request.
- Rollback: remove the limiter call from route.ts; no schema change,
  so revert is a single-file diff.
04

Acceptance Criteria Done Right

The acceptance criteria are the part of the spec file that actually earns its keep. They are the reviewer's contract: the set of statements that, if all true, mean the work is done, and if any is false, mean it is not. Written well, they turn code review from “re-read the whole diff and hope” into “walk the checklist.”

The single rule: every criterion must be checkable. Compare:

Not a criterion (unverifiable)A real criterion (checkable)
Login should be more secureThe 6th login POST from one IP within 60s returns 429
Handle errors gracefullyOn Redis error the request is permitted, not blocked
Good test coveragefixedWindow() has unit tests for increment, expiry, isolation
Fast enoughThe limiter adds under 5ms p95 to the login handler

The left column reads fine and means nothing: no reviewer and no test can mark it true or false, so it silently becomes “whatever the agent decided.” The right column is a target the agent can verify against before you see the diff, and a checklist you can run against the PR. If a criterion is not checkable, it is not finished, either make it concrete or move it to the goal section as context.

Your AI workspace for shipping software.

Download AIDEN free and point it at your existing Claude Code or Codex setup. No credit card, running in minutes.

Download AIDEN free

Free to start · macOS 12+ · No credit card required

05

Where Spec Files Live, and How They Version

There are two good homes for a spec file, and the choice is mostly taste:

In the repo, under specs/

One Markdown file per change, e.g. specs/2026-07-24-login-rate-limit.md, committed on the same branch as the code. The spec versions with the change: the diff and its intent land together, and the file is right there in the merged PR.

On the story card

The spec lives attached to the task in your board or tracker and travels with it through review. Nothing extra to commit; the audit trail lives in the workflow tool alongside the discussion and the PR link.

The rule underneath both options: the spec versions with the code it describes. That is what makes it worth writing. Six months later, the spec attached to a merged PR tells you exactly what was decided and why, in a way a chat log almost never can. If you keep specs in-repo, the free story and spec templates give you consistent starting files, and the agent spec builder turns a short story into a filled-in draft you can drop straight into specs/.

06

Common Mistakes

Most bad spec files fail in one of four predictable ways. All are easy to fix once you can name them.

07

Spec Files in the Workflow

A spec file is not a document you write and file away, it is a working artifact that shows up three times in the life of a task, and each appearance is a payoff:

  1. 1

    It feeds the agent

    The approved spec becomes the agent's brief, the primary task context in its window. This is the highest-value lever in context engineering: a clean window plus a sharp spec beats a cluttered window with a clever prompt, every time.
  2. 2

    It gates approval

    Reviewing and approving the spec, before any code exists, is the cheapest place to catch a misunderstanding. Two minutes on the spec routinely saves an hour of re-review on the diff. In a kanban flow the card sits in a spec-review column until you sign off.
  3. 3

    It becomes the PR review checklist

    When the PR opens, the same acceptance criteria are the review checklist, and the spec ships as the PR description. Review is now “walk the list,” not “re-read the diff cold.” This is what makes PR automation trustworthy: the bot, or you, checks the diff against a written contract, not a memory.

The same file, three jobs. That reuse is why the spec file earns the few minutes it takes: it is the brief, the gate, and the checklist at once, and the guardrails that carry it across those stages are what a good agent harness provides.

08

How AIDEN Uses Spec Files

AIDEN's board is built around the spec file as the unit of work. Cards move through Project → Epic → Story → Spec: you write a one or two sentence story, and AIDEN drafts the full spec file, goal, scope, non-scope, affected files, acceptance criteria, from your card plus its analysis of your codebase. You review, edit anything that is off, and approve. Since v1.5.21 that approval is an enforced gate: no agent starts coding without an approved spec.

After approval, the same file does the rest of its jobs automatically. AIDEN opens a git worktree per story and launches your Claude Code or Codex CLI with the spec as the working prompt, you keep BYO inference, running your own subscriptions or keys. When the agent is done, the PR is one click from the card with the spec attached as the description, so the acceptance criteria are the review checklist. The spec you approved is the brief the agent worked from and the contract you review against, no retyping, no drift.

You can draft spec files this way outside the board too: the agent spec builder turns a short story into a filled-in spec, and the story and spec templates give you a consistent starting shape. AIDEN is a cockpit over the CLIs you already use, and it is $19/mo for Solo, free for one project, so the whole spec-first loop costs nothing to try.

FAQ

What is a spec file for AI?
An AI spec file is a short, written, reviewable document that tells a coding agent exactly what to build and how you will judge whether it succeeded. It names the goal, the scope that is in and out, the files and interfaces it may touch, and concrete acceptance criteria. It sits between a vague prompt and a full PRD, bigger than a one-liner, smaller than a design doc, and it is scoped to a single task rather than the whole project.
How is a spec file different from CLAUDE.md or AGENTS.md?
CLAUDE.md and AGENTS.md are durable project context: build commands, conventions, and boundaries that apply to every task and rarely change. A spec file is per-task and disposable: it describes one change, ships with that change, and is done once the work merges. You keep one AGENTS.md for the repo and write a fresh spec file for each story. They complement each other, the agent reads both.
What goes in a good AI spec file?
Seven sections: goal and why, scope (what is in), non-scope (what is explicitly out), the files and interfaces it may touch, checkable acceptance criteria, a test plan, and risks with a rollback note. The acceptance criteria are the heart of it, each one should be a statement a reviewer or a test can mark true or false, not a vibe. If a criterion is not checkable, it is not a criterion yet.
Where should spec files live?
Either in the repo under a specs/ directory, one Markdown file per change, versioned alongside the code it describes, or attached to the story card in your workflow tool so it travels with the task. Both work; the rule is that the spec versions with the change. When the code merges, the spec that produced it is right there, six months later it tells you exactly what was decided and why.
Does AIDEN write the spec file for me?
Yes. You write a one or two sentence story card and AIDEN drafts the full spec file from your card plus its analysis of your codebase: scope, files, acceptance criteria, and exclusions. You review, edit anything that is off, and approve. Since v1.5.21 that approval is an enforced gate, no agent starts coding without an approved spec. The same file then becomes the agent's brief and the PR review checklist.

Keep reading

Every story gets a spec file, drafted for you.

AIDEN drafts a spec file from your story card and codebase, gates the agent behind your approval, then uses it as the brief and the PR review checklist. Free for one project.

macOS 12+ · Bring your own Claude Code or Codex · Your code stays local