[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

  1. have a complicated project with specific operational requirements
  2. do a lot of work until compaction
  3. watch claude not follow CLAUDE.md
  4. 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

View original on GitHub ↗

20 Comments

github-actions[bot] · 10 months ago

Found 3 possible duplicate issues:

  1. https://github.com/anthropics/claude-code/issues/4017
  2. https://github.com/anthropics/claude-code/issues/4517
  3. https://github.com/anthropics/claude-code/issues/1027

This issue will be automatically closed as a duplicate in 3 days.

  • If your issue is a duplicate, please close it and 👍 the existing issue instead
  • To prevent auto-closure, add a comment or 👎 this comment

🤖 Generated with Claude Code

igorkofman collaborator · 10 months ago

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.

DougJoseph · 10 months ago

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.

rogerc66 · 8 months ago

I can confirm this issue is critical for production workflows. I maintain a comprehensive CLAUDE.md with specific instructions for:

  • File creation protocols (checking for duplicates before creating)
  • Vault structure conventions (customer directories, naming patterns)
  • Tool-specific workflows (email archiving, git operations)
  • Integration points (MCP tools, custom scripts)

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.

tatyree · 7 months ago

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.

TerrysPOV · 6 months ago

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

solace-rcampbell · 6 months ago

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.

wiwa · 5 months ago

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)

asvishnyakov · 5 months ago

HALF A YEAR! And nothing done for that. I'm sorry, this isn't even free, we pay you money for that

tiagogbarbosa · 5 months ago

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!

SebRogala · 5 months ago

Findings from extensive SessionStart hook experimentation

We tested using the existing SessionStart hook with compact matcher to auto-refresh CLAUDE.md. Here's what we found:

Setup that works for /clear:

{
  "hooks": {
    "SessionStart": [{
      "matcher": "clear",
      "hooks": [{
        "type": "command",
        "command": "cat \"$CLAUDE_PROJECT_DIR\"/.claude/session-start-reminder.md; exit 0"
      }]
    }]
  }
}

With reminder content:

STOP. Your context was just reset.

Step 1: Say "Let me refresh my context first."
Step 2: Call Read tool on CLAUDE.md (visible to user)

DO NOT skip Step 2. DO NOT assume CLAUDE.md is loaded.

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.

junaidtitan · 5 months ago

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.

pip install cozempic
cozempic init

cozempic init auto-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.

Grivn · 4 months ago

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 SessionStart hook 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 PreCompact hook also extracts critical insights before compression occurs, so knowledge survives the cycle.

brew install mnemon-dev/tap/mnemon && mnemon setup

mnemon setup auto-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.

bodiam · 4 months ago
What helped me was [insert product here]. 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.

Would be nice if you stop advertising your own projects here, especially without a disclaimer.

junaidtitan · 4 months ago

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:

bodiam left a comment (anthropics/claude-code#6354) <https://github.com/anthropics/claude-code/issues/6354#issuecomment-3948503377> What helped me was Cozempic <https://github.com/Ruya-AI/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. Would be nice if you stop advertising your own projects here, especially without a disclaimer. — Reply to this email directly, view it on GitHub <https://github.com/anthropics/claude-code/issues/6354#issuecomment-3948503377>, or unsubscribe <https://github.com/notifications/unsubscribe-auth/AFVALNK24JZDJAJIJISHZ2L4NOYM5AVCNFSM6AAAAACESVBT46VHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZTSNBYGUYDGMZXG4> . You are receiving this because you commented.Message ID: @.***>
asvishnyakov · 4 months ago

Any update on this?

yurukusa · 3 months ago

A PreCompact hook can save critical state before compaction happens:

HANDOFF="$HOME/.claude/session-handoff.md"
{
    echo "# Pre-Compact State ($(date -Iseconds))"
    echo ""
    [ -d .git ] && echo "Branch: $(git branch --show-current 2>/dev/null)"
    [ -d .git ] && echo "Last commit: $(git log --oneline -1 2>/dev/null)"
    [ -d .git ] && echo "Modified: $(git diff --name-only 2>/dev/null | head -5)"
} > "$HANDOFF"
exit 0

Register as PreCompact hook in settings.json. After compaction, the next turn can read ~/.claude/session-handoff.md to recover context about what was happening.
For automatic session end state capture:

npx cc-safe-setup --install-example session-handoff

Not a complete fix (CLAUDE.md should be re-injected by the system), but preserves the "what was I working on" context.

lipcool8-ship-it · 3 months ago

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?

junaidtitan · 3 months ago

This is caused by compaction summarizing CLAUDE.md instructions into prose — the specific rules get diluted or dropped. The compact-summary-collapse strategy 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 feedback type memories. These persist on disk and survive compaction natively — Claude re-reads them on every turn.

pip install cozempic && cozempic init

Run cozempic digest show to see what rules have been extracted from your sessions.

yurukusa · 3 months ago

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)

#!/bin/bash
# PreCompact hook — saves session state before compaction
set -euo pipefail
INPUT=$(cat)

CHECKPOINT=".claude/pre-compact-checkpoint.md"
mkdir -p .claude

{
  echo "# Pre-compaction checkpoint ($(date -Iseconds))"
  echo ""
  echo "## Current branch"
  git rev-parse --abbrev-ref HEAD 2>/dev/null || echo "not a git repo"
  echo ""
  echo "## Modified files"
  git diff --name-only 2>/dev/null | head -20
  echo ""
  echo "## Recent commits"
  git log --oneline -5 2>/dev/null
  echo ""
  echo "## Critical CLAUDE.md rules"
  grep -iE '(ABSOLUTE|MUST NEVER|NEVER|CRITICAL|禁止)' CLAUDE.md 2>/dev/null | head -20
} > "$CHECKPOINT"

echo "📸 Pre-compact checkpoint saved to $CHECKPOINT" >&2
exit 0

Register in settings.json:

{
  "hooks": {
    "PreCompact": [{
      "hooks": [{ "type": "command", "command": "bash .claude/hooks/pre-compact-knowledge-save.sh" }]
    }]
  }
}

After compaction, Claude can read .claude/pre-compact-checkpoint.md to recover context.

2. Periodic CLAUDE.md re-injection (PostToolUse hook)

#!/bin/bash
# PostToolUse hook — reminds critical rules every 20 tool calls
set -euo pipefail

COUNTER_FILE="/tmp/claudemd-reminder-counter"
COUNT=$(cat "$COUNTER_FILE" 2>/dev/null || echo "0")
COUNT=$((COUNT + 1))
echo "$COUNT" > "$COUNTER_FILE"
[ $((COUNT % 20)) -ne 0 ] && exit 0

CLAUDEMD=""
for candidate in "CLAUDE.md" ".claude/CLAUDE.md" "../CLAUDE.md"; do
  [ -f "$candidate" ] && CLAUDEMD="$candidate" && break
done
[ -z "$CLAUDEMD" ] && exit 0

echo "⚡ CLAUDE.md critical rules reminder (tool call #${COUNT}):" >&2
grep -iE '(ABSOLUTE|MUST NEVER|NEVER|CRITICAL|禁止)' "$CLAUDEMD" 2>/dev/null | head -10 | while read -r line; do
  echo "  → $line" >&2
done
exit 0

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.