Free guide

Claude Code Memory: Persistent Memory Guide (2026)

How Claude Code memory works, where it breaks, and how to add persistent memory: CLAUDE.md, auto memory, Mem0, claude-mem and SuperLocalMemory compared.

PDF · Free download

Keep this guide as a PDF

Claude Code Memory: Persistent Memory Guide (2026), as one file you can read offline and share with your team.

Sign in with Google or GitHub to download.

Sign in to download

Claude Code has two built-in kinds of memory that load at the start of every session: CLAUDE.md files that you write, and auto memory that Claude writes for itself from your corrections. When they are not enough, an MCP memory server or a plugin can add recall across projects and tools.

This guide covers what the built-ins do, where they break, how Mem0, claude-mem, Hindsight and SuperLocalMemory compare, and how to stop memory from turning into an outdated source of truth.

Disclosure. I build SuperLocalMemory, one of the tools compared below, so I am not neutral. Every claim about another project is labelled as that project's own statement and linked to the page it comes from. Facts, star counts and licences were checked on 24 November 2026, and the comparison table carries that date. The two terminal sessions further down were run that day in a throwaway install.

How does Claude Code remember things between sessions?

Each Claude Code session starts with a fresh context window. Two mechanisms carry knowledge across that boundary, and they differ in who writes them (Claude Code docs).

CLAUDE.md files Auto memory
Who writes it You Claude
What it holds Instructions and rules Learnings and patterns
Scope Project, user or organisation Per repository, shared across worktrees
Loaded into Every session Sessions with auto memory on, up to the first 200 lines or 25KB of MEMORY.md
Diagram: Claude Code loads two kinds of built-in memory into the context window at session start. CLAUDE.md files are written by you. Auto memory is written by Claude, and the first 200 lines or 25KB of its MEMORY.md load. Topic files and subdirectory CLAUDE.md files are read only when needed.CLAUDE.md filesYou write themRules and instructionsAuto memoryClaude writes itFirst 200 lines or 25KBof MEMORY.md loadContext windowat session startLoaded as context,not enforced rulesRead only when neededtopic files and subdirectory CLAUDE.md files
Two kinds of built-in memory, who writes each, and what is read at session start versus on demand.

CLAUDE.md files can sit at the organisation, user, project or local level, and Claude Code concatenates every one it finds in the working directory and above it rather than letting one override another. Files in subdirectories load on demand, once Claude reads or edits something there.

Auto memory is on by default in local sessions. Claude saves four kinds of notes for itself, recorded as a type field in each file's frontmatter: user (your role and preferences), feedback (corrections you give and approaches you confirm), project (ongoing work and decisions it cannot derive from the code) and reference (where to find things outside the repository). It skips anything it can derive from the codebase or that your CLAUDE.md already says.

The notes are plain markdown files in ~/.claude/projects/<project>/memory/, with a MEMORY.md index and one file per topic. Claude Code loads the first 200 lines or 25KB of the index, whichever comes first, at session start and reads the topic files on demand. The folder is machine-local: it is not shared across machines or cloud environments. When Claude writes a memory file with frontmatter, Claude Code stamps it with a modified timestamp so you and Claude can see how current a fact is.

One caveat applies to both mechanisms. The documentation says Claude treats CLAUDE.md and auto memory as context, and that they "aren't enforced configuration". If something must happen at a fixed point, the docs point you to hooks, not memory.

Where does Claude Code memory break?

Four limits come up repeatedly, and each one is visible in the documentation itself.

Bloat. Anthropic recommends keeping each CLAUDE.md under 200 lines, because longer files use more context and reduce adherence. The auto memory index is capped: everything past 200 lines or 25KB is dropped on the next load, and Claude Code tells Claude to rewrite the index when it goes over. People ask about this directly, for example in a thread titled how to handle cross-session memory in large repos once CLAUDE.md or AGENTS.md gets too bloated.

Staleness. The docs warn that if two instructions contradict each other, Claude may pick one arbitrarily, and they suggest periodic review. Claude Code also reminds Claude to merge or drop stale entries when the index nears its limit. Nothing in the documentation describes a mechanism for marking one fact as superseded by another, which is why a thread asking how to stop agent memory becoming an outdated source of truth has no one-line answer. The section on stale facts below covers options.

