[BUG] /compact causes Claude Code to ignore CLAUDE.md
Environment
- Platform (select one):
- [ ] Anthropic API
- [ ] AWS Bedrock
- [ ] Google Vertex AI
- [x] Other: claude code
- Claude CLI version: all versions
- Operating System: Ubuntu 22.04 LTS
- Terminal:
Bug Description
After using /compact (or when auto-compress triggers), Claude Code stops respecting the instructions in CLAUDE.md and begins to behave unpredictably.
Steps to Reproduce
- Create or update a CLAUDE.md file with custom instructions.
- Start a conversation and ensure Claude Code follows the instructions.
- Use
/compactor let auto-compress trigger. - Continue the conversation and observe that Claude Code no longer adheres to CLAUDE.md.
Expected Behavior
Claude Code should continue to follow the rules and instructions defined in CLAUDE.md even after the conversation is compacted.
Actual Behavior
After compaction, Claude Code ignores CLAUDE.md and generates responses that do not align with the specified guidelines.
@jaried you/i should check the logfiles in ~/.claude/projects to confirm, but I think the CLAUDE.md basically gets loaded into context at the beginning, and then I imagine what's happening is that it's part of the history that's being compacted/summarized during compact. Would be interesting to confirm that. But in any case, just because a bug "makes sense" doesn't make it not a bug.
I believe a quick and easy solution for this is to have an PostCompact hook that forcefully re-reads both global and local CLAUDE.md files to the model
I believe a quick and easy solution for this is to have an PostCompact hook that forcefully re-reads both global and local CLAUDE.md files to the model
But Compact only has Precompact hook I think)?
I haven't find a way to trigger an action post compact (that isn't done via the preHook).
It seems very useful though, like monitoring auto compacts in a session or triggering custom context procedures beyond Claude.md
I believe a quick and easy solution for this is to have an PostCompact hook that forcefully re-reads both global and local CLAUDE.md files to the model
But Compact only has Precompact hook I think)?
I haven't find a way to trigger an action post compact (that isn't done via the preHook).
It seems very useful though, like monitoring auto compacts in a session or triggering custom context procedures beyond Claude.md
Some weeks ago I was working on a Stop hook script that read the .json chat files, and determined when was the latest compact and if an injection of CLAUDE.md happened after that or not. If not, then it printed the CLAUDE.md with Exit code 2 to force the model to read it. But it turned out to be much more complex than I initially thought.
basically same: #4517
I can confirm. Claude basically looses the plot after compression and violates all the rules.
This is really annoying. just add a PostCompact hook and I'll be happy.
I believe that the new conversation Hook works for this
same problem here. please make claude always remember claude.md content and rules, even after compression
Still a huge issue. You have to ask to read claude.md after every compact.
Found something interesting: Claude Code auto-reads .md files from ~/.claude/ AFTER you compact - meaning your instructions can survive compaction.
Tested with verification codes. After compact, Claude knew codes I never mentioned = proof files auto-loaded.
Impact: You can have persistent context that survives compaction, but only if you manage your file count strategically (found a 5-file limit).
Full investigation: https://gist.github.com/Kevthetech143/f6962aa451253f23aba49175fc49f366
@anthropics Is this intentional? Worth documenting?
This issue has been inactive for 30 days. If the issue is still occurring, please comment to let us know. Otherwise, this issue will be automatically closed in 30 days for housekeeping purposes.
This issue is still happening. Anthropic this is such an easy fix. Just create/enable a post compact hook. You release features far less useful than this all the time.