writingmaclulich.com

How to brief AI coding agents so review stops catching the same mistakes

Five changes to stop coding agents repeating mistakes your review already caught

  1. Give each agent a short brief, not a bigger promptMine are usually 9 to 12 lines. One agent’s conversation I measured had grown from 36K tokens to 334K, all re-sent every turn.
  2. Send the reviewer the same contract the builder gotMine is rebuilt from the commit’s real diff, so a file nobody mentioned still brings its rules.
  3. Attach the brief with a script, not an agent’s memoryI watched model-written context fail in three ways, and none of them needed a smarter model.
  4. Promote a finding to a lesson on its second failureA lesson goes into every future brief, so it needs evidence. Mine caps a brief at five known traps.
  5. Record exactly what every agent was toldWhen a review fails, you can tell whether the agent ignored a rule or never saw it. Mine adds about 6 KB per task.
The numbers are from my own agents, and the changes are too new for me to have results after them.

Agents repeat the mistakes you already caught

If you run AI coding agents and keep rejecting the same mistakes in review, this is for you. The story starts with my cheapest agent, one of several that Rigby, my own harness, runs at once.

It passed review first time only 67% of the time, and most of its rejections were mistakes we had already caught before.

The repeats were things like an old writer left registered after its replacement, or a second endpoint shipped without its permission check. Each one cost a full review round of tokens and an afternoon of waiting.

First-pass review: 67% for my cheapest agent, 93% for Opus

DeepSeek, the cheapest67%
Codex80%
Claude Opus93%
Before the change described here. Part of the gap is the model, and a lot of it was the same project mistakes caught again and again.

The fix wasn’t a bigger prompt. Every task now carries a short contract of the rules that apply to the code it touches, and the reviewer gets the same contract.

Past review findings feed back into the next brief for that area. To see why that beats a longer prompt, start with what an agent actually receives.

Send a short brief, not a bigger prompt

Each agent runs in its own terminal. One of them, the head (Claude Opus), plans the work and hands out units of it, one task each.

The others, which I call lanes, do the units: Codex on one, DeepSeek through OpenCode on another.

Rigby is the small supervisor in between. It carries messages, starts and restarts the lanes, and merges finished work once it has passed review.

A lane starts every unit fresh, so the handoff message is the whole interface

What a lane has

  • the message it’s handed
  • its standing instructions
  • whatever it reads in the repository

What it never saw

  • my conversation with the head
  • the design discussion
  • yesterday’s review

The reviewer is a fresh session too. A rule that isn’t in the message, or that the lane isn’t pointed at, doesn’t exist for that unit.

I measured the context first. One agent’s conversation ran for hundreds of turns across unrelated tasks, and all of it was re-sent on every turn.

One conversation grew from 36K tokens to 334K, all of it re-sent every turn

334K
tokens in the prompt, up from a 36K start
99.4%
of those tokens were cache hits
~210K
tokens per request, on average
One cheap lane before the change. Cheap per request, but the volume still dominated the bill.

The model was also reading a lot of stale history to find the one rule that mattered. So the brief has two jobs: be small, and be specific.

A unit starts in a fresh session with a 256K ceiling, and its brief is usually 9 to 12 lines, not pages of guidance.

The agent gets links to the full documents with a content digest, rather than the documents themselves. My first version linked the same four guides to every change, and now the guides follow the files: tests bring the testing guide, and Rust brings the Rust one.

Give builder and reviewer the same contract

The brief is built from two small files the project commits. Rigby reads them from the branch the work will merge into, never from the candidate change, so a unit can’t loosen the rules it will be judged by.

.rigby/areas.toml maps code areas to their owner, rules, guidance and proof commands. .rigby/lessons.toml holds the known traps that earned their place by repeating.

The reviewer gets the same contract, rebuilt from the commit’s real diff, and its own instructions are fixed.

The reviewer checks the same contract and marks every rule against it

  1. It traces every entry pointOf each changed operation
  2. It marks each ruleSatisfied, defective or not verified, with evidence
  3. It wants a retirement record for anything replacedThe old implementation, the new owner, the callers migrated, what was deleted and which tests still cover it
  4. It flags files outside every mapped areaBecause that’s where second implementations hide

My first version only gave a brief to projects with a hand-written areas file. Every project now gets a baseline contract, and the areas file sharpens it.

The question behind each fix I made was whether it would still work for a project nobody had set up by hand.

Don’t leave the brief to a model’s memory

The obvious objection is that the head is Opus and can write a good brief itself. It can, and on a good day it did.

But a brief written by a model is only as good as that model’s attention at that moment, and I watched it fail in three different ways.

Three ways model-written context failed me

  1. The head forgot to name the filesSo the unit went out with none of its area’s rules. Now Rigby won’t send a unit without them, and names the files the message already mentions.
  2. DeepSeek broke a rule it had already been givenThe rule was in its standing instructions. Being somewhere in the context isn’t the same as being read, but a short rule attached to the files it governs gets read.
  3. Lanes waited on questions in a terminal nobody watchesThe unit sat idle until I happened to look, whether the brief had left a decision open or already made it. Now a lane acts when the brief decides and asks the head, never its own terminal, when it can’t.

None of those are a smarter-model problem. Each is a step that a model was trusted to remember.

Rigby doesn’t know more about the task than the head does. What it has is the project’s rules written down, applied the same way every time.

It applies them from the paths the head names, and again at review from the files the commit really changed, so a file the head never mentioned still brings its rules.

Models are good at deciding the work and bad at remembering the paperwork

