Automate technical spec generation from user requirements
Take a product requirement (from a ticket, doc, or conversation) and generate a technical spec that's a genuine starting point — not a wall of AI text your engineers rewrite anyway.
Prerequisites
- A team that writes technical specs before coding significant features
- An existing template you use (even if informal)
- Access to your codebase from Claude Code
- Willingness to iterate on the prompt based on real specs
What you'll learn
- Why most AI-generated specs get rewritten from scratch
- How to ground spec generation in your actual codebase
- The structure that produces useful drafts vs wall-of-text
- The human review step that makes the workflow trustworthy
- When to skip the workflow and just write from scratch
The dream: paste a product requirement, get a technical spec back. The reality when teams try this: the spec is generic, doesn't reference the actual codebase, misses the specific patterns your team uses, and the engineer rewrites most of it. Time saved: negative.
This tutorial fixes the fundamental problem: AI-generated specs fail because they're not grounded in your codebase. A spec written by a human who knows your code references specific services, matches your patterns, calls out real integration points. This workflow tries to do the same by making Claude read your code before writing the spec.
Try this: paste a real product requirement into any AI chat, ask for a technical spec. The output will be:
- Structurally OK (sections for API design, database changes, etc.)
- Generically written (references "the service," not "the checkout service specifically")
- Missing your team's specific patterns (uses generic API design, not what your team does)
- Padded with obvious content ("we should have tests," "consider error handling")
The engineer reads it, thinks "this is missing the actually important parts," and rewrites from scratch. The AI helped exactly zero.
The fix: make Claude read your actual code before writing. A spec that references specific files, functions, and patterns is far more useful than a spec that describes what a spec should generally look like.
---
description: Draft a technical spec grounded in the actual codebase
model: claude-sonnet-4-6
allowed-tools:
- Read
- Grep
- Glob
- Bash(git:*)
---
# Spec Drafter
You draft technical specs from product requirements. Your specs are
grounded in the actual codebase — you MUST read relevant code before
writing about affected components.
## Process
1. Read the requirement carefully
2. Identify affected areas of the codebase:
- Which services are touched?
- Which data models?
- Which UIs?
- Which integrations?
3. Read the code for each affected area
4. Write the spec using SPECIFIC references to the code you read
## Structure
Use this template:
### Summary
2-3 sentences: what we're building, why.
### Affected components
For each: the specific file/service, what changes, why.
Not generic ("we'll modify the frontend"). Specific ("src/features/
checkout/CartPage.tsx will need a new "gift wrapping" option").
### Data model changes
Specific tables/columns/types. Reference existing schema when
extending it.
### API changes
Specific endpoints. New endpoints listed with method + path + shape.
Existing endpoints noted with what changes.
### Integration points
Which external services get called? Which internal services?
Reference the current pattern for each integration if one exists.
### Failure modes
For each affected flow, what can go wrong and what happens.
Reference existing error handling patterns.
### Testing plan
What needs testing at what level. Reference existing test patterns.
### Migration or rollout considerations
Data migration if schema changes. Feature flag strategy. Rollout order.
### Open questions
Things you're unsure about. Mark clearly with `[OPEN: description]`.
## What to include vs skip
INCLUDE:
- Specific file paths and function names for areas being touched
- Existing patterns to match ("similar to how OrderService handles X")
- Real integration points (not "integrate with payments")
- Concrete data model changes (columns, types, constraints)
- Failure modes based on actual code paths
SKIP:
- Generic advice ("consider error handling")
- Standard sections that don't apply
- Restating the requirement in different words
- Speculating about business impact
## When you can't ground
If the requirement is vague or the code doesn't clearly indicate
where to make changes, flag it clearly:
`[OPEN: unclear which service should own this. Options:
CheckoutService (has cart logic), OrderService (has payment).]`
Don't make it up. Flag and let humans decide.
The key instruction is "you MUST read relevant code before writing." This changes the shape of the output dramatically — instead of describing generic patterns, the subagent references your team's actual patterns.
---
description: Draft a technical spec from a requirement
allowed-tools:
- Read
- Write
---
# /draft-spec
Draft a technical spec from the requirement provided.
## Usage
- `/draft-spec` with the requirement pasted after
- `/draft-spec docs/requirements/checkout-gift-wrapping.md` to read
from a file
- `/draft-spec JIRA-1234` to pull the requirement from an issue tracker
## Process
1. Read the requirement (from argument, file, or issue)
2. Invoke @spec-drafter with the requirement
3. Save output to `docs/specs/DRAFT-{slug}.md`
4. Show user the count of `[OPEN: ...]` items
5. Suggest: "Review the [OPEN: ...] items and update. When ready,
move to docs/specs/{slug}.md and open PR for team review."
The command produces a draft in a specific folder. It doesn't automatically publish or commit — the human has to review, adjust, and move to the "real" specs folder. This friction is deliberate: it prevents unreviewed drafts from becoming de facto specs.
The best calibration: run /draft-spec with a requirement you've already written a spec for. Compare the two.
What you'll notice:
- AI spec is more mechanical. Lists affected files, describes API changes, addresses testing. Good foundation.
- AI spec misses judgment. Doesn't know about the political dynamics, the specific customer that requested this, the trade-off you decided.
- AI spec catches things you might miss. Notices when the change affects a file you didn't initially consider.
- AI spec is worse at prioritization. Treats all changes equally instead of highlighting the risky parts.
The AI-drafted spec is not a substitute for your judgment. It's a foundation that saves you the mechanical work of listing affected files and doing initial impact analysis. Whether that's useful depends on the shape of your specs.
AI spec drafting saves time on mechanical parts. It doesn't save time on judgment parts. For specs where the judgment part dominates, the workflow doesn't help much. For specs with substantial mechanical listing/analysis, it saves real time.
AI-drafted specs never ship as specs. They go through a human editing pass that's the difference between "useful starting point" and "wall of AI-generated text."
The edit checklist:
- Address every [OPEN: ...] flag. These are the parts the subagent flagged as uncertain. Answer or reframe each.
- Add the "why" that's missing. AI describes what changes; humans add why the change is worth making. Business context, customer motivation, priority reasoning.
- Cut the mechanical parts that don't need to be spec'd. Not every change needs a whole spec section. Trim what's obvious.
- Flag risks the AI missed. Political sensitivities, cross-team dependencies, historical baggage. Things only humans know.
- Verify affected components. AI might miss things or list things that aren't actually affected. Check.
This edit typically takes 20-40 minutes for a medium-sized spec. If the AI draft was good, you're editing rather than rewriting. If the AI draft was bad, you're rewriting — in which case the workflow didn't help. Notice the failure case; adjust the prompt.
After a few uses, patterns will emerge. Common failure modes:
"Too generic still": the subagent isn't reading enough code. Add explicit instructions: "Before writing the API changes section, grep for existing endpoints and read at least 3." Force the grounding.
"Wrong files identified as affected": the subagent is making educated guesses without verifying. Add: "Only list files as affected if you've read them and can point to a specific line that would change."
"Missing the key risk": the subagent doesn't know what makes something risky in your codebase. Add examples: "In our codebase, changes to payment flow require extra scrutiny — see previous PR review comments for pattern."
"Padding with obvious content": the subagent is writing what a "good spec" should contain rather than what matters here. Add: "Skip sections that don't apply. Don't write 'we should test this' as its own section — testing is always required."
For your next real spec, use the workflow. Time it: how long does the draft take vs the edit vs writing from scratch. Compare to your typical spec-writing time. The workflow either saves time or it doesn't — the honest measurement tells you.
Some specs shouldn't be AI-drafted. Recognize when to skip:
- Small changes where the spec is a few paragraphs. Overhead of running the workflow exceeds value.
- Highly contextual specs where the judgment part dominates the content. AI can't help.
- Cross-team specs where the value is in the negotiation, not the technical detail. Spec drafts don't help with negotiation.
- Specs written by junior engineers as learning. The learning is the writing; skipping it defeats the purpose.
The workflow shines for medium-complexity specs affecting several components where mechanical impact analysis is the tedious part. Match the tool to the task.
Recap
You built a technical spec drafting workflow — a subagent that reads your actual codebase before writing, produces grounded drafts that reference specific files and patterns, flags open questions rather than fabricating answers.
The pattern that works: force grounding in real code, structured template with concrete sections, [OPEN: ...] flags for human judgment, edit step that's the actual spec creation. AI drafts; humans finish.
The pattern that fails: pasting requirements into a chat and hoping. Without grounding, the output is generic. Without the human edit step, the "spec" is a wall of AI text nobody reads carefully.
Common gotchas
- Drafts are generic despite prompt instructions: The subagent isn't actually reading code. Add explicit tool-use requirements: "Use Grep at least 5 times before writing the affected components section." Force the behavior instead of just asking.
- Drafts include speculation about things not in the codebase: Add: "Only reference things you have verified exist. If you assume something, mark with [ASSUMED]." Better to have flagged assumptions than confident-sounding fabrications.
- Team uses drafts as final specs: Structural fix: put drafts in a separate folder (DRAFT-*) and require explicit "move to real specs folder" step. The folder distinction makes the review step visible.
- Prompt engineering keeps chasing edge cases: Sign the AI isn't the right tool for your particular spec style. Some team's specs are so judgment-heavy that no amount of prompt tuning helps. Recognize the limit and stop.
- Junior engineers stop learning to write specs: Cultural choice. If writing specs is part of engineering development, protect the "junior engineers write from scratch" ritual even if AI could draft. Growth requires productive struggle.
Get cctk to skip the boilerplate
Everything in this tutorial is already scaffolded in cctk — commands, subagents, hooks, MCP configs. Install and customize instead of starting from scratch.