Agents fix the bug in front of them
This is for you if your AI coding agents keep fixing the same files and each fix looks fine in review. I run mine with Rigby, my own harness that runs several of them at once, and the story starts with a disk that filled up.
Ask an agent to fix a bug and it fixes that bug. It rarely asks why the same file keeps needing fixes, so each fix adds one more special case.
Rigby’s disk cleanup is where this caught up with me, when the disk it was meant to protect filled up.
Each fix handled the case in front of it. The last one left fourteen build folders, most at 30 GB, on a nearly full disk.
The rule against this was already written down, in a skill and a playbook. The agents kept patching anyway, and in the end I had to tell them to stop and redesign it.
Now I don’t rely on a written rule to stop it. Git history already holds the evidence.
Count fix commits per file to find hotspots
Write fixes as fix: commits and a file’s fix count is one git query over the last 30 days.
I call two fixes in 30 days a hotspot, and a hook now checks every file an agent edits against that line.
Interrupt at two fixes, ask for a redesign
So the check lives where the edit happens. When an agent touches a hotspot, it gets the file’s recent fixes and a request for a redesign instead of one more patch.
What the agent sees, simplified
lib/rigby/idle_builds.py has 6 fix commits in the last 30 days:
the mechanism is the bug.
Recent fixes:
fix(housekeeping): what the hourly sweep reclaims is reported as a defect
fix(worktrees): a worktree's test stacks go with it
fix(idle-builds): enforce build-output limits on every rig and show what is kept
Only deletions here; replace the mechanism with the native tool.
Before another patch here, tell the user this would be fix 7
and propose the replacement; net state must not grow.It’s a hook that runs after every file edit, for Claude Code and Codex agents. It never blocks the edit, because a gate would be the same band-aid shape it warns about.
Make the warning quiet enough to be heard
Getting the warning quiet enough to be heard took longer than getting it to fire.
Fire once per file per session, and again only on a new fix, or the warning becomes noise.
Tell an unattended agent how to decide
In my setup, the user an agent reports to is usually my lead agent, which plans and merges the work, not me. So the reminder carries its own rule for the answer: only deletions here, and net state must not grow.
What it answered, simplified
sync.rs has 20 fixes in 30 days, so this would be fix 21.
My replacement proposal: remove its early refusal and route the
failure through the existing sync path, which already records
that the account needs reconnecting.That’s the loop with nobody in it. My lead agent handed out the task, the hook caught the patch, and the worker chose the deletion.
It doesn’t always land. Earlier that morning the same agent patched another hotspot anyway, adding 88 lines, because the guide the reminder pointed to wasn’t in that checkout. Part 2 is how that got fixed.
If your reminder points at a guide, make sure it exists in every checkout your agents work in.
Ask for a redesign that shrinks the code
For my cleanup it was one rule: while free disk is under a floor, remove the least recently used worker checkout.
The band-aid you’ve probably met is in the tests. Neuma’s deploy gate had a script that remembered which tests had passed, so the next run could skip them.
Before: a receipt for every pass, simplified
# after a gate phase passes, write a receipt
write_receipt(phase, git_tree, environment) # PASS, on this exact tree
# next run: skip the phase while a receipt matches
if receipt_matches(phase, git_tree, environment, max_age="24h"):
skip(phase)After: pytest’s own cache, simplified
# pytest already keeps a cache of what happened last run
pytest # reruns what failed, what changed and what never ranpytest already did most of that job. So the reminder asks for exactly that: less code, and the tool that already owns the job.
How far to trust it
What to copy
The query is one line of git. It lists every file with two or more fixes in the last 30 days, busiest first, and a fix that touches several files counts once for each.
Fix commits per file, last 30 days
git log --since="30 days ago" --no-merges -E \
--grep='^fix(\(.+\))?:' --name-only --pretty=format: \
| grep . | sort | uniq -c | sort -rn | awk '$1 >= 2'When an agent edits one of those files, print the reminder above with that file’s name, its fix count and its three most recent fixes, once per file per session.
How it works
The detection is one git log query inside a hook that runs after each edit.
Part 2 is how I got it quiet. It also covers the second hook, which catches my agents when they merge.