New-project amnesia. Auto memory is keyed to the repository. A new repository starts with an empty memory folder, so what Claude knows about you there is limited to your user-level ~/.claude/CLAUDE.md and ~/.claude/rules/, plus whatever the repository itself holds. Threads like Claude forgets everything and acts clueless in every new project describe the experience.

Repeated mistakes. Memory is advisory. The docs say CLAUDE.md content reaches Claude as a user message after the system prompt, with no guarantee of strict compliance. A correction saved to auto memory or CLAUDE.md can still be ignored, which is the complaint in a thread looking for a real persistent memory setup. The fix depends on what kind of mistake it is, covered next.

How do I stop Claude repeating the same mistake after I correct it?

Sort the mistake by how strict the rule must be.

If it is a preference or a project fact, say it once in plain words. The docs give examples such as "always use pnpm, not npm", and Claude saves such requests to auto memory. To put the rule in CLAUDE.md instead, say "add this to CLAUDE.md" or edit the file through /memory. The documentation's own test for when to add something to CLAUDE.md is: Claude makes the same mistake a second time, a code review catches something it should have known, or you type the same correction you typed last session.

Write the rule so it can be checked. The docs contrast "Use 2-space indentation" with "Format code properly" and say the specific version is followed more reliably. After saving, run /context all and look under Memory files to confirm the file is loaded.

If the rule must hold every time, such as running tests before a commit, do not rely on memory at all. Write it as a hook, which runs as a shell command at a fixed lifecycle event whatever Claude decides.

What do I do when CLAUDE.md gets too bloated?

Move content out by how often it is needed. The documentation's advice, in order of effect:

Path-scoped rules in .claude/rules/ load only when Claude works with matching files. A rule file with a paths field in its frontmatter, such as src/api/**/*.ts, stays out of context until Claude reads or edits a file that matches. Multi-step procedures belong in skills, which load when invoked or when their description matches the task. Splitting a file with @path imports helps you organise it but does not reduce context, because imported files load together with the file that imports them. And /doctor prompt-audit, which requires Claude Code v2.1.283 or later, has Claude look for outdated, missing or contradictory instructions across your instruction files and propose edits without changing anything until you approve.

There is a second size limit people hit without noticing. A CLAUDE.md or rules file that loads on demand from a subdirectory has its own cap of 40,000 characters on the smaller of the two context-window sizes the docs list, and Claude receives only the start of a file over the cap.

Why does Claude act clueless in every new project?

Because project memory belongs to the project. Auto memory for a repository does not follow you into another repository. Three things do: your user-level CLAUDE.md and rules, a memory tool that stores facts outside the repository, and a shared instruction file. If your repositories use AGENTS.md, Claude Code reads it when no CLAUDE.md is present (version 2.1.277 or later), and a CLAUDE.md that imports AGENTS.md pulls it in alongside your own notes.

For facts about you, such as your stack, review habits and what you never want done, user-level CLAUDE.md is the cheapest fix. For facts about many projects and the decisions behind them, you need one of the external options below.

What has Claude written about me, and where?

Run /memory. It lists your CLAUDE.md files and the auto memory folder, and opens any of them in your editor. Everything is plain markdown that you can edit or delete. Claude Code also shows "Saved N memories" or "Recalled N memories" in the interface when it reads or writes the folder. Anthropic excludes the memory directory from the cleanup that deletes old session transcripts, so these files stay until you or Claude change them.

That visibility is real but narrow. It is a folder of files on one machine. Apart from the modified timestamp, the memory page describes no history of what changed, no record of which session wrote a note, and no check for notes that contradict each other. The governance section below covers what the external tools add.

Which persistent memory options exist beyond the built-ins?

Five options are compared here. The table is a snapshot taken on 24 November 2026 from each project's repository, README or documentation. Stars are GitHub stars as of 24 November 2026, pulled from the GitHub API at 12:15 UTC. Benchmark scores are left out on purpose: each project publishes numbers under its own setup, and Mem0's README says its scores reflect its managed platform, which includes optimisations not available in the open-source SDK.

