Sub topic 11
Choosing how much spec a change needs
This chapter assumes you have read the earlier chapters on the spec-driven workflow. You should be comfortable with requirements, design, and task documents, and with basic automated testing. Not every change needs all three documents. This chapter gives you a way to decide how much spec to write.
The cost of too much and too little
A spec costs time to write and time to keep current. It pays off when it removes ambiguity the agent would otherwise resolve by guessing.
- Too little spec: the agent fills gaps with its own assumptions. You find out in review, after the code exists.
- Too much spec: you spend an hour writing for a ten-minute change. The spec also becomes one more file that can fall out of date.
The goal is the smallest spec that leaves no important decision to chance.
Three questions to ask
Answer these before you write anything.
- How many decisions are open? If there is one obvious way to do the work, there is little to specify. If there are several reasonable ways, write down which one you chose.
- How costly is a wrong guess? A wrong label in a log message is cheap to fix. A wrong rule for expiring password reset tokens is a security bug.
- How many files or components does the change touch? A change inside one function is easy to review directly. A change across several modules needs a design and an ordered task list so the pieces fit together.
Matching the spec to the change
| Change | Example | Spec to write |
|---|---|---|
| Trivial | Fix a typo, rename a variable | None. A one-line prompt is enough. |
| Small, clear | Add a validation check to one function | A short prompt with one or two acceptance criteria, plus a test. |
| Feature with rules | Password reset by email | Requirements with acceptance criteria, and tasks. |
| Cross-cutting or risky | Replace the session store, change the data model | Requirements, a design document, and tasks, with review after each. |
Treat the table as a starting point. A small change in a sensitive area, such as authentication or billing, moves up a row.
A worked example
Suppose you need two changes in the same project.
The first change is to show the 30-minute expiry in the reset email text. The decision is already made, the code is in one template, and a mistake is easy to see. A prompt is enough:
Update `templates/reset_email.txt` so it says the link expires
in 30 minutes. Change nothing else.The second change is the reset flow itself. It has security rules (single use, expiry, no account enumeration), it touches storage and an endpoint, and several designs would work. This needs the full set: requirements with testable criteria, a short design note on where tokens are stored, and ordered tasks.
You can write the criteria for the smaller change in a single line, and they still help:
1. WHEN the reset email is rendered THEN the system SHALL state that the link expires in 30 minutes.Signals to change the size
Adjust the spec as you work. These signals tell you to scale up or down.
- Scale up when the agent makes the same wrong assumption twice, when review comments keep asking "why did it do it this way?", or when the change grows past the files you first expected.
- Scale down when sections of your spec only restate the code, or when the criteria are so obvious that no test would ever fail.
Deciding in practice
Exercise
You must add a rule that rejects uploads over 10 MB in one existing handler. The handler already validates file type, and the project has tests for it. Which spec would you write, and why?
Show answer
A short prompt with one or two acceptance criteria, plus a test. There is one obvious place for the change, so a design document is not needed. The size limit is a testable behavior, so a criterion such as "WHEN a user uploads a file larger than 10 MB THEN the system SHALL reject it" and a matching test are enough to check the agent's work.
Exercise
Midway through a task, the agent chose a different token storage approach than you expected, and this has happened on two earlier tasks. What does this suggest about your spec, and what do you do?
Show answer
The spec is too small for this change. The storage decision is open and was never written down. Add a short design note that states the storage choice and the reason for it, link the tasks to it, and then rerun the task.