claude-code icon indicating copy to clipboard operation
claude-code copied to clipboard

[BUG] /compact causes Claude Code to ignore CLAUDE.md

Open jaried opened this issue 5 months ago • 13 comments

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

  1. Create or update a CLAUDE.md file with custom instructions.
  2. Start a conversation and ensure Claude Code follows the instructions.
  3. Use /compact or let auto-compress trigger.
  4. 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 avatar Jul 20 '25 10:07 jaried

@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.

hesreallyhim avatar Jul 21 '25 16:07 hesreallyhim

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

alexx-ftw avatar Jul 26 '25 17:07 alexx-ftw

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

JulianCrespi avatar Jul 26 '25 17:07 JulianCrespi

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.

alexx-ftw avatar Jul 26 '25 17:07 alexx-ftw

basically same: #4517

jaens avatar Aug 02 '25 18:08 jaens

I can confirm. Claude basically looses the plot after compression and violates all the rules.

Ba-So avatar Aug 17 '25 05:08 Ba-So

This is really annoying. just add a PostCompact hook and I'll be happy.

flux627 avatar Aug 22 '25 18:08 flux627

I believe that the new conversation Hook works for this

alexx-ftw avatar Aug 22 '25 19:08 alexx-ftw

same problem here. please make claude always remember claude.md content and rules, even after compression

tiagogbarbosa avatar Aug 28 '25 23:08 tiagogbarbosa

Still a huge issue. You have to ask to read claude.md after every compact.

extremesecrecy avatar Sep 25 '25 15:09 extremesecrecy

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?

Kevthetech143 avatar Nov 02 '25 16:11 Kevthetech143

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.

github-actions[bot] avatar Dec 10 '25 10:12 github-actions[bot]

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.

TerrysPOV avatar Dec 20 '25 16:12 TerrysPOV