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. This is the single most reported Claude Code failure, and the fix has two halves: what you do in the next five minutes, and what you install so it stops.
Sources checked 2026-09-25.
Why compaction erases context
Compaction replaces conversation history with a summary the model writes under a budget. It is designed to keep the story going, not to preserve working knowledge, so identifiers, constraints, and rejected approaches are the first things to go.
Public issue reports describe the same pattern: established column names and API parameters disappear, behavioral rules stop being followed, and the session starts re-doing work in the wrong order. One report documents silent context degradation even before compaction, where old tool results get cleared without notice.
The instructions you wrote in CLAUDE.md are also loaded once at startup, so a rule the session needs at hour three may no longer be in the window at all.
Free fixes you can do today
These work today, with no new tools.
- 1
Compact on purpose, not by accident
Run /compact at a natural boundary, right after a commit. You choose the moment, and the summary lands on a clean state instead of mid-refactor.
- 2
Write decisions into a file the moment they are made
A short, dated DECISIONS.md with one line per decision survives any compaction, because it is a file and not history. Ask Claude to append to it whenever a choice is settled.
- 3
Keep one task per session
Long mixed sessions accumulate fallout. Splitting them means a compaction can only damage one thread of work.
- 4
Use commits as checkpoints
A commit message that states intent is context that never compacts. Commit before you expect a long stretch of work.
- 5
Re-anchor after a compaction
When it happens, say "read DECISIONS.md and continue" instead of retyping the plan by hand. Files are the only reliable re-anchor.
The durable fix
Claude Code fires hooks at deterministic lifecycle points. MemoryRouter installs five of them: SessionStart warms the vault, UserPromptSubmit recalls relevant memory before every prompt, Stop captures the completed turn, and compaction events re-inject memory the moment they finish.
That means the plan comes back automatically after compaction, and it is there in a new session tomorrow, on another machine, and in another tool if you connect one.
- 1
Install the hooks
Run the installer in your project and paste your Memory Key when prompted. The key stays in your home directory, never in the repository.
One command
npx -y memoryrouter-claude init - 2
Verify with doctor
Health check
npx -y memoryrouter-claude doctor - 3
Prove it survives compaction
State a decision, force a compaction, then ask Claude what it is. With memory wired in, the answer comes back without you restating anything.
Full setup guide: Claude Code setup guide
Full install guide and commands. 14-day free trial.
Related
Claude Code memory
Keep project decisions across sessions and compaction with the published hook package.
conversation too long
The tell is subtle.
Claude Code ignores rules after compaction
The behavior is specific and repeatable: everything works, compaction runs, and then the session stops following the rules you set an hour ago.
FAQ
Sources
- Claude Code docs: memory
- anthropics/claude-code issue 29890: compaction loses working knowledge
- anthropics/claude-code issue 42542: silent context degradation
- anthropics/claude-code issue 10232: auto-compact loses instructions
Sources checked 2026-09-25. Tool behavior changes; check the vendor docs before relying on a detail.