How Claude Code memory works across sessions and tools
Claude Code memory is two sets of Markdown files that load when a session starts. You write CLAUDE.md files with instructions and rules. Claude writes auto memory, short notes about your preferences, your corrections and the project, in ~/.claude/projects/<project>/memory/. Both stay on your computer. A new session finds them, but another machine or another coding agent does not.
This guide follows Anthropic’s Claude Code documentation and changelog as of November 26, 2026. We build CrystalBrain, one memory shared by your AI apps and coding agents, so the last section shows how we connect Claude Code to it.
What is Claude Code memory?
Anthropic says each Claude Code session “begins with a fresh context window”, and two mechanisms carry knowledge across sessions (Claude Code Docs, checked November 26, 2026).
| CLAUDE.md files | Auto memory | |
|---|---|---|
| Who writes it | You | Claude |
| What it holds | Instructions and rules: build commands, conventions, architecture | Your preferences, your corrections, project context the code does not show |
| Scope | Your organization, you, a project, or you in one project | One git repository, shared by all its worktrees |
| What loads at launch | Each file in full, up to 4 MiB per file | The first 200 lines or 25 KB of MEMORY.md, when auto memory is on |
Claude treats both as context, not as configuration it must obey. When an action has to be blocked whatever Claude decides, Anthropic’s documentation points to a hook instead.
In Claude Code projects, a beta that opened on September 17, 2026 for select Pro and Max subscribers who use cloud sessions, “every thread now adds to and draws from a shared memory” (Anthropic). The Claude app’s memory, with its topics and project memories, is a separate system, covered in our guide to how memory works in the Claude app.
Does Claude Code have memory across sessions?
Yes. At launch, Claude Code loads your CLAUDE.md files and, when auto memory is on, the start of MEMORY.md. A session you open tomorrow knows your build commands and the corrections you gave today, as long as they reached one of these files.
Claude Code keeps the conversation itself in a separate file, a JSONL transcript at ~/.claude/projects/<project>/<session-id>.jsonl. The command claude --continue reopens the most recent session in the current directory, and claude --resume opens a picker (Claude Code Docs). Transcripts are deleted after the number of days in cleanupPeriodDays, 30 by default (settings reference). Memory files are excluded from that cleanup and stay until you or Claude edit or delete them.
Where do CLAUDE.md files go, and how do they load?
CLAUDE.md files sit at four levels. Claude Code reads them from the broadest to the most specific, so a project instruction comes after a personal one in the context.
- Managed policy.
/Library/Application Support/ClaudeCode/CLAUDE.mdon macOS,/etc/claude-code/CLAUDE.mdon Linux and WSL,C:\Program Files\ClaudeCode\CLAUDE.mdon Windows. IT deploys it, and a developer cannot exclude it. - User.
~/.claude/CLAUDE.mdholds your preferences for every project. - Project.
./CLAUDE.mdor./.claude/CLAUDE.mdis committed and shared with the team. - Local.
./CLAUDE.local.mdholds your own notes for one project. Add it to.gitignore.
At launch, Claude Code loads the files in the working directory and in every directory above it. It concatenates them, so no file overrides another. A CLAUDE.md in a subdirectory loads later, the first time Claude reads or edits a file there. Rules in .claude/rules/ can carry a paths field, such as src/api/**/*.ts, and then load only for matching files.
A few details change what a file costs and what Claude sees:
- Anthropic recommends under 200 lines per file, because longer files “consume more context and reduce adherence”. Claude Code skips a file over 4 MiB entirely. Choosing what goes in them is context engineering.
- An
@pathimport pulls another file in, up to four hops deep. Imported files load with the file that imports them, so they save no tokens. - Block-level HTML comments are stripped before the content reaches Claude, so they can hold notes for maintainers.
/initwrites a first CLAUDE.md from your codebase./doctor prompt-audit, in version 2.1.283 and later, lists outdated or conflicting instructions and changes nothing until you ask.
Since version 2.1.277, published on September 18, 2026, Claude Code also reads AGENTS.md when there is no CLAUDE.md or CLAUDE.local.md in the working directory or above it. To keep both files, set Project instructions to claude-md-and-agents-md in /config, or put @AGENTS.md at the top of your CLAUDE.md.
What does auto memory save, and where?
Auto memory holds the notes Claude takes for itself as it works. It arrived in version 2.1.59, published on February 25, 2026, with the changelog line “Claude automatically saves useful context to auto-memory. Manage with /memory” (changelog, npm). Version 2.1.63 shared it across the worktrees of a repository three days later. Version 2.1.74 added the autoMemoryDirectory setting on March 11.
Claude files each note under one of four types, written in the note’s frontmatter:
user: your role, expertise and working preferences;feedback: the corrections you give and the approaches you confirm;project: ongoing work, deadlines and decisions that the code and the git history do not show;reference: where to find outside information, such as an issue tracker or a dashboard.
Claude skips what the codebase shows, such as architecture, file paths and debugging fixes, and what your CLAUDE.md files already say. The directory holds an index and one file per note:
~/.claude/projects/<project>/memory/
├── MEMORY.md index, one line per memory, loaded at session start
├── user_role.md one memory
└── feedback_testing.md one memoryOnly the first 200 lines or 25 KB of MEMORY.md load at session start, whichever comes first. Claude opens a topic file when it needs it. Near a limit, Claude Code tells Claude to shorten the index. Past it, the write returns an error, because everything after the cutoff is dropped at the next load.
Auto memory is on by default in local sessions and off by default in self-hosted environments. The toggle in /memory saves autoMemoryEnabled in ~/.claude/settings.json, and CLAUDE_CODE_DISABLE_AUTO_MEMORY=1 turns it off from the environment.
Subagents do not receive the main conversation’s auto memory. A subagent with memory: project in its definition keeps its own notes in .claude/agent-memory/<name>/, which can be committed (Claude Code Docs).
How do you see, edit or delete Claude Code memory?
Type /memory in a session. It lists your CLAUDE.md, CLAUDE.local.md and auto memory locations, holds the auto memory toggle and opens the auto memory folder. Every file is plain Markdown, so you edit or delete it in your editor. You can also ask in the chat. “Remember that the API tests need a local Redis” goes to auto memory. “Add this to CLAUDE.md” goes to CLAUDE.md. To check what loaded in a session, run /context all and read the list under Memory files.
To delete a project’s auto memory, delete the files in ~/.claude/projects/<project>/memory/, or turn auto memory off in /memory to stop new notes. The 30-day transcript cleanup never removes these notes.
What survives /compact and a new session?
When a conversation fills the context window, /compact or auto-compaction replaces it with a summary. Anthropic lists what is read again from disk and what is summarized away (Claude Code Docs).
An instruction that disappears after compaction was given only in the chat, sits in a nested CLAUDE.md that has not reloaded yet, or is a path-scoped rule that has not matched a file since. Moving it to the project-root CLAUDE.md, or removing its paths field, keeps it.
Where does Claude Code memory stop?
Its limits come from where the files live.
- One machine. Anthropic writes that auto memory “is machine-local” and that its files “are not shared across machines or cloud environments”. A laptop, a desktop and a cloud session each build their own.
- One person. Auto memory sits in your home directory, so a teammate never sees the decision Claude noted for you. Only a committed CLAUDE.md reaches the team.
- One tool. The directory sits under
~/.claude, and Anthropic documents no way for Codex, Cursor or the Claude app to read it. Claude Code reads an AGENTS.md, but that file holds instructions, not the notes Claude took. - 200 lines at start. The index loads only up to its limit, so an old note stays visible only while MEMORY.md stays short.
Conflicts are the other gap. Anthropic warns that when two instructions contradict each other, “Claude may pick one arbitrarily”. Nothing flags a conflict between a CLAUDE.md rule and a newer auto memory note. We describe how such conflicts build up in how an AI memory ends up contradicting itself.
How do you share memory across machines and coding agents?
You move the memory out of ~/.claude and give each agent a way to reach it. For instructions, a committed CLAUDE.md or AGENTS.md is enough. For what builds up over time, the options below appear in the search results for Claude Code memory.
| Option | What it is | Where the memory lives | Agents |
|---|---|---|---|
| CLAUDE.md and AGENTS.md | Instruction files committed with the code | The repository | Claude Code, and agents that read AGENTS.md |
| claude-mem | An Apache 2.0 project. A second agent takes notes while yours works, and each session opens with an index of past observations | ~/.claude-mem on your machine, in SQLite with Chroma for search; cloud sync is opt-in | Claude Code, Codex, Cursor, OpenCode and 11 more, according to its README |
| Knowledge Graph Memory Server | The MCP project’s reference memory server. It stores entities, relations and observations | One JSONL file, set with MEMORY_FILE_PATH | Any MCP client that starts it; each client runs its own process, and writes to a shared file take turns |
| CrystalBrain | One memory your AI apps and coding agents share, with a dashboard to read and fix it | Hosted, with the database in Paris | Claude Code, Cursor and Codex over MCP, plus Claude, ChatGPT and Gemini |
Committed files are enough for rules the whole team follows. claude-mem records sessions with no instruction to the agent and stores the memory on your machine. Its note-taking agent runs on a hosted service with a 30-day trial that asks for a payment method, on your own OpenRouter or Gemini key, or on your Anthropic plan, and its anonymous analytics are on by default. The Knowledge Graph server is one local file, shared by the clients on one computer. CrystalBrain is built for people who use several agents on several machines and want to read and correct what all of them remember.
How we connect Claude Code to CrystalBrain
CrystalBrain is one memory your AI apps share. Claude, ChatGPT, Gemini, your coding agents and your own app read and write it, and you can see and fix every memory. With Claude Code, CLAUDE.md keeps the rules every session must follow. CrystalBrain holds the decisions, conventions and fixes that build up, and Claude searches it instead of reading everything at each start. The Connections page gives two steps.
- Add the server. Run
claude mcp add --transport http --scope user crystalbrainfollowed by your link, which adds it for all your projects. Then type/mcpin Claude Code, pick crystalbrain, choose Authenticate, sign in to CrystalBrain and click Approve. If the sign-in fails, Connections gives a link with a built-in key instead. - Tell Claude Code to use it. Paste the instruction from the same page into
~/.claude/CLAUDE.mdor into a project’s CLAUDE.md. Without it, Claude Code may not call the memory on its own. The instruction asks Claude to search the memory before its first reply and to save decisions, preferences and learnings as they come up.
Optional hooks run the search and the save without the instruction. The command curl -fsSL https://crystalbrain.ai/hooks/install.sh | bash -s -- claude-code adds a SessionStart and a SessionEnd hook to ~/.claude/settings.json. It needs Node.js 18 and an API key, kept in ~/.config/crystalbrain/config.json.
- At the start of a new session, the hook searches for the project’s decisions, conventions, preferences and open questions, by folder name, and hands Claude up to 8 memories. A resumed session gets nothing, since its earlier context is already there.
- At the end, it sends the last 8 messages, up to 8,000 characters, and CrystalBrain keeps what is worth remembering. Keys, tokens and private keys are replaced before anything leaves the machine. A session where none of your messages reaches 40 characters is not sent.
- The same script installs the hooks for Codex. Cursor gets the MCP connection without hooks.
For a team, a GitHub Actions workflow on the Connections page saves each merged pull request, with its title, description and link, in a brain named after the repository. In the dashboard, every memory shows the app that wrote it, and each edit keeps the previous version. Memory checks send contradictions to a Review queue, once a week per brain on the Free plan and daily or weekly on paid plans.
CrystalBrain is hosted. Its database is in Paris, and Voyage AI and Anthropic, both in the United States, process text to build the search and to check memories. Your own account never counts as a tracked user, and the Free plan needs no card. The memory page for Claude Code, Cursor and Codex has the steps for each agent, and the Connections guide describes every tab.
FAQ
Is Claude Code memory the same as Claude’s chat memory?
No. The Claude app keeps memory in your Claude account, by topic and by project. Claude Code keeps files on your computer. Anthropic documents them as two separate systems.
Is there a memory skill for Claude Code?
Its built-in memory needs none. Anthropic suggests moving a multi-step procedure out of CLAUDE.md into a skill, because a skill loads only when you invoke it or when Claude finds it relevant. Memory plugins bring their own: claude-mem ships a mem-search skill that searches past sessions.
Does Claude Code memory work in cloud sessions?
A CLAUDE.md committed to the repository travels with it. Auto memory from your computer does not, since its files are not shared with cloud environments. In the Claude Code projects beta, cloud threads share a memory of their own.
Sources
- Anthropic, How Claude remembers your project, Claude Code Docs, checked November 26, 2026.
- Anthropic, Explore the context window, Claude Code Docs, section “What survives compaction”, checked November 26, 2026.
- Anthropic, Manage sessions, Claude Code Docs, checked November 26, 2026.
- Anthropic, Create custom subagents, Claude Code Docs, section “Enable persistent memory”, checked November 26, 2026.
- Anthropic, All settings, Claude Code Docs,
cleanupPeriodDays, checked November 26, 2026. - Anthropic, Claude Code changelog, versions 2.1.59, 2.1.63 and 2.1.74, with publication dates from npm, checked November 26, 2026.
- Anthropic, Projects redesigned: from folder to conversation, September 17, 2026.
- claude-mem, thedotmack/claude-mem README, GitHub, checked November 26, 2026.
- Model Context Protocol, Knowledge Graph Memory Server README, GitHub, checked November 26, 2026.