How to Manage Your AI Memory (So It Works Exactly the Way You Want)
How AI's memory works, the three ways it breaks, and four levels of cleanup that also work in ChatGPT, Gemini, Codex and Grok.
When AI's memory goes wrong, it costs more than a bad sentence: an old price, an old address, a number your client already corrected. This guide shows how Claude's memory works, how it goes bad, what Anthropic's "dreaming" fixes, and how to keep one clean set of rules that works in every AI tool you use.
Has your AI ever forgotten your instructions, even though you asked so clearly?
You correct it once, your AI agrees, and two sessions later, the old rule is back.
I had this exact moment with em dashes, one of the first signs that AI wrote the text. My old writing rules allowed em dashes wherever they fit. Then the rule changed to "2-3 per piece." Later, I changed it again, to zero.
My skills recorded each new preference, but the old rules kept coming back.
How annoying is that?
From the outside, it looks like the AI is forgetting. And complaints like "Claude forgets everything and acts clueless in every new project, even with full memory, skills, and file access" always come up.
Em dashes are the cheap version of this problem. The more expensive ones could be last quarter's numbers in a client report, a price you already changed, or your old address on an invoice. Those cost real money.
The worst part? We already have skills and instructions. So where did things go wrong, and can we fix it for good?
The good news: this problem is universal, so every AI company wants to fix it as much as we do. Claude, our good old friend, has been working on it since earlier this year, with a feature called:
Dreaming.
But this isn't only a Claude fix. In this article, we'll look at what Anthropic built, the mechanisms underneath it, and how to do the same cleanup yourself, in any AI.
To keep things simple, I'll use two examples from my own setup all the way through: my em dash rule, which changed three times, and my brand color, which also changed along the way.
What's inside
The four layers of AI memory, and how one question pulls from them
How to fix a messy memory, in four levels that work in any AI
Okay, now back to the article.
Anthropic used "dreaming" to clean up Claude's memory
So what is dreaming? It's a scheduled job that runs between sessions, while the agent isn't working. Like sleep, it happens when you're away.
It does three things (Anthropic, dreams):
It reads the agent's memory and the transcripts of its past sessions, the full record of what was said and done.
It compares the two.
It writes a new memory, with duplicates merged and "stale or contradicted entries replaced with the latest value."
Anthropic shipped it in May 2026, on Claude Managed Agents, a platform for developers who build their own Claude agents (Anthropic).
Take my em dash problem. The image below shows what a dream would do with it.

That sounds fantastic: an automated cleanup of my AI memory while I sleep.
Underneath the fancy name, it is the cleanup a careful person runs on a shared notebook.
So why does it suddenly matter?
Because the job was always there, and it grows with every note we save. But nobody was doing it.
Anthropic announced dreaming for developers. Claude Code has its own version too, but it's hidden, and it was switched off on both of my setups.
So on one hand, Claude's "secret behavior" suggests we should clean up our memories, or at least learn how to maintain them.
On the other hand, Claude doesn't seem to want us to pay attention to that cleanup at all.
Why the mixed signals? Because the job is harder than it looks.
AI memory has four layers, and they get messy
Ask your AI where its memory is stored, and you'll get many answers.
In Claude Code, for example, type /memory. The files it lists are plain text, and you can read, edit or delete any of them (Claude Code docs). If you use the Claude app, open Settings and look for Memory: "Everything Claude remembers is listed under Topics" (Claude Help Center).
This is what mine shows. It's got auto-saved notes, user instructions, project instructions, and more.


Claude works inside a context window, which is everything it can see while it answers. Part of your memory loads into it before you type a word.
I sort these files into four layers, by when each one reaches that window.
Every AI tool has these layers in some form (more on that in Level 4). Here, I'll use Claude Code's layers as the example.
Layer 1: Rule files
These hold your standing instructions. They come in four kinds, from broadest to narrowest:
your organization's rules, which a company puts on every machine
your personal rules, for all your projects
your project's rules, in a
CLAUDE.mdorAGENTS.mdfilelocal rules that only you use in one project
In the screenshot above, my personal rules come to 32.4 KB, and my project rules to 8.4 KB.
Layer 2: The index
Alongside those rules, Claude loads MEMORY.md, which is an index of your saved notes.
Each line of the index is a title, a link to one note, and a few words about it. Those few words are all Claude has to go on when it decides whether to open the note.
The index is small on purpose.
Mine is 24.1 KB and loads every session. The 151 notes behind it come to 228 KB, about nine times as much, and Claude opens one only when a line sends it there.
But be aware: Claude Code's docs say that only "the first 200 lines or 25KB of MEMORY.md, whichever comes first, load at session start."
That means, if you have two notes talking about the same thing with slightly different detail, Claude might just pick the one closest to the top, not necessarily the most correct one.

