Context compaction recovery loses critical behavioral rules (session status block, memory writes, no-stop policy)
Summary
After context compaction occurs mid-session, Claude reliably drops several critical behavioral rules that were established earlier in the conversation. This is a recurring problem across multiple sessions on this project.
Observed failures after compaction
- Session status block not shown after git commit/push — CLAUDE.md explicitly requires displaying a
✅ SESSION STATUSblock with branch/commit/sync state after every code change. This was followed correctly before compaction, dropped immediately after.
- Memory not written — User had explicitly requested that completed features be written to the memory system (
MEMORY.md+ individual.mdfiles). This instruction was followed before compaction, completely ignored after.
- No-stop policy violated — User explicitly instructed: complete the entire feature without stopping to ask "ready to continue?" or "should I proceed?". Before compaction this was respected. After compaction the assistant stopped mid-feature and asked for permission to continue, causing significant user frustration.
What the compaction summary contained
The compaction summary accurately described:
- What work was done (Phase 1 complete, Phase 2 in progress)
- What files were changed and why
- The user's explicit instruction to not stop mid-task
Despite the summary containing the user's instructions, the assistant did not follow them.
Impact
Each compaction failure wastes a full session's worth of tokens and causes the user to have to re-establish context manually. On this project it has happened multiple sessions in a row.
Expected behavior
Behavioral rules established in the conversation (especially those confirmed by the user during the session) should survive context compaction. The compaction summary should be treated as carrying the same authority as if the user had typed those instructions at the start of the new context window.
Environment
- Claude Code CLI
- Model: claude-sonnet-4-6
- macOS / zsh
- Project: TDSS Operations PWA (PHP/MySQL)
Reproducibility
Consistent across sessions on this project. Any session with a CLAUDE.md containing required post-action behaviors (e.g. "after every change, show status block X") will reproduce this if the session compacts mid-task.
Showing cached comments. Read the full discussion on GitHub ↗
5 Comments
I've hit this exact failure mode across multiple Claude Code projects — compaction is a reliability cliff, not just a UX annoyance.
What's happening technically: During compaction, Claude Code truncates the conversation prefix to stay under context limits. But the behavioral rules (CLAUDE.md directives, session-state markers, memory-write instructions) that were established in early turns get truncated if they're positioned in the middle of the conversation rather than anchored in system-level instructions.
Diagnostic matrix to verify you're hitting this:
--verboseand look for"compacting context"log lines. If a compaction event precedes the rule drop by 1-2 turns, that's the trigger.memorytool or file-based memory writes, verify those writes actually landed. Compaction can drop tool call results from the effective context even though the file was written.Immediate workaround that worked for me: Move ALL behavioral rules into CLAUDE.md (or
.claude/instructions.md) with explicit section headers. Anything that's "established during conversation" is a compaction casualty. Rules defined in CLAUDE.md are re-injected into the system prefix on every turn after compaction.Longer-term hardening: If this is a recurring production pain, I've found that maintaining an external rules manifest + a pre-turn validation hook (checking rule presence in context) cuts the failure rate significantly. Happy to share the approach if you hit the wall again.
The three failures you've documented all stem from the same root: compaction summaries don't carry the same instructional authority as live conversation context, even when they accurately describe the instructions that were being followed. The model sees "user instructed no-stop policy" in a summary and treats it as a historical fact, not as an active gate to enforce now — different weight from those same words when issued live. The CLAUDE.md instructions do survive (they're re-injected at session start), but mid-session behavioral refinements — "complete the whole feature without stopping," "write completed items to memory" — have no structured re-injection path through the compaction boundary.
Two things that help while Anthropic works on the summarizer:
Leaner session → better summarizer output. The amount of signal loss in a compaction summary scales with session size. A 15–20MB JSONL gets compressed much more aggressively than a 3MB one, and fine-grained behavioral confirmations ("yes, continue this way") are among the first things lost.
cozempic(pip install cozempic) prunes bloat from the session JSONL before compaction hits — redundant tool outputs, oversized file echoes, intermediate steps that don't carry forward — so the summarizer has a tighter, higher-signal session to work from and more budget for preserving session-specific behavioral context.Behavioral digest (coming soon). Cozempic is actively developing extraction of mid-session behavioral corrections/rules from the JSONL delta and re-injection of them at session tail after compaction. That would directly address your case: the "complete without stopping" gate and the "write to memory" instruction would survive compaction as explicit re-injected rules rather than buried history. Honest caveat: that's not in the current release, it's what the current gap is pushing toward.
The underlying fix needs to come from Anthropic — the compaction summarizer needs to treat confirmed behavioral rules at higher fidelity than task context. But keeping the session lean is the highest-leverage thing you can do today to reduce how much signal the summarizer has to throw away.
Observed Behavior
I am observing the exact same degradation pattern in my macOS zsh environment during multi-turn CLI sessions. After a certain token threshold or number of conversation turns (after compaction), the model undergoes a complete context drop.
Specifically, the failure mode presents as follows:
---
@TapanSedai — the failure pattern you're describing (tool-use memory, no-stop policy, memory write triggers all dropping at once) is a good illustration of why compaction isn't just a UX annoyance — it's a reliability cliff for session-specific behavioral state.
The mechanism: compaction rewrites the conversation prefix as a summary, and that summary describes what the rules were but doesn't carry the same instructional authority as a live CLAUDE.md injection or an explicit user statement. The model is now reasoning about a rule it "remembers" rather than one it's actively seeing, which is why enforcement becomes inconsistent turn-by-turn rather than a clean break.
The most durable workaround today is to put the critical rules in CLAUDE.md (not just established in-conversation) — CC injects that fresh on every turn regardless of compaction, so those instructions survive. For the in-conversation behavioral state that can't go in CLAUDE.md, keeping sessions lean enough to compact less often is the other lever:
cozempic treat current --execute(pip install cozempic) prunes blob-type JSONL content that fills the window fast, which delays when compaction fires and reduces cumulative summary drift.The honest limit: cozempic can delay compaction but not prevent it when you genuinely need long sessions. The root fix — compaction summaries preserving behavioral rules with the same authority as live instructions — is an Anthropic-side change.
Related observation, one data point from a long session: compaction doesn't just drop conventions — it can silently invert one.
We run a convention where unverified guesses are wrapped in brackets with a label, e.g.
[fee assumption — unverified]. Right before a compaction we listed the session's seven bracketed guesses, then inspected the summary. Five vanished (annoying but safe). One survived with its meaning intact by luck. One came back as a flat, confident figure — content kept, "this is a guess" label stripped. The next session inherits a laundered guess as established fact, with the provenance gone.So it's not only "rules followed before, ignored after" — the summarizer can also rewrite epistemic markers out of existence, which is worse than dropping them. Only things written to files came through unchanged.
Wrote it up with the mitigation here: https://github.com/TJ11000/claude-stall-tools/blob/main/BRACKET_VALVE.md (n=1, labeled as such).