Option Where memory lives How Claude gets it back Licence and stars Install
Built-in CLAUDE.md and auto memory Markdown files on your machine; auto memory in ~/.claude/projects/<project>/memory/ CLAUDE.md in full at start; first 200 lines or 25KB of MEMORY.md; topic files on demand Part of Claude Code On by default; manage with /memory
MCP memory server A knowledge graph in a local JSONL file; default location is the server's own directory Claude calls its tools to create entities, relations and observations Repo licence file describes a move from MIT to Apache-2.0; hosting repo has 92,207 stars npm package @modelcontextprotocol/server-memory
Mem0 Library, self-hosted server or hosted platform Extraction by a model call; retrieval by semantic, keyword and entity matching Apache-2.0; 69,417 stars Plugin from the Mem0 marketplace, per Mem0's guide
claude-mem Local SQLite worker; data in ~/.claude-mem Hooks capture tool activity; an observer model turns it into observations that are injected later Apache-2.0; 119,439 stars npx claude-mem install or /plugin install claude-mem
Hindsight Self-hosted server (Docker or pip) or hosted cloud Retain, recall and reflect operations; MCP endpoint per memory bank MIT; 63,041 stars Docker, pip install hindsight-api, or its Coding Agents plugin
SuperLocalMemory (ours; source) Local database on your machine Hooks and MCP; recall tiers say when memory has no answer AGPL-3.0; 290 stars claude plugin install superlocalmemory@qualixar, or npm or pip

A few notes the table cannot hold.

The MCP memory server's own README warns that its default file sits next to the server's code, and that under npx or an npm install that directory can be cleared by a reinstall or cache clean, which deletes the graph. It tells you to set MEMORY_FILE_PATH to an absolute path you own.

Mem0's hosted path needs a platform account and an API key, per its guide, with a free tier of 10,000 memories and 1,000 retrieval calls a month and graph memory on the Pro plan. The guide also describes a local-first OpenMemory option. Mem0's README describes its current automatic extraction as single-pass and add-only, with no update or delete step: memories accumulate and nothing is overwritten. The SDK also exposes explicit update and delete calls, so an agent or a person can still correct a memory. The add-only default is a deliberate design choice with consequences for staleness, discussed below.

claude-mem's README says anonymous usage analytics are on by default and can be turned off, cloud sync is opt-in, and the installer asks you to sign in through a browser, where choosing the claude-mem observer starts a 30-day free trial on a checkout page that asks for a payment method. Passing an explicit provider flag, or setting CLAUDE_MEM_ONLINE_OPTIN=false, skips the sign-in. Its README also lets you wrap text in <private> tags so it is never stored.

Hindsight's page for its older Claude Code integration says that integration is retired and superseded by its Coding Agents plugin. Its README says it works with more than twenty-five model providers, hosted or local.

For SuperLocalMemory, the README states that in Mode A the core remember and recall operations make no model-provider call: no API key, no cloud account, no Docker.

Do you still need any of these now that auto memory exists? Often not. Mem0's own guide says the built-in memory applies to one project, does not carry to other tools, is capped at 200 lines and 25KB, loads in full whether or not it is relevant, and has no semantic search. If none of those limits bite, the built-ins are enough. If you work across many repositories, use more than one coding agent, or need to search a large history, an external store earns its place.

How do I add persistent memory with SuperLocalMemory?

The Claude Code memory plugin and the SuperLocalMemory package install from the same repository. The README's routes are an npm install (npm install -g superlocalmemory, then slm setup and slm connect claude-code) or the Claude Code plugin (claude plugin marketplace add qualixar/superlocalmemory, then claude plugin install superlocalmemory@qualixar). The README lists Python 3.12 to 3.14 for the pip route. One gotcha found while testing for this guide: on Python 3.15, pip quietly installed the old 3.3.1 release. The current release's package metadata excludes Python 3.15 and the old release's metadata does not, so pip falls back to the old one without an error. Use a supported interpreter and check with slm --version.

To see recall without touching a real memory store, the commands below were run on 24 November 2026 in a throwaway install (version 4.2.34, Mode A) with its own home directory. The output is real and lightly trimmed.

