See How Others Solved It First

What I found in the retrospective

This week I looked back at a project I worked on with AI agents. I wanted to find the problems I had lived with without seeing them.

One file stood out. It was the AGENTS.md, the instruction file every agent session loads before it starts work.

At one point it had been trimmed from about 1,100 lines to about 130. Four months later it was back near 1,000.

Nobody decided to let it grow. Agents wrote most of the pull requests, and each one added a few lines about the fix or feature it had just made. Each addition looked reasonable on its own. Nobody looked at that file during review, so nothing stopped it.

I hadn’t noticed any of this while it was happening. I only saw it when I went back and counted.

A beginner again

I have written code for many years. Working with agents, I am a beginner again, and I’m trying to act like one.

My old habit is to think hard, design the right solution, and then build it. That habit is useful when a client has already decided what they need. It is less useful when I don’t yet know whether a problem is real for anyone else, or whether someone has already solved it.

So this time I set myself one rule before writing any code: if a mature tool already exists, I write a post about it instead of building my own.

Looking at existing tools first

I searched for tools close to this problem and found several. I tried each one on my own repositories instead of just reading their READMEs.

One of them reported my CLAUDE.md as stale right after I had updated it. In my repo, CLAUDE.md is a symlink to AGENTS.md. The tool was reading the history of the link itself, and that never changes when the target file does. I wrote a short script that reproduced it and filed a report. The author fixed it the next day and turned my script into a regression test.

That exchange taught me more than the bug did. A clear report with a repro is a small thing to write, and it gets a real answer.

The tools I tried were useful in different ways. But none of them stopped the file from growing at the moment an agent wrote to it. They checked the file afterwards, or warned when something looked off, and left the decision to whoever happened to be watching.

Asking people how they handle it

Next I found people who had the same problem and asked them how they deal with it. I asked about what they actually do, not what they would like to do.

One maintainer had written a hook that warned when an instruction file gained narrative text. They had just deleted it, because it almost never fired. The hook that did the work was a stricter one on their own machine. It blocks an edit when the added text reads like a story: a date, a measurement from the past, a word about an incident. They had counted 35 blocks across 17 sessions. Their summary was: “blocking works on what kind of text goes in, warning doesn’t do much, and neither stops a file from growing.”

Another project had the same curve as mine. Its AGENTS.md went from 28.5k to 96k characters in four months, because, as their issue put it, no test failed when it grew. Contributors cut it down to 33k and added a test that fails at 40k.

Both answers changed my design before I wrote any code. Warnings were not enough, so the check had to block. And a fixed ceiling still lets a trimmed file creep back up to the limit, one small step at a time.

What I built

The tool is called agents-budget. It does one thing.

Each instruction file has a budget, counted in bytes. Once a file is over its budget, an edit may not make it larger. An edit that makes it smaller always passes. So the file never has to be cleaned up all at once, but it can never get worse.

The same check runs in two places. A Claude Code hook runs it at the moment an agent tries to write the file. A command-line check runs it against the main branch, for a pre-commit hook or CI, because the hook only sees the sessions it is installed in.

When an edit is denied, the message tells the agent where the text should go instead:

  • If a test, lint rule, type or script already enforces it, don’t write it.
  • If it only concerns one file, put it in a comment next to that code.
  • If it is history or an incident, put it in the commit message.
  • If it really is needed, first remove something a check already covers.

In my first trial, the agent offered to raise the budget so the edit would fit. So I closed that door too: an agent may lower a budget but never raise one.

The moment it worked

Then I tried it in a real session. I asked the agent to add a new rule, plus a short summary of the incident behind it, to an AGENTS.md that was already over budget.

The write was denied. The agent did not try to work around the check. It went to look, and found that the rule was already enforced by a lint rule and a type. It said the rule didn’t need to be written down at all, and that the incident belonged in the commit message.

That was the behavior I had been hoping for. The agent didn’t just obey a limit. It ended up making the decision a careful reviewer would have made.

What I’m taking away

The tool is small, and it only judges size, not whether a line is useful. That is fine. What I want to keep is the order I did things in this week.

First I looked back and found a problem I hadn’t noticed. Then I looked outside to see whether someone had already solved it. Then I asked people how they handle it. Only then did I build something, and I built less than I would have otherwise.

I’m a beginner again, and this is what I’m practicing: before I build, look at how other people have solved similar problems, talk with them, and then find the approach that fits me.