Claude Code, Codex and Cursor
How do I give Claude Code memory that persists between sessions?
Alexandru Lupascu, CTO & Co-founder · Updated
Claude Code persists memory between sessions through files on disk, not through the conversation: a CLAUDE.md you write, which loads in full at every session start, and auto memory, which Claude writes to ~/.claude/projects/<project>/memory/ and which is on by default in local sessions. According to Anthropic's Claude Code docs, each session begins with a fresh context window, so a fact you only mentioned in chat is missing from the next session unless it was saved to one of these files. Resuming an old conversation with claude --continue brings that conversation back, which is not the same as memory.
How do you set up persistent memory in Claude Code?
Set up both files once per project, then check that they load:
- Run
/initin the project root. Claude Code analyzes the codebase and writes a starting CLAUDE.md with build commands, test instructions and conventions. - Trim it to under 200 lines and commit
./CLAUDE.md, so every session and teammate gets it. Put personal notes inCLAUDE.local.mdand add that file to.gitignore. - Open
/memoryand confirm the auto memory toggle is on. The toggle savesautoMemoryEnabledto~/.claude/settings.json. - Tell Claude what to keep. "Remember to always use pnpm, not npm" goes to auto memory; "add this to CLAUDE.md" goes to the file.
- Start a new session, run
/context, and check that your files appear under Memory files.
What persists between sessions, and what does not?
Files persist; the conversation does not, unless you resume it. Based on the Claude Code memory, subagent and session docs:
| What | Persists? | Detail |
|---|---|---|
| CLAUDE.md files | Yes | Loaded in full every session; files over 4 MiB are skipped |
| Auto memory | Yes, on this machine | MEMORY.md index loaded up to 200 lines or 25KB; topic files read on demand |
| Subagent memory | Yes | A subagent with a memory field keeps its own directory, scoped to user, project or local |
| Conversation | Only if resumed | claude --continue reopens the latest session in the directory; transcripts are deleted after cleanupPeriodDays, 30 days by default |
Auto memory files are excluded from that cleanup and stay until you or Claude edit or delete them.
How do you keep persistent memory accurate?
Review memory like code, because stale notes load into every session. Run /memory and open the auto memory folder to read what Claude saved; every file is plain markdown. When Claude writes a memory file with frontmatter, Claude Code records a modified timestamp, so you and Claude can see how current a fact is. If MEMORY.md grows past 200 lines or 25KB, Claude Code tells Claude to rewrite the index, because everything past the limit is dropped on the next load. For CLAUDE.md, /doctor prompt-audit reports outdated instructions, references to files or commands that do not exist, and files that contradict each other.
When do you need memory beyond Claude Code's own files?
Claude Code's persistent memory is per developer and per tool, which is enough for one person on one machine. Teams usually hit two limits: auto memory is machine-local, and it lives in Claude Code's own ~/.claude directory, so sharing it with teammates or other coding agents takes extra setup (see one memory across coding agents). MCP memory servers are one option, explained in what an MCP memory server is. elephant.broker, a pluggable runtime for AI agents, is another: according to its website, every turn recalls from, and writes back to, one graph and vector store, gateway-isolated per tenant, and a post-turn hook captures decisions, corrections and outcomes for the next turn. elephant.broker connects through an MCP server, native plugins or a REST API, and adds a retrieve and rerank step to every turn.
Sources
- Anthropic: Claude Code memory docs, Claude Code subagents, Claude Code sessions, Claude Code costs
- elephant.broker: overview, how a turn flows
Product details come from each vendor's public documentation as viewed on 2026-10-23 and may have changed. Product names are trademarks of their respective owners; elephant.broker is not affiliated with them.