$ slm remember "We deploy the API blue-green; rollback is a DNS flip." --kind decision
Queryable ✓ 1 facts (operation=e55b621b40f647a88414089b9ff37543).
$ slm remember "Staging DB is Postgres 16 on port 5433."
Queryable ✓ 1 facts (operation=f1932a25611f4b63912575acfecbc002).

$ slm recall "how do we roll back the API"
  1. [0.54] We deploy the API blue-green; rollback is a DNS flip.

$ slm recall "zxqv plorth wimble"
That isn't in SuperLocalMemory.

The second recall is the behaviour to look for: a question the store cannot answer returns an explicit "not in memory" instead of the closest-looking text. A store that always returns something invites the agent to build on the wrong memory. The README says scores rank memories and are not probabilities.

How do I keep memory from going stale?

Stale memory can do more damage than missing memory. A missing fact makes the agent ask or look; a stale one gets used. Three approaches are in use among the tools above, and they trade off differently.

Diagram: three ways to keep memory from going stale. Letting the model curate, as auto memory does, fails quietly because nothing records what replaced what. Accumulating every version and ranking by time, as Mem0 does, grows the store and needs the ranker to be right. Replacing a named old fact explicitly, as SuperLocalMemory does, can still fail if the agent does not call replace on its own.Let the model curateAuto memory: typed notes with a modified dateFails quietly: no record of what replaced whatAccumulate and rank by timeMem0: keep every version, rank with time-aware retrievalThe store grows and the ranker must be rightReplace explicitlySuperLocalMemory: new fact replaces a named old oneThe agent may not call replace on its own
Three approaches in use, what each does, and where each can fail.

Let the model curate. Claude Code's auto memory does this. It tags each note with a type and a modified timestamp and reminds Claude to merge or drop stale entries when the index nears its limit. It works without effort and fails quietly: nothing records that a new fact replaced an old one. A third-party post from April 2026, which cites no official documentation and is based on its author's reading of Claude Code's source, describes a background consolidation step called auto dream. It is not on the official memory page consulted for this guide, so check /memory on your own version before relying on it.

Accumulate and rank by time. Mem0's add-only extraction keeps every version and relies on retrieval to prefer the right one. Its README says its retrieval includes time-aware ranking for questions about current state and past events, and explicit update and delete calls exist for corrections. The default cost is a store that grows and a ranker that has to be right each time.

Replace explicitly. SuperLocalMemory lets a new fact replace a named old one, keeps the old one on record, and offers an undo. The same run as above, continued. slm list gives the ID of the fact to replace (the real output prints each ID on its own line under the fact; they are folded onto the fact line here):

$ slm list
  8c0ee81568f047cf  Decision: We deploy the API blue-green; rollback is a DNS flip.
  6070efe89da34a67  Event (suggested): Staging DB is Postgres 16 on port 5433.

$ slm remember "Staging DB moved to Postgres 17 on port 5434." --replaces 6070efe89da34a67
Replaced ✓ 1 fact(s) of 6070efe89da34a67.
To undo, run:
  slm review-correction 6e3350300b9d5a7cb3a3f2e8a4d94666 rollback 1

$ slm recall "which port does staging postgres use"
  1. [0.67] Staging DB moved to Postgres 17 on port 5434.
  2. [0.52] We deploy the API blue-green; rollback is a DNS flip.

Before the replacement, the same question returned the Postgres 16 fact. After it, the old fact no longer appears in recall, although slm list still shows both memories, so the history is kept. The README also describes disputes, where two memories that disagree about the same thing are both shown, newest first, until you or an agent settles it, and cues that warn when a file a memory came from has been edited. Those two were not tested here.

What this test does and does not show: it is a two-fact demonstration of one mechanism, not a benchmark of staleness handling. It does not show an agent choosing to call replace on its own, which is where this approach can still fail.

One pattern to try with any of these tools, offered as analysis and not as a tested method: keep three kinds of record apart (current facts, dated decisions and reusable lessons) and give each a source, a last-checked date and a scope. Claude Code's own type and modified fields go part of the way, with project and reference close to current facts and feedback close to lessons.

How do I see and govern what the agent stored?

