Write a Spec Before You Prompt: Planning Features for AI Coding Agents
AI coding agents build exactly what you describe, gaps and all. A one-page spec written before you prompt saves hours of rework. Here's a simple template and how to use it.
There is a moment many developers hit after a few weeks with AI coding agents. You ask for a feature in one breezy sentence. The agent gets to work, edits a dozen files, and hands back something that runs. Then you look closer and realise it built a slightly different feature than the one in your head.
The agent didn't fail. Your request had gaps, and it filled them with reasonable guesses. The fix is not a cleverer prompt. It is a short written spec, prepared before you prompt.
Why specs matter more with AI, not less
When you hand a vague task to a human teammate, they ask questions. "Should this work for guest users too?" "What happens if the file is empty?" Some AI agents ask clarifying questions too, but many will simply pick an answer and keep going.
Because agents work fast and touch lots of files, a wrong assumption early on spreads quickly. Five minutes of planning can save an hour of untangling.
A spec also gives you something to review against. Without one, "is this right?" becomes a gut feeling. With one, it is a checklist.
The one-page spec template
You don't need a formal document. A plain Markdown file in your repository works perfectly. Here is a template:
# Feature: [name]
## Goal
One or two sentences: what problem this solves and for whom.
## In scope
- Bullet list of what this change includes
## Out of scope
- What it deliberately does NOT include (yet)
## Behaviour
- Step-by-step description of what the user does and what happens
- Include the unhappy paths: errors, empty states, invalid input
## Acceptance criteria
- [ ] Testable statements that must be true when done
## Constraints
- Files or modules to change (and ones not to touch)
- Libraries to use or avoid
- Performance, security or accessibility requirements
## Open questions
- Anything you haven't decided yet
Most features fit on a single screen. If yours doesn't, it may be several features in disguise.
Filling it in: a worked example
Imagine you want to add "export to CSV" to a reports page. A one-line prompt might be: "Add a CSV export button to the reports page."
A spec forces decisions:
- Scope: Export only the currently filtered rows, or everything?
- Out of scope: No Excel format, no scheduled exports.
- Behaviour: What's the file name? What happens if there are zero rows? What about very large reports?
- Acceptance criteria: "Downloaded file opens correctly in a spreadsheet app with headers in the first row." "Exporting with no rows shows a message instead of an empty file."
- Constraints: "Use the existing table data service. Don't add new dependencies."
Every one of those is something an agent would otherwise guess.
The agent will make every decision you don't. Decide the ones that matter yourself.
Let the AI help write the spec
There is no rule that says the spec must be written without AI. In fact, it is a great use of it. Try a planning conversation before any code is written:
Here's a rough feature idea: [your one-liner].
Here's some context about the codebase: [brief description or relevant files].
Don't write any code yet. Ask me the questions you'd need answered
to implement this well, then draft a spec using this template: [template].
The questions it asks are often the most valuable part. They surface edge cases you hadn't considered.
Then edit the draft yourself. You are the one who knows the product, the users and the trade-offs.
Using the spec with your agent
Once the spec is ready:
- Save it in the repo, for example in a
docs/specs/folder, so the agent can read it and so it lives alongside the code. - Point the agent at it: "Implement the feature described in
docs/specs/csv-export.md. Start by proposing a plan and list the files you'll change. Wait for my approval before editing." - Review the plan against the spec. Catching a wrong approach here is far cheaper than after the code is written.
- Ask for tests tied to acceptance criteria. "Write tests that cover each acceptance criterion."
- Review the result against the checklist. Tick each acceptance criterion yourself.
Keep it light
Specs can become bureaucracy if you let them. A few guardrails:
- Small fixes don't need one. A typo, a colour tweak or a one-line bug fix is fine as a direct prompt.
- Time-box it. Most specs should take 10 to 20 minutes.
- Update it when things change. If you discover something mid-build, change the spec, not just the code.
- Delete or archive old ones if they stop being useful, or keep them as lightweight documentation if your team finds them handy.
Where this fits in AI-driven development
In an AI-driven development lifecycle, much of the typing shifts to the agent. What remains with you is intent, judgement and verification. A spec is simply intent, written down clearly enough that both a machine and a teammate can act on it, and that you can check the result against.
The takeaway
Before your next feature, spend fifteen minutes on a one-page spec: goal, scope, behaviour, acceptance criteria, constraints. Let the AI ask you questions to help fill it in. Then hand it over and review against it. You'll get closer to the right feature on the first try, and you'll know exactly how to tell.
Enjoyed this piece?
Get the next one in your inbox, every other Friday.