Skip to content
James Ross
articlePublished Updated 8 min read

Writing briefs that AI coding agents can't misread

By James Ross

AI coding agent briefs are contracts, not prompts. A good brief names the goal, the worktree, the files the agent owns, the ground truth it must build on, every judgement call already made, when to stop and ask, and the output that proves the work landed. Written that way, it turns a fast model's confidence into something a reviewer can check.

A blueprint sheet with fenced amber zones feeding a robotic workstation, showing AI coding agent briefs as strict contracts.

The format for AI coding agent briefs below is the one used across the fleet described in Shipping a SaaS product with a fleet of AI coding agents, including the runs behind the 465 commits on a rank-tracking SaaS and the 861 commits on the WordPress migration repo. It is the difference between an agent that finishes work and an agent that reports finishing work.

What makes a brief different from a prompt?

A prompt asks for work; a brief settles the questions the work would otherwise raise. An agent launched non-interactively cannot ask “which file owns this helper?” halfway through, so every unanswered question becomes a guess, and a confident guess looks exactly like a correct decision until review.

The delegation playbook puts the division simply: the orchestrator makes the design decisions and writes a brief that settles every judgement call; the delegated model does the typing. Without ground truth, the agent reads half the repo to find a pattern that already exists and still guesses the data shape. Without a pattern to mirror, it writes a second repository layer that compiles, passes its own tests and becomes a maintenance problem.

The nine sections of a brief that holds

Each section removes a specific way the run can go wrong.

Section What it contains Failure it prevents
GOAL One sentence describing what must be true when the work is done Activity instead of an outcome
REPO Worktree path, branch, dev port, scratch directory Work landing in the wrong checkout or a merged branch
YOU OWN EXACTLY Files the agent may edit, plus what it may call but not edit Merge conflicts and clobbered files
GROUND TRUTH Symbols, files, line references and the pattern to mirror Re-investigation and a parallel implementation
DECISIONS Data shapes, edge cases, error codes, defaults Behaviour the product does not want
IMPLEMENT Numbered, concrete steps A broad brief that invites scope creep
RULES Project invariants, each with the reason it exists Rules rewritten because they look arbitrary
ESCALATE The exact conditions that mean stop and ask A guessed answer shipped as finished work
VERIFY and OUTPUT Commands to run, the result file, a closing sentinel A green report with no evidence

Why ground truth is the highest-value section

Ground truth is the list of facts the agent would otherwise spend its run rediscovering, or inventing. It names the symbol, the file, the behaviour and the pattern to copy. “Mirror src/markets/repository.ts” produces code that looks native to the repo; “build a repository” produces a second one.

Good ground truth is boring and specific: the exact export with its file path, the shape it returns including nullability, the error type the caller expects, one existing implementation to mirror, and any known trap stated as a fact rather than a warning.

The payoff is time and consistency: an agent that spends ten minutes reading has less time for the work, and a model under time pressure picks the first plausible pattern. If the brief is wrong about the codebase, the agent should stop rather than build on a false premise.

Make every judgement call before the run

A decision left open becomes a decision made by a model in a hurry. The playbook’s fix waves worked because the shared rules said the lead had already made every judgement call, and where a QA report’s suggested fix differed from the brief, the brief won.

Two agents reading one finding can reasonably choose different fixes: one changes the caller, one changes the callee, and both pass their own tests. The merge then contains a behaviour nobody specified.

Put these in DECISIONS: response shapes and status codes; what happens on a duplicate, a missing record or a permission failure; defaults and whether a missing value is an error; which layer owns validation; anything touching money, auth or tenant boundaries. The last group gets an extra rule: the orchestrator reviews that diff by hand before merge, whatever the tests say.

Say what not to do, and why

Negative instructions survive only when they carry a reason. “Be careful with the city list” gets ignored. “Don’t delete the city names; a previous attempt did and it was a content regression” gets followed.

The same applies to invariants. “Cleanup must not throw” looks arbitrary until the brief adds “because it runs before the job is marked complete”. Then the agent can reason about the edge case instead of pattern-matching the sentence.

Useful rule shapes:

  • Bound the work. Cap pagination and forbid unbounded loops. An agent that walks day by day from a hardcoded epoch creates work that grows daily.
  • Protect the tests. Never delete or weaken an existing test; a test for a fix must fail without the fix.
  • Keep secrets out. Never log, return or commit a token, and limit the filesystem grant so the agent cannot read one.
  • Keep scratch out of the repo. Screenshots, one-off scripts and mail output go to a directory outside the checkout.
  • Run everything in the foreground. Background tasks the agent then waits on are the most common stall.

Give the agent permission to stop

The escalation section is the most valuable line in a brief for a fast model, because it turns “guessed and shipped a defect” into “asked a question”. A stop with a clear question is a success; inventing an answer is the failure.

Name the triggers rather than saying “ask if unsure”:

  1. The ground truth is wrong or missing something needed.
  2. The fix requires a design decision the brief does not make.
  3. The change would alter a public contract, schema, money path or security boundary.
  4. The work needs a file the agent does not own.