With the built-ins, /memory and a file browser are the whole toolkit, which is fine for one developer on one machine. Teams and regulated work need more: who wrote a fact, when, from which source, and a way to erase it everywhere.

SuperLocalMemory's README describes a hash-chained audit trail, receipts for saves and erasures that reach every copy, a record of how each memory arrived, and replacement of credentials in saved text with a typed placeholder before storage. claude-mem's <private> tags are a lighter control for keeping secrets out. The SuperLocalMemory 4.0 paper (arXiv:2608.08253) describes the governed design and also leads with a negative result: ten mechanisms were implemented and reachable but ineffective at their final connection, and it withdraws an overhead figure from the previous version. For how recall works under the hood, see how AI memory actually works. For the compliance angle, see our post on the EU AI Act and agent memory and the memory governance post. This is the kind of work we group under AI Reliability Engineering: agent memory you can audit, which can be inspected and corrected.

Why is Claude Code memory not working, and what do I check?

The memory documentation's troubleshooting section gives a usable order. If you are still setting Claude Code up, our Claude Code setup guide covers the basics, and memory is one part of a harness.

Check that auto memory is on. Open /memory and read the toggle. Auto memory can be disabled with the autoMemoryEnabled setting or the environment variable CLAUDE_CODE_DISABLE_AUTO_MEMORY=1. It is off by default in sessions on a self-hosted environment, and the toggle cannot turn it back on in a background session or in a session that another Claude Code session started.

Check what loaded. Run /context all and read the Memory files list. A CLAUDE.md in a subdirectory will not appear there because it loads on demand. If you are relying on AGENTS.md, remember that Claude reads it by default only when no CLAUDE.md exists in the working directory or above.

Check size. If MEMORY.md is over 200 lines or 25KB, the tail is not loaded. A CLAUDE.md over 200 lines is followed less reliably.

Check whether a subagent is involved. The main conversation's auto memory is not loaded into subagents, with the exception of a fork, which inherits the parent conversation.

Check conflicts. Contradictory instructions across files, including user-level and project-level, let Claude pick either one.

Check what survives compaction. After /compact, the project-root CLAUDE.md is re-read from disk, but anything you only said in conversation is gone. Put it in CLAUDE.md to make it stay.

If none of that explains it, start a new session and run /context all again before changing anything else.

Watch and read more

Three films show the tool running: a full memory demo across Claude Code and other agents, Your AI Forgets Everything. Here's the Fix. and 74.8% on the AI Memory Benchmark. The research papers page lists the SuperLocalMemory preprints, including the governed 4.0 design.

FAQ

Do I still need Mem0 or another tool now that auto memory exists? Only if the built-in limits cost you something: memory per repository only, nothing shared with other agents, a 200-line or 25KB index, no search over a large history. Otherwise the built-ins are enough.

Can memory be shared across Claude Code, Codex and Cursor? Instruction files can: Claude Code reads AGENTS.md when there is no CLAUDE.md, and a CLAUDE.md can import it. Auto memory cannot, since it is machine-local and Claude-specific. SuperLocalMemory's README lists connectors for Codex and Cursor among others. Check each tool's own docs for current behaviour.

What is the difference between CLAUDE.md and auto memory? You write CLAUDE.md and it holds instructions. Claude writes auto memory and it holds learnings. CLAUDE.md loads in full; auto memory loads the first 200 lines or 25KB of its index.

Where is auto memory stored, and can I move it? In ~/.claude/projects/<project>/memory/ by default. The autoMemoryDirectory setting moves it to an absolute path or one starting with ~/.

Does Claude Code memory work across machines? No. Auto memory is machine-local. CLAUDE.md files travel with your repository if you commit them.

Is persistent memory safe to turn on? It stores text about you and your work on disk, and any tool that does that needs the same care as other personal data. Read what it saved, keep secrets out, and prefer tools that show provenance and can erase. For the built-ins, everything is plain files you can inspect.

What is auto dream? A background memory consolidation step described by third-party posts, one of which dates from April 2026 and cites no official source. It is not on the official memory page consulted on 24 November, so verify it on your own installation.

Want more guides like this?

Subscribe to get weekly AI agent reliability insights and new guide notifications.