When the head writes the context

  • The brief exists only if the head remembers it.
  • What goes in depends on what the head noticed this time.
  • The reviewer gets a different summary from the producer.
  • Nobody can say afterwards what the agent was told.

When Rigby attaches it

  • Every work and review message carries a brief.
  • The same paths always produce the same rules.
  • Producer and reviewer get the same contract.
  • Each brief is stored by digest in the unit’s record.

Promote a lesson only after a second failure

Rigby can only send what someone has written down, so the lessons need an author. The tempting version is to let the reviewer write them freely.

I didn’t, because a lesson injected into every future brief is a prompt change, and prompt changes need evidence.

A finding becomes a lesson only when the same rule fails twice in one area

  1. findingrule ID, code area, what went wrong and the fix
  2. promotiona reviewed commit to lessons.toml after a second failure
  3. briefat most five known traps per brief
  4. retirementwhen the area’s code is deleted or goes quiet

Rigby records a finding itself whenever a review blocks a unit, so the loop doesn’t depend on the reviewer remembering to.

Five traps is the ceiling because more stop being read. I learned that when DeepSeek ignored an instruction already sitting in its standing prompt.

Record what every agent was told

When a review fails, you want to know whether the agent ignored the rule or never saw it.

Every unit keeps a record of exactly what its agents were told

  1. standing promptthe one its lane launched with
  2. work textthe message as it was sent
  3. briefsproducer and reviewer, with the guidance digests
  4. subagent briefsevery brief the head pasted into its own subagents

My first version let session cleanup delete the history of what an agent had been told. A context record is now written before any cleanup and kept 90 days, readable with rig context.

Each text is stored once by digest, so a typical unit adds about 6 KB. At my pace that’s roughly 3 MB every 90 days.

How far to trust it

Too new to measure, and only as good as the rules someone wrote down

  1. No after numbers yetThe mechanism went live the night before this was written, and I’ll add the results here when I have a few days of them
  2. Part of the 67% to 93% gap is the modelA lot of it was the same project mistakes caught again and again
  3. A gap in the map is a gap in every briefRigby can only send rules someone has written down
  4. Context doesn’t fix everythingOne lane couldn’t run Docker at all, because it started with the wrong PATH, and no amount of context would have fixed that

What I’m measuring, against the week before the change

SignalBeforeTarget
First-pass review rate, cheapest lane67%rising
Same rule failing again in the same areanot measuredfalling
Tokens per request, cheapest lane~210K< 100K
Units whose result covers the contract itemsnot measuredall

What to copy

A brief is the work, its rules, its proof and up to five known traps

  1. The workWhat to do, in a line
  2. The rules for these filesShort rule names, with links to the full guidance and a content digest
  3. The proofThe command that shows the work is done
  4. Known trapsAt most five, each from a rule that failed twice in this area

Here is the shape of one, shortened. The rule names are labels from my own guides, so use whatever your reviews keep catching.

What a lane receives (illustrative, shortened, digests invented)

WORK: replace the old order-sync writer with the new owner
CONTRACT (src/orders/**)
  rules: ONE-OWNER, RETIRE-REPLACED, TRACE-ENTRYPOINTS
  guidance: single-surface-api (sha256 3f9a1c…): core rule ONE-OWNER
            testing (sha256 b71e04…): tests changed
  prove: ./run test fast -k order_sync
KNOWN TRAPS
  - last 2 units here left the old writer registered in the nightly job
  - list every caller you migrated in the retirement record

Send the reviewer the same brief, rebuilt from the commit’s real diff, and keep a record of every brief that goes out.

How a handoff works

The producer and the reviewer get the same contract

  1. dispatchthe head names the files, and Rigby attaches the brief
  2. producethe lane works from rules, guidance links and known traps
  3. reviewthe brief is rebuilt from the commit’s real diff
  4. recordeach blocking finding is logged by rule and code area
  5. learna rule failing twice in one area becomes a known trap
Known traps flow back into the next dispatch for the same area.

Rigby attaches every brief from committed files, so the same paths always produce the same rules and no model decides what goes in.

Rigby builds every brief, and no model decides what goes in it

Who sends what during a handoffFour columns: the head agent, Rigby, a producer lane and the reviewer. 1, the head dispatches a unit with its paths. 2, Rigby reads the contract and lessons from the main branch and sends the lane the work with its brief. 3, the lane finishes with rig done. 4, Rigby records the unit's context and sends the reviewer the brief rebuilt from the real diff. 5, the reviewer passes it or records a finding. 6, Rigby merges on a pass or sends a correction carrying the brief. Repeated findings are promoted into lessons, and the head's own subagents get the same brief through rig brief.Head agentClaude OpusRigbybuilds every briefProducer laneCodex / DeepSeekReviewerpeer lane / Opus1 rig dispatch --scope paths2 WORK + brief: rules, links, traps3 rig done <commit>4 VERIFY + brief rebuilt from the real diff5 pass, or rig finding: rule + area6 merged, or correction + briefmain branch.rigby/areas.toml.rigby/lessons.tomlproject logsfindingscontext recordread at 2 and 4written at 3 and 5a rule failing twice in one areais promoted to lessons.tomlHead’s subagentssame brief, viarig briefEvery brief is attached by Rigby from committed files. No model decides what goes in it.
Who sends what. Rigby reads the rules from the main branch at steps 2 and 4, and writes the context record before any cleanup at step 3.

If an agent keeps making the same error, put it in the next brief for that area, not in a longer prompt for everyone. I’ve written more about keeping agents’ context small in five changes that keep coding agents’ context small.