Claude Code memory: what it keeps, and what compaction takes
Claude Code reads your instructions at startup, keeps a running summary of the session, and compacts when the context window fills. Everything the session learned that is not in a file dies at one of those boundaries.
Anthropic. Sources checked 2026-09-25.
How Claude Code handles memory today
Two systems, per the official memory docs. CLAUDE.md files are written by you and loaded in full at session start: project instructions, conventions, commands. Auto memory is Claude’s own notes, written to MEMORY.md during sessions, and only the first 200 lines or 25KB of it is loaded at startup.
A session also carries a live conversation, and Claude Code compacts when that fills up. The compaction summary is a lossy rewrite of the session, produced by the model, under budget pressure.
What Claude Code forgets
What survives a session is files. What does not survive is the reasoning behind them.
- Anything learned mid-session that never made it into a file: the failing approach you ruled out, the constraint you discovered, the reason a function is shaped the way it is.
- Detail inside the compaction summary. The model decides what matters while compacting, and the working knowledge behind the decision is usually what gets cut.
- Cross-project continuity. CLAUDE.md travels with the repository. If a session ended without a commit or a note, the next one starts cold.
- Auto memory depth. Its first 200 lines load at startup; everything past that waits for a lookup that may never come.
The fix with MemoryRouter
The published hook package installs at deterministic Claude Code lifecycle points. Recall runs before each prompt, capture runs after each completed turn, and compaction, resume, and fork all re-inject project memory the moment they finish.
- 1
Install the hooks in your project
Grab a Memory Key from the app, then run the installer in the repo. It wires SessionStart, UserPromptSubmit, Stop, PreCompact, PostCompact, resume, and fork.
Run inside your project
npx -y memoryrouter-claude init - 2
Verify the integration
Start a new session, then check health. A healthy setup ends with "Automatic memory integration is healthy."
Health check
npx -y memoryrouter-claude doctor - 3
Confirm it survives compaction
Stash a decision mid-session, force a compaction, then keep going. The recalled context comes back in the next turn instead of a request to restate the plan.
Your Memory Key stays under ~/.memoryrouter/ with owner-only permissions. It is never written into .claude or your repository, so hook settings are safe to commit for a team.
Full install guide, commands, and the MCP option on the Claude Code page. 14-day free trial.
Related
Full Claude Code guide
Full install guide, commands, and the MCP option on the Claude Code page. 14-day free trial.
Codex memory
Persistent project context for Codex sessions, with a published hooks package.
OpenClaw memory
Workspace files plus the mr-memory plugin for sessions that keep their context.
Claude Code lost context after compaction
One compaction event, and the session forgets the plan, the file names, and the constraint you spent an hour explaining.
Claude Code memory FAQ
Sources
- Claude Code memory docs (CLAUDE.md and auto memory)
- Claude Code hooks reference
- anthropics/claude-code issue 14227: persistent memory between sessions
Sources checked 2026-09-25. Tool behavior changes; check the vendor docs before relying on a detail.