Claude Code ignores your 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. No error, no warning.
Sources checked 2026-09-25.
Why rules disappear at compaction
Compaction is a rewrite. The model summarizes the conversation under a token budget, and behavioral rules are context, not code. Reports on the Claude Code tracker document exactly this: session status blocks, memory writes, and no-stop policies dropping away right after compaction.
Related reports show summarization dropping instructions and workarounds that were established early in the session, which sends the agent back to default behavior without anyone asking it to change.
The mechanism is the same in every case. If a rule is only in the conversation, compaction can remove it. If it is in a file, it needs something to load it back.
Free fixes you can do today
These work today, with no new tools.
- 1
Promote recurring rules into checks
A rule that a lint, test, or pre-commit hook can enforce does not need to survive compaction, because it is verified mechanically.
- 2
Re-anchor right after compaction
One sentence: "before continuing, re-read CLAUDE.md and DECISIONS.md." It resets behavior without restarting the work.
- 3
Compact at boundaries
The fewer moving parts in the session at compaction time, the less there is to drop. Commit first, compact second.
- 4
Keep the rules list short
A short list of hard rules gets followed more reliably than a long list of preferences, before and after compaction.
The durable fix
The reason rules vanish is that nothing re-injects them. MemoryRouter flushes the session to memory before compaction and re-injects relevant project context immediately after, so instructions and decisions return without a human prompt.
The same memory is recalled before every subsequent prompt, which means a rule stays available for the whole session instead of only the first hour.
- 1
Install the hooks
In your project
npx -y memoryrouter-claude init - 2
Record the rules that matter as memories
Rules with a reason attached recall better than bare imperatives, because retrieval matches meaning rather than exact wording.
- 3
Verify after a compaction
Force compaction and check the behavior. If the rule still holds, the layer works. Doctor confirms health any time: npx -y memoryrouter-claude doctor
Full setup guide: Claude Code setup guide
Hook events, scopes, and verification on the Claude Code page. 14-day free trial.
Related
CLAUDE.md not being followed
You wrote the rule, the file is in the repository, and the session keeps breaking it.
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.
Codex memory
Persistent project context for Codex sessions, with a published hooks package.
FAQ
Sources
- anthropics/claude-code issue 67500: compaction loses behavioral rules
- anthropics/claude-code issue 10232: auto-compact loses instructions
- Claude Code hooks reference
Sources checked 2026-09-25. Tool behavior changes; check the vendor docs before relying on a detail.