Layer 3: Topic notes
Each index line points to a note file in the same folder. Claude opens a note only when it decides the note is needed. Almost every note starts with a small header that gives its name, one line about it, and its kind. The brand colors note in the image above is a reference note. My 151 notes break down like this:
corrections I gave: 81
pointers to tools and places: 40
facts about my projects: 26
facts about me: 3
one note with no name and no kind at all
Layer 4: Session transcripts
The notes hold the lessons Claude chose to save. The full record lives elsewhere: Claude Code saves a transcript of every session, one file each, and deletes them after 30 days by default (Claude Code docs). I keep mine longer, so this project's folder holds 452.
Anthropic's dreaming works from records like these.

How one question pulls from the layers
Say I type "make an image for my post."
My rules and my index are already in the window before I type a word.
One index line, "Brand colors and fonts," fits the ask, so Claude opens the note behind it and finds my purple, #6B2FD0.
The other 150 notes stay shut, and the transcripts stay on disk.

So a note only helps if its index line loads and says clearly what it's for. A note behind a vague line, or past the 200-line cut, rarely gets opened.
You can check yours in ten minutes.
In your AI agent, just ask plainly: "Help me open my memory md file in plain text editor". You'll see a list like mine above.
As you keep working, notes go into these files, and almost nothing takes them out.
Four layers of files, each one pointing at the next, and every session adds a little more. You can guess where that goes.
Over time, that memory breaks in three ways
"As an evolving program is continually changed, its complexity ... increases unless work is done to maintain or reduce it."
AI memory follows the same law. Its notes go bad in three ways.
Break 1: Notes go stale
A note is true the day you write it. Then your work moves on, and the note doesn't.
I've changed my brand colors and styles many times, and old notes with old palettes stayed in memory.
I know my brand color now, but any AI session that opens memory can read old and new notes alike. That's how one image comes out exactly right and the next is way off.
Drew Breunig calls this context poisoning: an error that "makes it into the context, where it is repeatedly referenced" (Breunig). An old note is that error, read again every time it's opened.
Break 2: The same rule lives in several places
Copies pile up around the things you change most: your prices, your client details, your tone, your brand. Each time you update one, the new version goes into one file and the old version stays in another.
My em dash rule lived in three places. One copy allowed a few, the others said zero, and all of them loaded.
Breunig calls this context clash: new information "that conflicts with other information in the context." When the copies disagree, Claude can follow either one. When they agree, they take up room twice. And with a price, a second copy is how the old price survives the change.
Break 3: The index outgrows its limit
You can try your best to make good notes. But even good notes pile up until the index runs past the point where Claude stops reading.
It's a curse: the more you use AI, the bigger the problem gets.
Take one of my accounts, its memory files (the rule files and the index together) grew from 13,700 to 24,500 tokens in just four months.

Remember the 200-line cut from Layer 2? One Claude Code user tested it: the same rule at line 20 was followed 9 times out of 9, and at line 240, past the cut, 0 times out of 9.
The note that falls off is usually the one you added last, and that's often the one about what just changed, like your new price.

These three breaks are why an AI you've used for months starts to feel less cooperative.
Its memory desperately needs a good cleanup.
How to fix a messy memory
Let's go back to Anthropic's answer with dreaming. If a dream ran on your memory, what would it fix?
A dream aims at each break.
It replaces "stale or contradicted entries" with "the latest value," merges duplicates, and writes a new memory (Anthropic, dreams), so the memory doesn't "grow unbounded over time" (Anthropic).

