[HYPOTHESIS] Post-compaction CLAUDE.md drift may be a positioning problem, not a content preservation problem
The problem
After compaction, Claude drifts from CLAUDE.md rules. This is widely reported (#9796, #14258, #25528, #6549, #36068). The common diagnosis is that instructions get lost or summarized during compaction.
But CLAUDE.md is not lost. It is reloaded fresh from disk after every compaction. The content survives verbatim. So why does drift still happen?
Hypothesis: it's about position, not presence
After compaction, the context loads in this order:
- System prompt (safety rules, tool definitions)
- Compacted summary (conversation narrative — may paraphrase project rules)
- CLAUDE.md (system-reminder — the actual rules)
- Memory files
- New messages
The compacted summary at position 2 often restates project rules in its own words. Because it appears before CLAUDE.md at position 3, the model gives more weight to the summary's interpretation than the actual rules.
This is consistent with the "lost in the middle" effect documented in LLM research (Liu et al., 2023) — content earlier in the context window receives more attention weight than content in the middle.
Why this matters
If drift is a positioning problem rather than a content preservation problem, then the fix isn't better preservation (the content is already preserved). The fix is moving CLAUDE.md above the compacted summary in the context order — treating it as system-level context with the same priority as the safety prompt.
My experience
I'm at 50+ sessions on a single project with extensive CLAUDE.md rules (~4K tokens). After compaction, I consistently observe:
- Rules being followed loosely rather than exactly
- The "spirit" of rules being applied but specific requirements missed
- Needing to push back 2-3 times before Claude re-reads the actual CLAUDE.md
I implemented a workaround: a PreCompact hook sets a flag, then a UserPromptSubmit hook injects a short directive on the first post-compaction message telling Claude to treat CLAUDE.md as authoritative over the summary. Early results suggest this helps but doesn't fully solve it — the directive itself lands at the bottom of context (with the user message), not at the top.
Question for the community
Has anyone else observed that:
- CLAUDE.md content survives compaction but drift still happens?
- The drift gets worse with longer/more detailed compacted summaries?
- Explicitly telling Claude to "re-read CLAUDE.md" after compaction partially fixes it?
If so, that would support the hypothesis that positioning — not content loss — is the root cause.
Suggested fix
Allow CLAUDE.md to be pinned at the top of the context window, before the compacted summary, with the same priority as the system prompt. This could be:
- A setting:
"claudeMdPriority": "system" - Or structural: load CLAUDE.md as part of the system prompt rather than as a system-reminder after the summary
---
Environment: Claude Code 2.1.x, Claude Opus 4.6 (1M context), macOS, 50+ session project
This issue has 7 comments on GitHub. Read the full discussion on GitHub ↗