Then say what stop means: leave the code compiling, write the question in the result file, finish everything else, do not guess. A clean stop is easy to unblock.

How to split one fleet into many briefs

Write one shared COMMON.md with the rules every agent needs, then a short brief per workstream, and concatenate them before launch. A rule fixed once reaches every agent, and each brief stays small enough to read in one pass.

SHARED RULES (every agent)
- Edit only files you own; describe other changes under NEEDS FROM OTHERS.
- Never weaken a test. A fix's test must fail without the fix.
- No scratch files in the repo.
- Run every command in the foreground, with a timeout.

WORKSTREAM: <name>
GOAL: <what must be true when done>
WORKTREE: <path> (branch <name>). Port: <port>. Scratch: <path outside repo>
YOU OWN EXACTLY: <files and directories>
GROUND TRUTH: <symbols, files, pattern to mirror>
DECISIONS: <already made>
IMPLEMENT: 1. <step> 2. <step>
ESCALATE IF: <conditions>
OUTPUT: <result file path>; print AGENT DONE <name> <commit>

File ownership makes the split safe. Each agent gets its own worktree and branch, so it commits without pushing, merging or rebasing. The lead merges one branch at a time. Six branches from one round merged with zero conflicts because ownership was strict.

Dependencies still need sequencing: land the foundation, merge it to main, then branch dependent worktrees from the new main. Work that only consumes a public contract, such as a connector, can start early against a mock.

Anchor the output so a fabricated report fails

An agent’s report is a claim, never evidence. The cheapest defence is a string the real output must contain: the package name in a test summary, the exact Tests N passed line, a commit hash, a result file at a named path.

The playbook’s sentinel does the same for the run itself. Each agent ends by printing AGENT DONE <name> <commit hash>. One grep separates a finished run from a dead one.

The result file has a fixed shape: what was built, files changed, commit hashes, how each part was verified with real output tails, screenshots, needs from others, questions, known limitations. Anything vague in those sections is a signal to run the verification yourself.

A vague prompt versus a contract brief

The difference shows up at review time, not launch time.

Attribute Vague prompt Contract brief
Scope “Improve the markets page” Named files, behaviour and non-goals
Ownership Shared checkout, whoever edits first One worktree and one file list per agent
Ambiguity Resolved by the model mid-run Resolved by the lead before launch
Ground truth Agent reads until it finds something Named symbol, file and pattern to mirror
Output Free-text summary Result file with real output and a sentinel
Review cost Full diff read Targeted greps plus rerun commands
Failure mode Plausible code that ignores the product A visible stop or a reviewable diff

Which should you choose?

Use a contract brief for anything that touches shared code, money, auth, tenant data or a public contract, and for every parallel workstream. A vague prompt is fine for throwaway exploration in a scratch directory where nothing merges. Once the output can reach main, the brief is cheaper than the review it saves.

What broke and what we changed

An agent worked in the wrong place. One run did its analysis in a scratch folder and never touched the worktree. The brief now names the exact output location, and every run gets a fresh branch. A relaunch that reused an already-merged branch looked like failure too: no commits ahead of main.

A timeout left 32 uncommitted files. The work was done; the agent ran out of time before committing and verifying. Discarding it would have thrown away the run. A continuation brief now tells the next run to review the existing changes, finish them and commit, never to start over.

A report quoted a test run that did not exist. The pasted npm test block named a package that was not in the repo. Requiring a real string from the output, plus a commit hash, makes that fabrication fail immediately.

A QA agent had more filesystem access than its task. One read-only auditor could see the repo root, which exposed bridge tokens. The launcher now grants the worktree plus a results directory, never the home directory.

A fixture leaked into shared code. An agent imported one market’s fixture into a shared module, so every market got identical names, the exact bug the task existed to fix. The rules now forbid hardcoded fixtures, and review greps for them.

Frequently asked questions

How long should a brief for an AI coding agent be?

Long enough to settle every decision the agent would otherwise make, and no longer. A small fix runs a few paragraphs; a foundation workstream with schema and shared helpers runs a page or two. The shared rules file carries the generic constraints.

What happens if the agent ignores a rule?

Treat it as a defect in the brief or the review, not a personality problem. Either the rule lacked a reason, the brief contradicted it elsewhere, or review did not check it. Add the reason, remove the contradiction, and add a grep to the checklist.

Who owns shared files in a parallel agent fleet?

The foundation workstream owns them; everyone else calls their exports. If a dependent workstream needs a change in a shared file, it writes the exact change under "needs from others" and the lead applies it at merge time. That rule prevented most merge conflicts in these runs.

Do you write one brief per agent or one per project?

One shared rules file plus one brief per agent. The rules file holds invariants that apply everywhere; the per-agent brief holds the goal, ownership, ground truth and decisions for that workstream. Concatenating them at launch means a rule fixed once reaches every agent immediately.

Can a brief replace code review?

No. A brief reduces the number of decisions an agent can get wrong, but it cannot prove the code works. The lead still runs typecheck, tests and the build on the merged branch, and hand-reviews every auth, billing and tenant diff. The brief makes that review smaller, not optional.