In What I Have Built With Claude Code (So Far) I listed one of my ground rules as “Claude keeps its own memory of decisions, gotchas and things I’ve told it not to touch, so each new session doesn’t start from scratch.” That rule has worked well. Almost too well: by late November the memory on my Raspberry Pi had grown big enough that it was quietly starting to forget things.
This post is about how that memory works, the first time I sat down and spring-cleaned it, and what I put in place so that it doesn’t get into the same state again.
How Claude Code remembers things
Each Claude Code session starts with no recollection of the last one. To get round that, Claude keeps a folder of small Markdown files on the Pi, one fact per file. Some are about me and how I like things done, some are feedback I’ve given it, some describe ongoing projects and some point to where things live. Examples of the kind of thing in there:
- Gotchas. The newer version of Pi-hole ignores the old file that DNS records used to be kept in, so records have to be added through its API instead.
- Things to leave alone. A service I stopped on purpose, which shouldn’t be restarted or reported as broken.
- Things that look like bugs but aren’t. An automation that emails me from my own address will legitimately show up twice in Gmail.
Alongside the files there is an index, MEMORY.md, with one line per memory. The index is loaded into every session, and Claude opens the individual files when a line looks relevant. That makes the index the important part, and it has a limit: it gets cut off at about 24.4KB.
The problem: it had started forgetting
When Claude audited its own memory on 26 November, it found:
- 77 memory files, all of them listed in the index.
- An index of just over 24KB, right at the limit. It had already lost its last line, silently.
- Long index lines. 35 of the 95 lines were over 250 characters, because history and “since…” notes had crept into what should have been one-line hooks.
Nothing had visibly broken. That is what made it worth fixing: a memory that drops its last line without telling anyone fails in exactly the way you won’t notice.
The first memory review
I asked for a way to keep the memory relevant and current. What came out of it is a review page in my Obsidian vault, in the same tick-box style I already use for tidying Flickr. Claude checks four things and lists each proposed change with a tick box:
- Is it still true? Paths, services and claims checked against what is actually on the Pi.
- Is it already written down somewhere else? If a fact is in the project instructions file (
CLAUDE.md) or a README, the memory is just a second copy that can drift. - Do two memories cover the same thing? If so, merge them.
- Is the index too long? Every line should be a short hook, with the detail kept in the file.
There was also a “still wanted?” section for things only I could decide. I ticked what I wanted, told Claude to “apply the memory review”, and it made only the ticked changes. Before deleting anything it had to check whether the memory held a fact that wasn’t recorded anywhere else and, if so, move that fact first.
Some of what it found:
- Stale facts. A memory said not to edit a config folder that no longer existed. Another described a project as “not yet scheduled” when it had been running weekly for over six weeks. Another said a set of connectors was “configured but disabled”, when several were now connected; that one was simply deleted, because every session already lists the tools it has.
- Broken links. Memories link to each other, but 46 of them had the wrong name in their header, so links to them didn’t resolve.
- Duplicates of the instructions file. Several memories, and several lines of the index, just repeated what
CLAUDE.mdalready says. - Things spread too thin. Everything about one Gmail project was split over four places, and my “definition of done” over three memories. Each became a single memory.
The suggestion that was wrong
One item was a good reminder of why I tick the boxes myself rather than letting it tidy unsupervised. The review proposed deleting a paragraph that warned a particular change hadn’t been deployed yet, because that commit was no longer in the project’s repository.
When it came to applying it, the reason turned out to be wrong. That commit belongs to the Windows version of the same tool, which lives in a separate repository and still has it. Claude had checked the wrong repo. So the paragraph wasn’t deleted; it was shortened to say that Windows deployments need a manual pull, which can’t be checked from the Pi.
Nothing was lost, but only because the “apply” step re-checked each change instead of trusting the review.
The result
- 77 memory files became 68.
- The index halved, to 12,191 bytes, with no line over 200 characters.
- Nothing worth keeping was thrown away. For example, the notes from my Evernote migration moved out of memory and into that project’s README, which is where they belonged in the first place.
Putting the memory in git
There was one uncomfortable detail. The only backup of the memory from before the review was a temporary folder. I keep everything else on the Pi in git, so the memory got the same treatment the same day:
- A private GitHub repository. The first commit is the memory exactly as it was before the review, and the second applies the review, so the review itself can be read back or reverted.
- A commit at the end of every session. A small script, ClaudeMemorySync, runs from a hook when each Claude Code session ends, including the headless ones on timers. It commits whatever changed, names the changed files in the message and pushes. A lock stops two sessions that end together from colliding, and a failed push is retried next time. By the time this draft was written, it had already committed changes from later sessions on its own.
- Backup, not sync. My other Claude Code setup syncs agents and commands between the Pi, my Windows PC and my Chromebook, but it still deliberately doesn’t sync memory between machines.
Keeping it tidy
The point of all this is that I shouldn’t need to notice the problem next time. Two things look after that:
- A regression test. Like every other service on the Pi, the memory now has a test in my regression suite. It fails if the index goes over 20KB (leaving headroom below the cut-off), if an index line is over 250 characters, if a link or a name doesn’t match, if the index and the files disagree, if a memory change has gone uncommitted for more than a day or hasn’t been pushed, or if the end-of-session hook has gone missing. While a review is open, the size and format checks are skipped, but only until a fixed date, so an abandoned review can’t hide them forever.
- A reminder every 90 days. Ninety days after the last review, a link appears in my Daily note. Clicking it opens the review page, and telling Claude to “review memory” produces a fresh list of tick boxes. The next one is due on 24 February 2027.
What I’ve learned
- Memory needs maintenance like everything else. It grows one sensible addition at a time, and nobody notices it getting stale until something is quietly missing.
- Know your limits, literally. The cut-off was the real problem, and the test now keeps a margin below it.
- One fact, one home. Most of the clean-up came from facts that had been written down in two or three places. If something is in a README or the instructions file, it doesn’t need to be in memory too.
- Keep a human in the loop for deletions. The tick-box page plus a re-check before applying caught the one wrong suggestion.
- Put it in git. Anything worth cleaning up is worth being able to roll back.
A note on how this post was written: it was drafted by Claude Code, which went through the repos, code history and vault notes for the memory review and the memory backup, and wrote the draft directly into WordPress as a draft through the WordPress API. The header image was generated with Google’s Gemini image model. I then reviewed and edited it before publishing.

Leave a Reply