[BUG] Claude forgets everything in CLAUDE.md after compaction
Open 💬 20 comments Opened Aug 22, 2025 by flux627
💡 Likely answer: A maintainer (igorkofman, collaborator)
responded on this thread — see the highlighted reply below.
Environment
- Platform (select one):
- [x] Anthropic API
- [ ] AWS Bedrock
- [ ] Google Vertex AI
- [ ] Other: <!-- specify -->
- Claude CLI version: 1.0.88 (Claude Code)
- Operating System: macOS 14.5 (23F79)
- Terminal: iTerm2
Bug Description
My complex project has a lot of things that need to be known for agentic workers to navigate effectively. All these details are listed in my project's CLAUDE.md located at the root of my project. I noticed that I have to tell it to re-read this every time it compacts, otherwise it starts doing things in "common sense" ways that deviate from the "correct way" that is defined. After re-reading, all problems disappear.
Steps to Reproduce
- have a complicated project with specific operational requirements
- do a lot of work until compaction
- watch claude not follow CLAUDE.md
- tell claude to read CLAUDE.md and watch it follow it
Expected Behavior
After compaction, Claude should remember or re-read CLAUDE.md
Actual Behavior
Claude does not remember CLAUDE.md after compaction
Additional Context
None
20 Comments
Found 3 possible duplicate issues:
This issue will be automatically closed as a duplicate in 3 days.
🤖 Generated with Claude Code
Could you try asking Claude to recite what is in CLAUDE.md when compaction happens (you can trigger compaction manually using /compact). In my testing it still have the contents of CLAUDE.md in context but would be great to have a repro of this not happening.
I have this problem with every auto-compact. Claude Code forgets what is in Claude.md and I have to tell it to read again.
I can confirm this issue is critical for production workflows. I maintain a comprehensive CLAUDE.md with specific instructions for:
After conversation compaction/summarization, Claude needs to be explicitly reminded to follow CLAUDE.md conventions, otherwise it reverts to generic behavior that doesn't match my established patterns.
Real example from today: Built a smart email archiver system with specific filtering rules, attachment handling, and vault organization patterns all defined in CLAUDE.md. After compaction, continuing work would require manually asking Claude to re-read the context.
Impact: This breaks continuity in long-running projects where CLAUDE.md serves as the single source of truth for project-specific conventions.
+1 for making CLAUDE.md persistent across compaction cycles.
I routinely have this problem as well. It just wiped out a running production project because it carried on making changes after compaction and before I could catch it.
@claude : just create/enable a post compact hook and this MAJOR issue would be solved. You release features all the time far more useless and complex than this would be to do. Come on guys this is killing us!
I also routinely run long sessions (sometimes for weeks) with hundreds of interactions and dozens of context compactions. After every compact, I have to tell it to re-read the memory files. Please either make this automatic, or add a hook for after compact.
Edit: I would likely not recommend the below, due to https://news.ycombinator.com/item?id=46723384
(possibly off-topic, but on the topic of guideline stability): It seems we can, even without CLAUDE.md changes, "poison" the compactor agent itself, transferring style+information (i.e. guidelines) into the summary, and can even give the summarizer tasks. I presume this would be easier if you added lines in CLAUDE.md for the summarizer ('upon a summary request...'). I also assume that this is all within normal expectations since this issue implies guiding auto-compaction is an expected of CLAUDE.md: https://github.com/anthropics/claude-code/issues/7708#issuecomment-3300781207
If you have Claude Code give such a compaction summary to a subagent, that subagent will automatically assume certain guidelines. Seems like the models give extra high priority to 'the summary' over other things. Presumably one could just skip all the ceremony and write their own compaction-summary-like text for any Claude Code agent to pattern match on.
Something possible more useful for auto-compaction: TodoWrite a final item for "read CLAUDE.md post-compaction" (haven't tested though)
HALF A YEAR! And nothing done for that. I'm sorry, this isn't even free, we pay you money for that
I dont know that is the problem to implement this? The lack of this make experience WAY worst, as someone that pay 200USD/MONTH i guess you guys need at least a explanation why dont want to implement, because its IMPOSSIBLE to be hard to implement a hook after compact!
Findings from extensive SessionStart hook experimentation
We tested using the existing
SessionStarthook withcompactmatcher to auto-refresh CLAUDE.md. Here's what we found:Setup that works for
/clear:With reminder content:
Key insight: The instruction must be the first line and include a specific observable action (say a phrase, then visibly read file). Passive context injection doesn't work.
Results:
| Trigger | Hook fires? | Content injected? | Claude follows it? |
|---------|-------------|-------------------|-------------------|
|
/clear| ✅ | ✅ | ✅ ||
/compact| ✅ | ✅ | ❌ |The problem with
/compact: The compacted conversation summary creates "momentum" that overrides the injected reminder. Claude sees the summary ("user asked about X") and continues that thread, ignoring the hook output.Suggested fix: The hook output needs higher priority than the compacted summary - perhaps injected AFTER the summary in Claude's context, or treated as a system instruction rather than context.
This has been my biggest pain point too — CLAUDE.md instructions forgotten after compaction, and then Claude goes off-script. The root issue is that compaction is lossy compression, and when it's operating on a session full of noise (progress ticks, duplicate system reminders, stale file reads, metadata), the signal-to-noise ratio is terrible and the important stuff gets summarized away.
What helped me was Cozempic. The approach: remove the noise before compaction fires, so when it does compress, it has a much better signal-to-noise ratio and CLAUDE.md instructions are more likely to survive.
cozempic initauto-wires a guard daemon that starts on every session and continuously prunes dead weight — progress ticks (often 40-50% of session size), duplicate system-reminder injections, stale file reads that were superseded by later edits, thinking block signatures, metadata bloat. On a typical session I see 15-22% size reduction from pure noise removal.The result: compaction triggers far less often, and when it does, it has much less junk to wade through. Won't fix the fundamental issue of compaction being lossy, but it significantly reduces how often you hit it and improves the quality when you do.
Would appreciate if you could give it a try and let me know if it helps with the CLAUDE.md retention. If compaction is still dropping your instructions after pruning, I'd like to investigate what's left in the session and see if there are additional strategies to apply.
This thread captures the core problem well — compaction summaries create "momentum" that overrides re-injected instructions.
I've been running mnemon in production to address this — it's a standalone skill binary for persistent agent memory. Rather than fighting the compaction summary, mnemon stores knowledge in a local SQLite graph outside the context window. After compaction, the
SessionStarthook re-injects relevant entities via structured recall — not re-reading a monolithic CLAUDE.md, but querying specific facts and decisions relevant to the current work.The
PreCompacthook also extracts critical insights before compression occurs, so knowledge survives the cycle.mnemon setupauto-detects Claude Code and deploys skill + four lifecycle hooks. Portable — the same binary + skill works across Claude Code, OpenClaw, and any LLM CLI that reads markdown skills.Would be nice if you stop advertising your own projects here, especially without a disclaimer.
Sorry about that, I have done that everywhere but sometimes gets missed by
the prompt
Regards,
Junaid Ali Qureshi
On Tue, 24 Feb 2026 at 6:19 AM Erik Pragt @.***> wrote:
Any update on this?
A PreCompact hook can save critical state before compaction happens:
Register as PreCompact hook in settings.json. After compaction, the next turn can read
~/.claude/session-handoff.mdto recover context about what was happening.For automatic session end state capture:
Not a complete fix (CLAUDE.md should be re-injected by the system), but preserves the "what was I working on" context.
I keep seeing the same failure pattern: the agent follows repo-specific rules until compaction, then falls back to generic behavior and starts violating the project’s actual way of doing things.
For people here, what rule types hurt most when they get dropped? Stack constraints, migration/schema rules, banned commands/patterns, or post-task workflow steps?
This is caused by compaction summarizing CLAUDE.md instructions into prose — the specific rules get diluted or dropped. The
compact-summary-collapsestrategy in Cozempic v1.4.1 proactively removes stale pre-compaction content (85-95% savings) so compaction operates on a much smaller, cleaner input.Additionally, the behavioral digest feature extracts your corrections and syncs them to Claude Code's memory system as
feedbacktype memories. These persist on disk and survive compaction natively — Claude re-reads them on every turn.pip install cozempic && cozempic initRun
cozempic digest showto see what rules have been extracted from your sessions.This is a known structural limitation — compaction summarizes conversation history but doesn't preserve the full CLAUDE.md context. Two workaround approaches using hooks:
1. Save state before compaction (PreCompact hook)
Register in
settings.json:After compaction, Claude can read
.claude/pre-compact-checkpoint.mdto recover context.2. Periodic CLAUDE.md re-injection (PostToolUse hook)
This extracts lines containing enforcement markers (ABSOLUTE, MUST NEVER, etc.) and prints them to stderr every 20 tool calls. The output appears in Claude's context, acting as a persistent reminder that survives compaction.
Neither approach is perfect — the root fix needs to come from Anthropic preserving CLAUDE.md context across compaction boundaries. But these hooks significantly reduce the "amnesia" effect in long sessions.