Lose weight in your dreams: my agents’ memory gets smaller every night
Every morning at a quarter to six, a job I call the dream has already run. It read everything my coding agents did in the last 24 hours. It found the mistakes that happened more than once. It changed whatever would stop them from happening again. Then it deleted some of their memory.
Last night it archived 40 notes and added none. That was a good night.
Memory felt like the obvious fix
When an agent makes a mistake, the easy move is to write it down. “Don’t use sleep in this shell.” “This API returns 409 before 403.” “Run the tests before you push.” Do that every day for a few months and the notes pile up.
By this week, that habit left 723 files in my agents’ memory folder. I also tried a shared version for my team. It was a set of notes in the repo for every agent to load. It felt like progress. Every note sat there because something had gone wrong once.
Then I tested it in my lab. There I rebuild merged tickets with different setups. I check each one against what shipped.
- Giving a reviewer agent my old notes caught nothing extra. It cost 25 to 40% more. In four traced runs, it never opened the notes.
- Shared team memory made no difference beyond the noise between two runs of the same setup.
- Rebuilding with the new shared memory matched the old setup on quality. Every pair cost about 60% more.
- One version scoped notes to the files being changed. It loaded between 25,000 and 62,000 tokens of notes per task before the agent did anything.
Every note was true. Most of them just weren’t needed.
So I switched the shared memory off. I gave the nightly job a second task: make the memory smaller.
What the dream does
It runs on a schedule by itself, with nobody signing off. Everything it touches is in git. I read its report in the morning. Anything wrong gets reverted.
First, it prunes. Before adding anything, it reads every memory file’s one-line description. It never deletes. It archives any note that is:
- a duplicate of the instructions the agents already load, or of another note;
- stale, about a tool, flag or flow that no longer exists;
- obvious, something a capable agent does anyway, or a generic coding pattern that belongs in a style guide;
- one-off, only relevant to one finished ticket.
The budget is hard: 120 files and an index of at most 60 lines. A night can’t end with more files than it started with. Only a rule I stated or a mistake that happened at least twice can grow it. My folder is far over budget, so it cuts 40 a night, weakest first. Of last night’s 40, eleven repeated another note or a rule the agents already had. Another three described flows I’ve since removed. The other 26 were generic advice like “avoid queries in a loop”. Any good agent follows that anyway.
Then it reads the day. Small, cheap readers run in parallel. They go through each agent transcript and each pull request with review comments. They list only concrete mistakes: a reviewer finding that led to a fix, me correcting an agent, a command failing the same way twice or a broken rule. Last night six of them found about 95.
Then it decides where a fix belongs. A pattern counts when it happened at least twice. Once is enough if a human reviewer found a real defect. It picks the strongest place for the fix in this order:
- A check that fails - a lint rule or a test. It files a ticket, since a check is code someone should review.
- An instruction in the playbook the agent reads at that step.
- A line in the style guide the reviewers apply.
- A memory note, only if nothing above fits. Even then, only for something a capable agent would get wrong again without it.
Every change carries its proof. It lists the count and links to the pull requests or tickets where it happened.
Text doesn’t fix everything
The most useful section of the report covers what the job can’t fix itself.

Some mistakes already have a perfectly good note. Agents keep making them anyway. They use a different Node version than the repo needs, write temporary files to the wrong folder or run shell commands that behave differently on a Mac. For some of those, last night’s report counted the tenth day in a row. They spanned half a dozen tickets.
When a written rule fails ten days running, another note won’t help. The fix is a tool: a shell wrapper that refuses the wrong command or a hook that checks the version. The dream can’t change hooks or settings. It puts those at the top of its report for me. It keeps counting until I change them.
Some things it never touches: what’s allowed to merge, what needs my approval, anything about production. Those go in the report as questions.
Why “dream”
I didn’t come up with this myself. I borrowed the idea of agents learning while you sleep. A job reflects on the day while nobody’s waiting on it. What I added is the part about losing weight. Without a budget, a reflection job is just a faster way to grow a pile of notes.

If you want to build one:
- Prune before you add, every night, with a hard budget.
- Archive, don’t delete, with everything in git. A bad night is one revert.
- Fix the strongest layer. A failing check beats an instruction, which beats a note.
- Require proof and repetition. Two occurrences with links, or one real defect from a human.
- Measure your memory. If your agents do as well without a note, it only costs you tokens.
My agents remember less than they did a week ago. They’re no worse for it, just cheaper.