Skip to content
mentoor

Topic 1 of 5 · 4 min read

Why coding agents need written specs

Goal: Trace a guessed behaviour in an agent's change back to the missing line in its spec.

A coding agent builds what is written and guesses everything else, so the spec is the real interface between you and the agent. Whatever you leave out, the agent still has to decide, and it decides without telling you.

Check yourself · 1 of 3

A coding agent finds a gap in your request. What does it usually do?

Choose one answer

Why it matters

A human colleague who hits a gap in a ticket walks over and asks. Claude Code, Codex, Cursor and Copilot usually do not. In a long run they pick the most likely behaviour from their training and keep going. The code looks finished and the guess looks like a decision. You only find it in review, in a test, or in production.

The cost also shifts. Typing code is now cheap. Deciding what the code should do is the part that still needs you, and it is the part a short prompt skips. A written spec moves that decision to the start, where changing it costs one sentence instead of one rewrite.

How to trace a guess

When an agent's change does something you did not expect, do not argue with the code. Ask three questions in order:

  1. What did the agent do? Describe the behaviour in one line, for example "deleted records instead of archiving them".
  2. Which line of the spec should have covered it? Search the prompt, ticket or spec for that behaviour.
  3. Was the line missing, vague or ignored? Missing means the spec has a gap. Vague means two readings were possible. Ignored means the instruction was there and the agent dropped it, which is a different fix: shorter spec, repeated rule, or a test that fails.

Most surprises land in the first two cases. That is good news, because you can fix them by editing text.

Before and after

Weak prompt: "Add a way for users to remove their saved addresses."

The agent writes a DELETE /addresses/:id endpoint that removes the row. It never asked about orders that reference the address, about the default address, or about who may call it. Each of those was a guess.

Better, as a short spec:

  • Users can remove a saved address from their account.
  • Removing an address that past orders reference must keep the order's address text unchanged.
  • Removing the default address makes the most recently added address the default; if none is left, there is no default.
  • Only the owner of the address may remove it; anyone else gets 404.

Now each guess is a stated rule, and each rule can become a test.

What goes wrong

  • The silent default. The agent picks hard delete, UTC, English-only text or no pagination, and nothing in the output says it chose.
  • The chat-only spec. The requirements live in a long chat. The next session, or the next teammate, starts from zero and the agent re-guesses.
  • Over-trusting the summary. The agent says "implemented as requested". That is a claim about its own work, not a check against your intent.

Examples

Gap, vague line or ignored rule

An agent archived nothing and hard-deleted rows. Checking the three cases:

  • Missing: the spec never said what happens to orders that reference the address. Add a rule.
  • Vague: the spec said "remove the address", which allows delete or archive. Say which.
  • Ignored: the spec said "keep order history intact" and the agent still deleted. Add a test that fails when order text changes, and point the agent at it.

The same prompt as a spec

# Remove saved address
Users can remove a saved address.
- Past orders keep their address text unchanged.
- Removing the default makes the newest remaining address the default.
- Non-owners get 404.

Four lines, three decisions the agent would otherwise have made alone.

Key points

  • An agent fills every gap in a request with the most likely guess and rarely tells you it guessed.
  • A spec moves the decisions to the start, where changing one sentence is cheaper than reworking code.
  • To debug a surprise, find the spec line that should have covered the behaviour and ask whether it was missing, vague or ignored.
  • Requirements that live only in a chat are lost to the next session, so write them in a file the agent reads each time.
  • The agent's summary of its own work is a claim to check against the spec, not proof.

Common mistakes

  • Treating a surprising agent change as a model failure when the spec simply never covered that case.
  • Putting requirements in the chat and expecting the next session to remember them.
  • Writing a long prompt that describes the solution in detail but never states the behaviour wanted.
  • Accepting 'done as requested' without comparing the change to the written requirements.

Check yourself · 2 of 3

An agent hard-deleted records when you wanted them kept. Which question helps first?

Choose one answer

Check yourself · 3 of 3

Why is a spec file in the repo better than requirements typed in a chat?

Choose one answer

Practice items, not counted towards your mastery.

Start here

More for this topic