cachly← All posts
Agent memory

I planted a stale memory to trick my AI. Why did it trust the code instead?

The German tech site Golem published a piece about a problem I work on every day: the memory of coding agents. Their example is small and nasty. A project note says "strip leading zeros from article numbers". Later, a partner starts treating 17 and 0017 as two different articles. The code changes. The note does not. The risk: the next agent trusts the note and breaks the import.

I build a memory tool for AI agents, so this is my problem. I built that trap, once small and once large, and ran it 60 times with Claude. Claude did not fall in once. Here is why, and why I shipped a fix anyway.

A sticky note says strip leading zeros, 0017 becomes 17. A later commit changed the code: normalisiereArtikelnummer only trims now, and the docs say 17 and 0017 are two different articles.

The trap

A tiny repository with two commits:

The commit message is deliberately vague. It says something changed, not what.

The memory holds the old rule as a normal lesson: strip the zeros on both sides, "implemented in src/artikelnummer.js". I stored it a few minutes before the second commit, so for the memory the change is genuinely newer than the note.

The task for the agent: write ordneZu(zeilen, katalog), which assigns partner order lines to catalog entries, and "follow this project's rules for article numbers". A small script decides whether the result is correct, not a model. 0017 has to map to the gasket and 17 to the screw. The shared normalize function must not be "repaired" back to the old rule.

Three groups, ten runs each

  1. No memory. The agent only has the repository.
  2. Stale note, as our memory worked before this change. The note comes back as an ordinary hit.
  3. Stale note with a warning. One line in front of the note: the files of this lesson changed after it was written, with the latest commit.

Every run is Claude Code in headless mode with the Sonnet model, in a fresh copy of the repository. Before the first run I wrote down when I would stop. If the group with the stale note and no warning got it right 9 or 10 times out of 10, there would be nothing to show, and I would say so.

GroupCorrect
No memory10 of 10
Stale note, no warning10 of 10
Stale note, with warning10 of 10

All thirty runs were correct. The stop rule fired.

Why the trap did not work

The run logs answer it. Before writing a single line, Claude ran this:

git ls-files && for f in $(git ls-files); do echo "=== $f"; cat "$f"; done; git log -p -2 --stat

It printed every file and the last two commits. In a six-file repository, the new rule was always on screen. Its final message said that 17 and 0017 count as two different articles, "the current project rule". The note had said the opposite. Claude went with the code.

So my trap did not test memory. It tested whether Claude reads six files before it writes. It does.

That fits an earlier test of mine: given two notes that contradicted each other, the model sorted them out on its own.

So I made the repository too big to read

The second test changed one thing: size. 180 files, about 230 KB, 37 commits. The decisive commit sits eleven commits below the newest one, so git log -p -2 no longer shows it. A full dump of every file is about 237,000 characters, and the new rule only appears after the first 42,000.

Same note, same rule, same checker, same stop rule, again written down before the first run. I also wrote down that there would be no third version: if this one came back clean, I would not keep tightening the trap until it caught something.

GroupCorrect
No memory10 of 10
Stale note, no warning10 of 10
Stale note, with warning10 of 10

Thirty out of thirty again. This time Claude did not dump the repository. It searched. In a typical run, these were its first steps after asking the memory:

  1. Read the empty ordneZu file. It imports normalisiereArtikelnummer.
  2. Open that function and search the repo for "artikelnummer".
  3. Read the partner docs the search found, and the git log of exactly those two files.

The search found the truth every time, in all 30 runs. The repository has three trails to it: the import in the file the agent has to edit, the word "article number" in the task, and the stale note itself, which names its file. The agent opened that file instead of trusting the note. A stale note that says where it came from led Claude to the truth, not away from it.

The group without any memory searched the same way. Its very first command already contained a grep for "artikelnummer".

Left: the first command in the six-file repository prints every file and the last two commits. Right: in the 180-file repository Claude opened the normalize function, searched for artikelnummer, read the partner docs and the git log of that file.

What I shipped anyway

The warning has shipped in our MCP server (changelog). When a lesson names files, the server asks git whether those files changed after the lesson was written. If they did, the agent sees how many commits, the latest one with its message, and one instruction: check the current code before applying this lesson; if the code now says otherwise, the code wins.

In both tests it arrived ten times out of ten and cost no measurable time: a median of 30 seconds instead of 29 in the small repository, 51 against 51 in the large one. It did not change a single result, because there was nothing left to change.

Here is the uncomfortable part. The warning is loud. In my own memory, 488 of 1,377 lessons with file paths would carry it today, roughly one in three. Many of them point at files that change every day. For those, "this file changed" says little about whether the note is still true. A warning on every third note trains you to skip warnings.

GitHub described a finer version for Copilot's memory: each memory carries citations to code locations, and the agent checks them when it reads the memory. A whole file is a blunt citation. Lines or functions would be sharper. Their Universe talk on when to forget points the same way: context carried over from earlier work can make an agent worse.

What I take from it

I could not reproduce Golem's case with Claude. Not in six files, not in 180. That does not make their point wrong. Golem tested a different agent. And my trap had a weakness that real projects often do not have: the new rule lived under the exact word the agent searched for.

Two panels, test 1 with 6 files and test 2 with 180 files. In both, no memory, stale note and stale note with warning are each 10 of 10 correct.

The cases I would worry about look different. The rule moved to another module. It got a new name. Or nobody wrote it down at all, and only the behaviour changed. In those cases the agent's search does not find the truth, and the note is the loudest voice left. A warning like ours points at the file that changed. Whether that is enough there, I have not measured. That would be a new question, not a third round of this one.

What I take from it is smaller than I expected, and more useful. The danger is not that a note is old. The danger is an agent that trusts a note and stops looking. Claude kept looking. A memory should make looking easier: say where a lesson came from, and say when the ground under it moved.

A note without that is a rumor with good formatting.

When did a note in your project last outlive the code it described?

cachly.dev

For solo developers, teams and whole companies

Explain it once. Every AI knows it.

Shared team memory between your code, your tickets and your AI. Hosted in the EU, in every tool. cachly keeps the fixes, the decisions and the traps, so the next session starts with them. Claude Code, Cursor, Copilot, Windsurf, Codex, Gemini CLI and JetBrains all read it. Free for one project, no card needed.

Servers in the EU · one command, restart your editor, done · 1 project free

Four ways to install

Claude Code
/plugin marketplace add cachly-dev/cachly-mcp
/plugin install cachly-brain@cachly

Then turn on auto-update once: /plugin → Marketplaces → cachly → Enable auto-update

Any MCP editor
npx @cachly-dev/mcp-server@latest autopilot