When Claude trips twice on the same thing, write it down.
Every Claude Code session starts with a fresh context window. What an agent knew about the project yesterday, it knows today only if it ended up in a file. At…
6 min readBy Whilehaus

Every Claude Code session starts with a fresh context window. What an agent knew about the project yesterday, it knows today only if it ended up in a file. At the studio, the signal to write that file is the second time an agent trips on the same thing, and from then on the file is worth keeping as long as someone shortens it and reviews it.
Two hands write an agent's memory
The Claude Code documentation explains that two things carry over from one session to the next. The first is the CLAUDE.md files, the project instructions, which a person writes. The second is auto memory, notes that Claude writes on its own from the corrections and preferences it is given. As of November 2026, that memory is on by default in local sessions.
So there are two hands on that memory, the person's and Claude's, and neither of them leaves it tidy for good. The studio's position is that reviewing, shortening and pruning that memory is somebody's job, the same as maintaining any other file a project depends on.
At the studio, each hand has its own share. CLAUDE.md holds what is always true for the project: the conventions, the commands in use and what is off limits. Memory holds the facts learned on the job that an agent would otherwise have to rediscover in every session.
What gets written down
The same page says when it makes sense to add something to CLAUDE.md: when "Claude makes the same mistake a second time". The studio took that signal as a working rule for all of memory: the first time an agent trips on something, it gets corrected in the conversation and the work moves on, and the second time it gets written down.
At the studio, each memory is a short file with a single fact and three parts, a format the studio came up with, which the documentation does not ask for. A sample file, built for this note and named line-endings.md, reads like this.
- The fact. The script that generates the config files writes Windows line endings, and the repository expects Unix ones.
- Why. The script runs on a Windows machine, and version control flags the whole file as modified even though not a single word changed.
- How to apply it. After running that script, convert the line endings before looking at what changed.
One fact per file, with its why and how to apply it.
The why gets written for two reasons: with the reason in view, an agent can recognize a similar case the file does not name, and whoever rereads it months later can decide whether it still holds.
A short index, then indexes by topic
Auto memory lives in one folder per project, with an index called MEMORY.md and the memory files next to it. It is local to the machine, so it does not travel on its own to another computer or to a cloud environment.
Each file leaves one line in the index, and the index is the only part of auto memory that loads when the session starts. As of November 2026, that is the first 200 lines or 25 KB of MEMORY.md, whichever comes first, according to the Claude Code memory page. Anything past that threshold does not load at startup, and each memory file is read only when it is needed.
That gives the rule of the short index: one line per memory, with the file name and what it covers in a few words. When the main index grows too large, the studio splits it on its own into indexes by topic, one for tooling and another for the database, and the main index keeps a single line pointing to each.

For CLAUDE.md the math is different, because it loads in every session. As of November 2026, the documentation recommends fewer than 200 lines per file, because longer files use more context and Claude follows them less well.
Memories go stale
According to the documentation, when Claude writes a memory file that starts with a metadata block (YAML frontmatter), Claude Code records the time of that write in a field called modified, so the person and the agent can see how current the fact is. The files are plain text that can be edited or deleted at any time, and they stay there until the person or Claude changes or deletes them.
A memory is a dated snapshot, and it gets verified before it is used.
The studio's rule is that before leaning on a memory, its date gets checked and so does the fact: that the file it names still exists and that the command still goes by that name. What has expired gets corrected or deleted, and its line leaves the index at the same moment.

What stays out of memory
Part of the upkeep is deciding what not to record. According to the documentation, auto memory skips what can be derived from the code, such as the architecture, file paths and the fix for a specific bug, and also what the CLAUDE.md files already say.
The studio reads a useful split in that. The one-off fix goes to the code and its history, where an agent finds it by reading. The environment trap that the code does not reveal is memory, and it is the one most worth writing down.
The studio adds a rule of its own: secrets never go into memory, whether they are keys, passwords or tokens. A memory file is plain text with no protection, and a secret has its own place.
Four stumbles that ended up written down
These four come from the studio's work, and they leave out the names and places where they happened.
- The line endings. This is the sample file from above: a script that ran on Windows and a repository that expected different line endings.
- The text with apostrophes. A long block of text pasted inside a command (a heredoc) broke when it contained single quotes or apostrophes, and the command never ran. The memory says that kind of text goes into a file first.
- The migration on a shared database. On a local database shared by several parallel workstreams, schema changes are applied one way only, and never with the command meant for development.
- The memory that went stale. A memory described how a step was done that later changed, and it had to be corrected.
The first three could not be deduced from reading the code, and the fourth is the reason a memory gets verified before it is used.
What memory does not solve
Having the file does not guarantee that an agent reads it or applies it. Memory files are read when an agent decides it needs them, so one can go unopened. Of what it does read, the documentation says Claude treats CLAUDE.md and auto memory as context, not as a rule the system enforces. It tries to follow them, but nothing guarantees it does so to the letter, especially when the instructions are vague or contradict each other.
That is why what cannot fail goes into a mechanism that always runs, such as a hook or a test, and memory is kept for what helps the work go better.
Memory does not tidy itself either. What sits in the index past the threshold does not load at startup, a fact that has changed stays written until someone corrects it, and the documentation warns that if two instructions contradict each other, Claude may pick one arbitrarily. Pruning is the part of the job that keeps everything else useful.
Run this way, an agent's memory is archive work: it gets noted the second time, shortened, dated, verified and pruned. Whilehaus works this way on what it builds every day.
Write it first. Then maintain it.