Topic 5 of 5 · 4 min read
Stories a coding agent can act on
Goal: Extend a user story with the context, constraints and done checks a coding agent needs to deliver it without guessing.
A story written for people assumes a team that can ask questions; a story for a coding agent must also carry the context, limits and checks the agent cannot go and find out. Add these parts and the same story works for both.
Check yourself · 1 of 3
What is the main reason to add 'context' to a story given to a coding agent?
Why it matters
A human developer asks "which file?", "do we have a style for this?" and "is this safe to change?". A coding agent, such as Claude Code, Cursor or Copilot's agent mode, usually starts working. It fills each gap with the most likely choice, and it may stop early or claim success without proof. Anthropic's guidance for Claude Code stresses giving the agent a way to verify its own work, because that is the most effective thing you can add.
How to do it
Keep the story and criteria, then add four parts.
- Context. Where does this live? Name the area of the product or the folder, and one or two files to read first, for example the existing search for products. Say what already exists so the agent reuses it.
- Constraints. What must not change? Name the libraries to use or avoid, files to leave alone, behaviour that must stay, and anything that needs a person's approval, such as changes to the database.
- Examples. One real input and its expected output. "Searching 'kettle' returns orders 1042 and 1107." An example removes more guesswork than a paragraph.
- Definition of done. The commands and checks that prove it works: which tests must pass, which new tests must exist, what a reviewer will open and click. Make each check something the agent can run.
Keep the story small. An agent given a large story will make many choices in one go, and each one is a chance to go wrong.
Before and after
Before: As a returning customer, I want to search past orders, so that I can reorder quickly.
After: Same story, plus: Context: orders live in the orders page, and product search already exists in the catalogue module; reuse its matching. Constraints: no new libraries, do not change the orders table. Example: searching 'kettle' shows orders 1042 and 1107 only. Done when: the new tests for the four criteria pass, the existing test suite passes, and the summary lists every file changed.
What goes wrong
- The agent builds a second version of something that already exists, because nobody named it.
- "Done" is left unwritten, so the agent declares success after the happy path.
- A constraint such as "do not touch the database" is only in someone's head.
- The story is too large for one pass, so the result mixes several decisions that nobody reviewed.
Examples
A story turned into an agent brief
Story: As a returning customer, I want to search my past orders by product name, so that I can reorder quickly.
Context: the orders page lists orders; catalogue search already matches product names, so reuse it.
Constraints: no new libraries; do not change the orders table; keep the page loading in the same number of requests.
Example: 'kettle' returns orders 1042 and 1107.
Done when: a test exists for each acceptance criterion, all tests pass, and you list the files you changed and anything you were unsure about.
A done check that can be run
Weak: 'Make sure it works.'
Stronger: 'Run the unit tests for the orders module and the full test suite. Open the orders page with the seed data, search for "kettle" and confirm two results. Report each result.'
The second version gives the agent steps it can carry out, and gives you a report to check.
Key points
- A story for an agent needs the same user, need and benefit, plus context, constraints, examples and a definition of done.
- Name existing code to reuse so the agent does not build a duplicate.
- State what must not change, such as libraries, files or data, in the brief itself.
- One concrete input and expected output removes more guesswork than a paragraph of description.
- Write done as checks the agent can run, and keep the story small enough for one reviewable change.
Common mistakes
- Handing the agent a story with no context, so it invents structure that clashes with the codebase.
- Leaving 'done' undefined, so the agent stops when the main path works.
- Keeping constraints in the team's heads instead of in the brief.
- Giving a large epic in one go instead of a small story with clear checks.
Check yourself · 2 of 3
Which 'definition of done' can a coding agent act on?
Check yourself · 3 of 3
A brief says 'do not change the database schema'. Where does that line belong?
Practice items, not counted towards your mastery.
Start here
- User Stories (Mountain Goat Software) (opens in a new tab)ArticleFree
Mike Cohn's plain overview of the story format, with the three parts and why stories stay small.
- Acceptance Criteria for User Stories (Mountain Goat Software) (opens in a new tab)ArticleFree
Short guide to writing conditions of satisfaction that tell a team when a story is done.
- INVEST in Good Stories, and SMART Tasks (Bill Wake) (opens in a new tab)ArticleFree
The 2003 article that coined INVEST, with each of the six checks explained.
More for this topic
- Best practices for Claude Code (Claude Code docs) (opens in a new tab)DocsFree
Anthropic's advice on giving a coding agent context, constraints and a way to verify its work.