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

Resolved 💬 18 comments Opened Jul 20, 2025 by jaried Closed Jan 21, 2026

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: <!-- e.g. iTerm2, Terminal App, GNOME 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.

View original on GitHub ↗

18 Comments

hesreallyhim · 12 months ago

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

alexx-ftw · 11 months ago

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

JulianCrespi · 11 months ago
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

alexx-ftw · 11 months ago
> 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.

jaens · 11 months ago

basically same: #4517

Ba-So · 11 months ago

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

flux627 · 10 months ago

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

alexx-ftw · 10 months ago

I believe that the new conversation Hook works for this

tiagogbarbosa · 10 months ago

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

extremesecrecy · 9 months ago

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

Kevthetech143 · 8 months ago

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?

github-actions[bot] · 7 months ago

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.

TerrysPOV · 6 months ago

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.

github-actions[bot] · 5 months ago

This issue has been automatically closed due to 60 days of inactivity. If you're still experiencing this issue, please open a new issue with updated information.

marcindulak · 5 months ago

This issue was closed incorrectly despite recent human comments. This behavior of the bot is reported at https://github.com/anthropics/claude-code/issues/16497. Please upvote that issue, so maybe it gets noticed.

nikkundra · 5 months ago
This issue was closed incorrectly despite recent human comments. This behavior of the bot is reported at https://github.com/anthropics/claude-code/issues/16497. Please upvote that issue, so maybe it gets noticed.

@marcindulak just curious, would SessionStart not work for what you are trying to do?

marcindulak · 5 months ago

The point of my comment is that there is currently a "60 days of inactivity" bot that closes issues which contain active human discussions.

github-actions[bot] · 5 months ago

This issue has been automatically locked since it was closed and has not had any activity for 7 days. If you're experiencing a similar issue, please file a new issue and reference this one if it's relevant.