In an ideal world, it would work perfectly. Finally, a self-improving agent.
But how sure are you that Claude will replace stale memories with the right ones, and that you can keep track of what it changed?
I'm not, at least not always. There are two reasons:
An AI can tidy up facts, but it cannot verify a person's preferences.
A person relying on AI dreaming will eventually stop checking its changes.
If you've ever clicked "Accept all" on a long list of AI edits without reading every one, you've seen the second reason happen.
So can we fix the three breaks ourselves?
Yes. Four levels do a dream's work with your own judgment, in any AI you use.
Level 1: Tidy the note
A bad note rarely needs a better home. Usually it needs a fix, or it needs to go.
The question I use is: "Would the AI get this wrong without this note?"
It tells you whether your AI needs the note. One more look tells you whether it's still true. Between them, every note lands in one of three places:
AI needs it, and it's still true. Keep it. If its line in MEMORY.md is long, shorten it, and keep the link and enough words to say when the note matters.
AI needs it, but it's no longer true. Rewrite it from the source that holds the current version, such as your rule file or your live project.
AI doesn't need it. Another file already says it, or it records work that is finished and tracked somewhere else. Move it to an archive folder and take its line out of MEMORY.md.

Back to my brand colors. I had many notes with different palettes. Some could go to the archive, some needed a fix, and only the newest were still right.
Level 2: Move it into a rule file
Memory notes come and go. They get overwritten, and they take a lot of upkeep if you rely on them alone.
So once a note is settled as the truth, move it up to a rule file. A rule file loads every session, and both you and your AI can see it.
Claude might remember from a note that my brand color changed, but only in the project where that note lives. A session in another project never sees it. My personal rule file loads in every project, so a rule there reaches all of them.
Level 3: Make it stick with a skill or a hook
A rule file loads in full, but your AI can still skip a rule in it.
This is where a skill helps. Your brand colors matter when Claude makes an image, not when it drafts an email. A skill holds the instructions for that one job, and it loads only when the job comes up.
When a rule must never be skipped, use a hook. A hook is a small script that runs at set moments in Claude Code, and a mod bundles hooks into one easy install. My answer-first mod puts my "answer the question first" rule in front of Claude with every prompt I type. It can't make Claude obey, but the rule is always there.
Level 4: Give it one home for every AI you use
What if you use more than one AI?
The fix is simpler than it looks. AI agents work in similar ways, whether you use Claude, ChatGPT, Grok, Gemini or others. Grok, for one, remembers your past chats now (TechCrunch). Open any AI tool's settings and you'll find the same memory layers.

Because the layers match, one set of rules can serve all of them.
That's why I keep a second brain, one folder of rules that outlives any single tool.
My global rules live in one folder there. Claude, ChatGPT, Cursor, Hermes all read and act from it. When I change a rule, I change it once, and every AI that reads it, from Claude Code to Codex gets the change in its next session.

My global rules file also tells every AI where everything else goes. A rule for one project goes in that project's AGENTS.md. A habit of mine goes in my habits file. A job I repeat goes in a skill. So a new rule has a home before anyone writes it down.
One home also keeps the cleanup small. One home for each rule means one place to check, not one for every tool. I explain how I set it up in A shared AI second brain.
So which level does a rule need? Ask these in order:
Would your AI get it wrong without this note? If not, archive it.
Does it matter in every session? Put it in your rule file.
Does it matter only for one kind of work, or must it never be skipped? Use a skill for the first and a hook for the second.
Do you need it in every AI you use? Give it one shared home.
Ask the first question of every note. Move a rule up only when Claude keeps getting it wrong where it is.
Clean memory won't make your AI perfect, but it stops the old rules from winning.
From then on, I've been tidying my AI memory, first as one big cleanup and then as a monthly routine. My AI has been a LOT smarter since, and so much easier to work with.
So I put the memory skill into the Build to Launch MCP for premium members. Ask your AI: "Use the Tidy Your AI Memory guide from my Build to Launch connector."
It audits your memory, proposes every change in one list, and acts only on your go. It works in Claude Code and Codex. In a chat app, your AI gives you each step to run.
You might also enjoy
Claude Skills Not Working? 5 Fixes That Actually Work: when a skill from level 3 doesn't load, start here.
MCP, Plugins, and Skills: how to choose where a rule or a tool should live.
Obsidian + Claude Code: How to Build a Second Brain that Remembers, Connects, and Runs Itself: the note side of a second brain.
How I Built a Shared AI Second Brain for My Scheduled Tasks: the same one-home idea, for jobs that run on a schedule.
What's the oldest line in your MEMORY.md that Claude still reads every session?
— Jenny
Build to Launch | Claude Code hub | A shared AI second brain