Claude Code memory across sessions: how to make it remember
Why Claude Code forgets between sessions and how to fix it: CLAUDE.md, auto memory, /memory, --continue and --resume, compaction, hooks and MCP memory.
Every Claude Code session starts with a fresh context window. What carries over is what Claude Code loads from disk:
your CLAUDE.md files and its own auto memory. To make Claude Code remember across sessions, put lasting
instructions in CLAUDE.md, let auto memory save your corrections, resume a past conversation with --continue or
--resume when you need its details, and add hooks or an MCP memory server for anything beyond that.
What carries over and what does not
The Claude Code memory docs name two layers that load into every session:
| Layer | Who writes it | Where it lives | What loads |
|---|---|---|---|
CLAUDE.md | You | ~/.claude/CLAUDE.md, ./CLAUDE.md, ./CLAUDE.local.md, .claude/rules/ | The whole file at launch |
| Auto memory | Claude | ~/.claude/projects/<project>/memory/ | The first 200 lines or 25KB of MEMORY.md |
Everything else from a past session is only in its transcript. A new session does not see what you said in the last one unless it ended up in one of these files.
Step 1: Put lasting instructions in CLAUDE.md
CLAUDE.md is the most reliable memory Claude Code has, because you control it and it loads in full.
- Run
/initto generate a firstCLAUDE.md. Claude reads your codebase and writes build commands, test steps and conventions it finds. If the file exists,/initsuggests improvements instead of overwriting it. - Put preferences for all projects in
~/.claude/CLAUDE.md, and private notes for one project inCLAUDE.local.md(add it to.gitignore). - Keep each file under 200 lines. The docs say longer files cost more context and reduce adherence. Move rules for
part of the codebase into path-scoped rules in
.claude/rules/.
To add something yourself, ask "add this to CLAUDE.md" or open the file with /memory.
Step 2: Let auto memory save corrections
Auto memory is on by default in local sessions. As Claude
works, it saves notes about you, your corrections, ongoing project decisions and where to find outside information.
It skips what it can derive from the code and what your CLAUDE.md already says. It does not save something every
session.
How it works:
MEMORY.mdis an index, one line per memory. Topic files hold the details and are read on demand, not at startup.- Only the first 200 lines or 25KB of
MEMORY.mdload at session start. Anything past that is dropped on the next load. - All worktrees and subdirectories of one git repo share one memory directory.
- It is machine-local: files are not shared across machines or cloud environments.
When you say "remember that the API tests need a local Redis", Claude saves it to auto memory. Messages like "Saved 2 memories" show it happening.
To check or change it, run /memory. It lists your CLAUDE.md files, opens the auto memory folder and has a toggle
that saves autoMemoryEnabled to ~/.claude/settings.json. Set CLAUDE_CODE_DISABLE_AUTO_MEMORY=1 to turn it off.
Step 3: Resume a past conversation
Sometimes you do not need a memory, you need the old conversation back. The sessions docs list the entry points:
claude --continue # most recent session in this directory
claude --resume # session picker
claude --resume auth-fix # a session by nameInside a session, /resume switches to another one. Name sessions with claude -n <name> or /rename so you can
find them later.
A resumed session restores the messages, tool calls and results. If it was compacted, Claude continues from the last
summary. Flags such as --mcp-config, --add-dir and --settings are not restored, so pass them again. Transcripts
are kept for 30 days by default (cleanupPeriodDays). Auto memory files are not part of that cleanup.
The tradeoff: resuming brings back one whole conversation, with its context cost. It is good for picking up a task, not for knowledge you want in every future session.
Step 4: Know what compaction keeps
Claude Code compacts automatically as the context fills, and you can run /compact yourself. Per the
context window docs:
- The project-root
CLAUDE.md, unscoped rules and auto memory are re-injected from disk. - Path-scoped rules and nested
CLAUDE.mdfiles load again only when Claude touches a matching file. - Instructions you gave only in chat are summarized with the rest of the conversation, and details can be lost.
If an instruction disappears after compaction, move it into CLAUDE.md. Use /compact focus on <topic> to choose
what the summary keeps.
Step 5: Add context with hooks
Hooks run shell commands at fixed points. For SessionStart and
UserPromptSubmit, Claude Code adds the command's stdout to Claude's context. A SessionStart hook with the
compact matcher runs after every compaction:
{
"hooks": {
"SessionStart": [
{
"matcher": "compact",
"hooks": [
{ "type": "command", "command": "echo 'Use Bun, not npm. Run bun test before committing.'" }
]
}
]
}
}The command can be anything that prints text, such as git log --oneline -5. Hook output is capped at 10,000
characters. For context you want on every start, the docs suggest CLAUDE.md instead.
Step 6: An MCP memory server
When files on one machine are not enough, add a memory server over MCP:
claude mcp add --transport http memory https://example.com/mcp --scope user--scope user makes it available in all your projects; the default local scope is one project only. The server
gives Claude tools to search and save memories, stored outside your repo and outside one machine.
The catch: over MCP alone, Claude has to decide to search, and it rarely searches for what it does not know it is missing. Servers that also install hooks can push memories in without being asked. See MCP memory servers compared.
Where axs brain fits
axs brain is one option for the MCP plus hooks approach. The Claude Code plugin
adds hooks on session start, every prompt, tool calls and the end of each answer, plus MCP tools such as
memory_search and memory_write.
- Your always-on rules load at session start, the memories of a project, server or tool on the first work there, and matching memories on every prompt.
- When you correct the agent, axs brain asks it to save the lesson as a short memory. It checks for near-duplicates first and refuses memories with secrets.
- The same memory works in Codex, Cursor and other MCP clients.
- If axs brain is down, every hook gives up after a few seconds and the agent keeps working without memories.
Setup, after you install the axs CLI:
axs login
axs install claudeOr without the CLI:
claude plugin marketplace add axs-sh/claude; claude plugin install brain@axsYour agent offers to import your existing CLAUDE.md in the first sessions. See
Plans and billing for prices.
The honest tradeoff: it is a hosted service, so your memories live outside your machine. If you work alone in one
repo, CLAUDE.md plus auto memory is often enough.
FAQ
Does Claude Code remember previous conversations?
Not on its own. A new session loads CLAUDE.md and auto memory, not past chats. Use claude --continue or
claude --resume to reopen a conversation.
Where does Claude Code store its memory?
CLAUDE.md files are where you put them. Auto memory is in ~/.claude/projects/<project>/memory/, and transcripts
are in ~/.claude/projects/<project>/ as .jsonl files.
Why did Claude forget my instruction mid-session?
Most likely compaction. Instructions given only in chat get summarized. Put them in the project-root CLAUDE.md,
which is re-injected after compaction.
Does auto memory sync between my laptop and desktop?
No. It is machine-local and not shared across machines or cloud environments. For that you need a file in git or a memory server.
Claude Code team memory: CLAUDE.md in git vs MCP
Share Claude Code memory with your team: commit a project CLAUDE.md to git, deploy a managed CLAUDE.md, or add shared memory over MCP and hooks. The tradeoffs.
CLAUDE.md vs AGENTS.md: one file for all coding agents
CLAUDE.md is Claude Code's instruction file, AGENTS.md the open format Codex, Cursor and others read. How to keep one file for every agent, and its limits.