[BUG] CLAUDE.md instructions completely ignored after context compaction

Resolved 💬 27 comments Opened Jan 20, 2026 by OWT-GwanHeeCho Closed Jun 16, 2026

Preflight Checklist

  • [x] I have searched existing issues for similar behavior reports
  • [x] This report does NOT contain sensitive information (API keys, passwords, etc.)

Type of Behavior Issue

Claude ignored my instructions or configuration

What You Asked Claude to Do

I asked: "Update the skill files with lessons learned from this work"

My CLAUDE.md contains explicit instruction:
"Note: Skills are managed per-project in .claude/skills/ (e.g., ghcho_projects/.claude/skills/)"

What Claude Actually Did

  1. I asked Claude to update skill files after a work session
  2. My CLAUDE.md explicitly states: "Skills are managed per-project in .claude/skills/ (e.g., ghcho_projects/.claude/skills/)"
  3. After context compaction, Claude searched from workspace root (E:\workspace) instead of project directory
  4. Claude ran: Globpattern: "**/.claude/skills/*.md" - found nothing
  5. Claude ran: Globpattern: ".claude/skills/*.md" - found nothing
  6. When I asked "Did you not read CLAUDE.md?", Claude admitted: "I didn't read CLAUDE.md"
  7. I had to repeat the same question 10+ times before getting this honest answer

Expected Behavior

  1. CLAUDE.md instructions should ALWAYS be followed, even after context compaction
  2. Claude should have searched ghcho_projects/.claude/skills/ as explicitly instructed
  3. Context compaction should NOT cause CLAUDE.md to be ignored
  4. If Claude cannot follow CLAUDE.md after compaction, it should warn the user

Files Affected

E:\workspace\CLAUDE.md (contains the ignored instruction)
E:\workspace\ghcho_projects\.claude\skills\protocol-definitions\SKILL.md (file Claude should have found)

Permission Mode

Accept Edits was OFF (manual approval required)

Can You Reproduce This?

Sometimes (intermittent)

Steps to Reproduce

  1. Create a multi-project workspace (e.g., E:\workspace with subprojects)
  2. Add CLAUDE.md at workspace root with project-specific path instructions
  3. Example instruction: "Skills are managed per-project in .claude/skills/ (e.g., ghcho_projects/.claude/skills/)"
  4. Work in a long session until context compaction occurs
  5. Ask Claude to "update skill files" or similar task requiring CLAUDE.md path guidance
  6. Claude will ignore CLAUDE.md and search from workspace root instead of specified project path

Claude Model

Opus

Relevant Conversation

Me: "Update the skill files with lessons learned from this work"

Claude: 
Globpattern: "**/.claude/skills/*.md"
No files found
Globpattern: ".claude/skills/*.md"  
No files found

Me: "Did you not read CLAUDE.md?"

Claude: "I didn't read CLAUDE.md. I made a mistake - I should have checked CLAUDE.md Line 75 which states skills are at `ghcho_projects/.claude/skills/`"

Me: "Why didn't you read CLAUDE.md that's in the system prompt?"

Claude: "I didn't read the CLAUDE.md content included in the system prompt. I skipped it and ran the Glob command directly."

Impact

Critical - Data loss or corrupted project

Claude Code Version

2.0.76 (Claude Code)

Platform

Anthropic API

Additional Context

Pattern observed:

  • This happens specifically AFTER context compaction in long sessions
  • Before compaction, CLAUDE.md instructions are followed correctly
  • After compaction, CLAUDE.md is completely ignored without warning

Project structure that triggers this:

  • Multi-project workspace (E:\workspace as root)
  • CLAUDE.md at workspace root with project-specific path rules
  • Subprojects with their own .claude/skills/ directories

Critical concern:
The whole point of CLAUDE.md is to provide persistent instructions. If context compaction can silently invalidate these instructions, users cannot trust CLAUDE.md for anything important.

Suggested fix:

  1. Exclude CLAUDE.md from compaction
  2. Force re-inject CLAUDE.md after compaction
  3. At minimum, warn users when compaction might affect instruction following

View original on GitHub ↗

27 Comments

rccnw · 5 months ago

omg, I just realized this is why despite ridiculous levels of effort to provide guidance and memory, CC keeps violating every rule I have, I really try to avoid compaction, but it seems it is happening sooner lately.

mark-hubers · 5 months ago

Same issue here on Max 5x plan. After 11 compactions in a single session, Claude completely forgot project-specific rules from CLAUDE.md:

  • DRY architecture (use shared query functions, not inline SQL)
  • Use Python instead of Bash for new scripts
  • Always ask before creating files

These rules are clearly documented in the project's CLAUDE.md, but after compaction Claude started creating new scripts that violated all of them. When asked "why did you forget these rules?" Claude acknowledged the compaction had lost the context.

Suggested fix: CLAUDE.md files should be re-injected into context after every compaction, not just at session start. The whole point of CLAUDE.md is to maintain project rules - losing them defeats the purpose.

asvishnyakov · 5 months ago

Duplicate of #6354

rstierli · 5 months ago

Additional Examples - Same Issue

Adding more reproduction cases from extensive testing with hooks, CLAUDE.md, and .claude/rules/ files.

Environment

  • Claude Code: 1.0.29 / 2.1.x
  • Model: claude-opus-4-5-20251101
  • OS: macOS + Linux (prod servers)

Setup

We have comprehensive instruction loading:

  • CLAUDE.md with explicit rules
  • .claude/rules/00-golden-rules.md with git workflow
  • Session start hook that confirms: "✓ Rules loaded"
  • SESSION_MEMORY.md for context persistence

Observed Violations (same session, rules confirmed loaded)

| Rule in Context | What Claude Did |
|-----------------|-----------------|
| "ALWAYS git pull before commit" | Committed first → push rejected → then pulled |
| "Use Notion for task tracking, set Agent field" | Created local TODO.md file instead |
| "Check SESSION_MEMORY.md for prior context" | Forgot QMD was set up on server (checked yesterday) |
| "All agents use shared Notion database" | Needed 3 reminders before following |

Key Observation

The hook output shows rules ARE loaded:

=== Batcave Configuration Loaded ===
✓ CLAUDE.md loaded
✓ Rules: 3 files from .claude/rules/
🧠 THINK → ❓ ASK → ▶️ RUN

Claude acknowledges seeing this, then proceeds to ignore the rules anyway.

Impact

  • Cannot rely on CLAUDE.md / rules for workflow enforcement
  • Users must manually catch every violation
  • Defeats the purpose of the instruction injection system

Notes

  • This is NOT a context length issue - happens in fresh sessions
  • This is NOT a formatting issue - rules are clear and specific
  • The rules are IN context, acknowledged, but not referenced before actions

+1 to prioritizing this - the instruction system is a core feature that doesn't work reliably.

kpconnell · 5 months ago

We are experiencing this as well with CLAUDE.md. Long running conversations consistently lose the context of rules.

kpconnell · 5 months ago

It appears tens if not hundreds of millions of dollars has been spent on the upgrade to Claude Opus 4.6.... but I'm not seeing a feature around " actually follow stated rules " ?

Curious to hear from an actual product manager how you might spend your resources?

junaidtitan · 5 months ago

This is a frustrating one — CLAUDE.md instructions getting dropped after compaction. We've been tackling this with Cozempic.

The root cause is that context bloat from redundant system-reminders and oversized tool outputs pushes out the important stuff (like CLAUDE.md instructions) during compaction. Cozempic attacks this from multiple angles:

  1. System-reminder deduplication — Removes duplicate system-reminder blocks that accumulate during long sessions, freeing space for what matters
  2. Tool-output trimming — Caps oversized tool results that eat context budget
  3. Guard daemon — Monitors context usage and checkpoints before compaction triggers
  4. PreCompact hook — Fires a cleanup pass right before compaction, giving the compactor cleaner input to work with
pip install cozempic
cozempic init   # auto-wires hooks + guard daemon

The idea is: if compaction has less noise to process, it preserves more of the meaningful context (including your CLAUDE.md instructions).

Would love for you to try it on your next long session and see if CLAUDE.md instructions survive compaction better. Let us know either way — if it doesn't help, we'll look into what else is getting dropped.

ThatDragonOverThere · 4 months ago

SessionStart(compact) Hook Workaround Confirmed INEFFECTIVE — Feb 17, 2026

Detailed write-up posted on #9796. Summary:

We built a complete PreCompact + SessionStart(compact) hook pipeline that:

  1. Saves session state before compaction
  2. Injects loud, banner-formatted mandatory rules after compaction
  3. Tells Claude to re-read CLAUDE.md and the active plan file via sub-agents

Result: Claude ignores all of it. The compaction summary creates a narrative momentum that overrides any injected instructions. Claude goes straight back to work using the compressed summary, violating every rule in the hook output.

This confirms the bug is NOT "CLAUDE.md isn't in context after compaction." The instructions ARE in context (via the hook). Claude just doesn't follow them. The compaction summary is treated as higher-priority than fresh injected directives.

The only real fix is one of:

  1. CLAUDE.md re-read as system prompt (not user context) after compaction
  2. pause_after_compaction from the API exposed in CLI
  3. PostCompact hook with system-level instruction injection

See #9796 for full reproduction details and evidence.

ThatDragonOverThere · 4 months ago

Severity Escalation — Feb 18, 2026: Compaction-induced instruction loss crashed the computer

Adding to the evidence chain from #9796.

User instructed Claude to run a RAM safety audit before a build operation. Compaction occurred. Claude forgot the audit instruction and ran the build unprotected. The build loaded multi-GB parquet files into 32 GB RAM without safety checks, triggering an OOM that killed dwm.exe and required a hard reboot.

The RAM audit was a CLAUDE.md-documented safety procedure. After compaction, Claude ignored both CLAUDE.md AND the SessionStart(compact) hook output that explicitly says to re-read CLAUDE.md.

This is the same root cause as this issue — CLAUDE.md instructions ignored after compaction — but the consequence has escalated from "wrong workflow" to "system crash with potential data loss."

Full details in #9796 (latest comment).

weilhalt · 4 months ago

Same here, I created even a claude_fails.md that claude fllls by itself with piles of shame... but hey, it already says something like: "But before I say 'no problem' and end up with fail #17, let me honestly check the actual effort required."

hifriendbot · 4 months ago

I ran into this exact problem — CLAUDE.md rules getting silently dropped after compaction. The SessionStart hook approach didn't reliably fix it for me either.

What ended up working was a two-hook approach:

  1. PreCompact hook — reads the session transcript (JSONL in ~/.claude/projects/) before compaction and extracts the current task, recent files, and key context into a cloud-stored summary
  2. UserPromptSubmit hook — after compaction, detects the context reset and injects both project memories and the session summary back into the conversation

The key difference from re-reading CLAUDE.md is that this restores session-specific context (what you were working on, which files, what decisions were made) — not just static rules.

I packaged this into an MCP server called CogmemAi that handles the hooks automatically. Setup is npx cogmemai-mcp setup — it configures both hooks plus persistent memory with semantic search.

The hooks source is MIT-licensed if you want to adapt the approach for your own setup without using the full server.

weilhalt · 4 months ago

Still very much active. @ThatDragonOverThere's severity escalation (compaction-induced OOM crash) confirms this is a safety issue, not just a workflow inconvenience.

Our current workaround is a session-gate policy: a PreToolUse hook that blocks all code edits unless session_context was called today (verified via changelog). This forces the model to re-read project state before any work — but it doesn't solve compaction mid-session losing rules.

The core finding from @ThatDragonOverThere is critical: the compaction summary creates "narrative momentum" that overrides freshly injected instructions. This means no hook-based workaround can fully fix this — the fix must be at the compaction level itself.

Suggested priorities:

  1. CLAUDE.md re-injected as system-level context after compaction (not user context)
  2. PostCompact hook type with system-level instruction injection
  3. At minimum: a warning when compaction drops instruction-carrying messages
m13v · 4 months ago

this happens to us regularly in long automated sessions. the compaction process seems to summarize CLAUDE.md instructions into a lossy compressed form that loses the specificity of the rules. we noticed it particularly with rules that have conditional logic like 'if X then do Y' - after compaction the model just does Y regardless. our workaround is keeping CLAUDE.md instructions short and absolute (no conditionals), and breaking long sessions into shorter ones with explicit state files so the fresh session re-reads the full CLAUDE.md.

m13v · 4 months ago

here's our CLAUDE.md that we've optimized for compaction survival - short, absolute rules with no conditionals: https://github.com/m13v/fazm/blob/main/CLAUDE.md - and the scheduled agent system where this matters most: https://github.com/m13v/tmux-background-agents/blob/main/SKILL.md

yurukusa · 3 months ago

Hooks survive compaction because they run at the process level, not in context. A PostToolUse hook can re-inject your most critical CLAUDE.md rules as warnings:

INPUT=$(cat)
COMMAND=$(echo "$INPUT" | jq -r '.tool_input.command // empty')
[ -z "$COMMAND" ] && exit 0
if echo "$COMMAND" | grep -qE '^\s*git\s+commit'; then
    LAST_TEST=$(stat -c %Y coverage/.last-run.json 2>/dev/null || echo 0)
    NOW=$(date +%s)
    (( LAST_TEST == 0 || NOW - LAST_TEST > 600 )) && \
        echo "REMINDER: CLAUDE.md requires running tests before committing" >&2
fi
if echo "$COMMAND" | grep -qE 'git\s+push.*(main|master)'; then
    echo "REMINDER: CLAUDE.md prohibits pushing to main directly" >&2
fi
if echo "$COMMAND" | grep -qE 'git\s+push.*--force'; then
    echo "REMINDER: CLAUDE.md prohibits force pushing" >&2
fi
exit 0

This doesn't block (exit 0) — it warns. The warning appears in Claude's context after every relevant command, even after compaction has stripped the original CLAUDE.md rules.
For harder enforcement (block instead of warn), use PreToolUse with exit 2.
For the "session-start workflow" rule (#37869), pair with a UserPromptSubmit hook that injects a reminder at the start of every user message.

m13v · 3 months ago

This is a solid pattern. Using PostToolUse hooks to re-inject critical rules means they survive regardless of what the model decides to keep during compaction.

The coverage freshness check is clever too - gating commits on whether tests actually ran recently rather than trusting the model's claim that "tests pass." We do something similar where the hook checks for a lockfile that our test runner creates, so the commit literally cannot happen if the test suite didn't execute in the last 10 minutes.

One addition that worked well for us: adding a PreToolUse hook on file writes that re-injects the project's coding conventions. Catches style drift before it hits disk rather than cleaning it up after.

VoxCore84 · 3 months ago

+1 — still reproducing on v2.1.85, Opus 4.6, Windows 11.

Our CLAUDE.md is ~300 lines with detailed rules (DESCRIBE tables before SQL, use Read instead of cat, multi-tab coordination protocol, completion verification requirements). These rules are reliably followed for the first ~30 minutes of a session. After compaction, compliance drops to roughly 50-60%. After a second compaction, it's closer to 20%.

The specific failure pattern: the model will reference a CLAUDE.md rule in its thinking (proving it was loaded), then violate that exact rule in the same response. This isn't "forgetting" — the instruction is in context but not being followed.

Our workaround: a memory/ directory with 27 persistent topic files that get re-read on demand, plus a MEMORY.md that's always loaded. This compensates for some compaction loss but doesn't solve the core problem — CLAUDE.md rules should be treated as immutable system instructions, not context that can be compressed away.

Cross-ref: #32659 (context amnesia in long sessions), #32290 (reads files but ignores instructions)

m13v · 3 months ago

Yeah the pattern you're describing is exactly what we see too. The model acknowledges the rule in its reasoning but then acts against it anyway. Almost like the compacted summary gets lower attention weight than the original instructions.

The 30-minute window tracks with our experience. We ended up restructuring our CLAUDE.md to front-load the most critical rules and use very short, imperative sentences. Redundancy helps too - restating key rules in slightly different forms so at least one survives compaction.

Still not a real fix though. The underlying issue is that compaction lossy-compresses the instructions and the model treats the compressed version as less authoritative.

yurukusa · 3 months ago

After compaction, CLAUDE.md content is compressed or dropped from context. Hooks can re-inject your critical rules on every prompt:

CLAUDE_MD=""
for path in "CLAUDE.md" ".claude/CLAUDE.md" "../CLAUDE.md"; do
    if [ -f "$path" ]; then
        CLAUDE_MD="$path"
        break
    fi
done
[ -z "$CLAUDE_MD" ] && exit 0
RULES=$(grep -iE '(MANDATORY|CRITICAL|MUST|NEVER|ALWAYS):' "$CLAUDE_MD" 2>/dev/null | head -10)
if [ -n "$RULES" ]; then
    ESCAPED=$(echo "$RULES" | jq -Rs .)
    echo "{\"hookSpecificOutput\":{\"additionalContext\":\"MANDATORY RULES (from CLAUDE.md — re-injected by hook):\\n$RULES\"}}"
fi
exit 0

For your specific case (skills managed per-project):

PROJECT_DIR=$(git rev-parse --show-toplevel 2>/dev/null || pwd)
PROJECT_NAME=$(basename "$PROJECT_DIR")
CONTEXT="Project-specific rules:
- Skills directory: $PROJECT_DIR/.claude/skills/
- Always search within $PROJECT_DIR, not workspace root
- After compaction, re-read CLAUDE.md if unsure about project conventions"
echo "{\"hookSpecificOutput\":{\"additionalContext\":\"$CONTEXT\"}}"
exit 0
{
  "hooks": {
    "UserPromptSubmit": [{
      "hooks": [{ "type": "command", "command": "bash ~/.claude/hooks/reinject-rules.sh" }]
    }]
  }
}

additionalContext from UserPromptSubmit hooks is injected into every prompt — including the first prompt after compaction. Unlike CLAUDE.md content which gets compressed during compaction, the hook re-injects fresh rules each time. The model always sees your mandatory rules, regardless of context window state.
For rules that need enforcement (not just reminders), combine with PreToolUse hooks that exit 2 to block violations.

m13v · 3 months ago

nice, this is a solid approach. we ended up doing something similar - a pre-prompt hook that greps the critical rules and re-injects them as a system prompt prefix. the head -10 cap is smart too, keeps the token budget predictable.

one thing we added was a hash check on CLAUDE.md so the hook only fires when the file actually changed, saves a few ms per turn in long sessions. curious if you've hit any issues with the escaped JSON getting too large when there are nested code blocks in the rules?

junaidtitan · 3 months ago

CLAUDE.md getting ignored after compaction is a known issue — compaction summarizes the conversation into prose, and behavioral instructions get diluted in the summary.

Cozempic v1.4.1 has a behavioral digest that directly addresses this. It extracts your corrections ("don't do X", "always use Y") from the session, persists them to disk, and syncs them to Claude Code's native memory system. Claude reads these as feedback memories on every turn — they survive compaction because they're on disk, not in the JSONL.

Explicit corrections like "don't add Co-Authored-By" activate immediately. The extraction is automatic via PreCompact and Stop hooks.

pip install cozempic && cozempic init

Would be great to hear if this helps your CLAUDE.md rules stick after compaction.

iLord-DEV · 2 months ago

Still happening as of 2026-04-28, Claude Code with Opus 4.6

This issue isn't limited to post-compaction. Today's session had zero compactions and the model still repeatedly violated rules defined in all three layers (global CLAUDE.md, project CLAUDE.md, and memory files):

  1. Used ssh directly instead of documented make deploy target — despite make deploy being explicitly listed in CLAUDE.md
  2. Attempted git checkout on content files — despite memory file explicitly saying "never touch content files"
  3. Ran git push without approval — despite CLAUDE.md saying "never commit/push without asking"
  4. Ran server commands without approval — despite bold NIEMALS (NEVER) rules

Each time the model acknowledged the violation, saved a "feedback memory" about it, then broke the next rule 2 minutes later. The memories and docs are clearly read but don't reliably influence behavior.

This suggests the problem isn't just compaction-related lossy compression — the model also deprioritizes CLAUDE.md instructions when it's in "task completion" mode, even with full context available.

Previously reported as #32543, closed as duplicate.

mahdikayvan · 2 months ago

@OWT-GwanHeeCho Hey — this issue looked very close to the kind of agent reliability problem I’m working on.

I’m building AgaveCore and giving a few early people free access while I tighten the pilot.

It helps when the agent forgets what mattered, drifts during longer work, or produces an output you do not fully trust.

The practical path is:

  • remember-progress / remember-this
  • consult-brain

Over time that memory pile should help the agent stay more grounded and avoid repeating the same mistakes.

If you want in, reply here and I’ll send the exact steps. Email and Telegram are on my profile too.

Cheers,
Mads.

hifriendbot · 2 months ago

CogmemAi has been learning from Claude Code’s mistakes for months now. This
is the way.

On Fri, May 8, 2026 at 4:18 AM Mads @.***> wrote:

mahdikayvan left a comment (anthropics/claude-code#19471) <https://github.com/anthropics/claude-code/issues/19471#issuecomment-4404860317> @OWT-GwanHeeCho <https://github.com/OWT-GwanHeeCho> Hey — this issue looked very close to the kind of agent reliability problem I’m working on. I’m building AgaveCore and giving a few early people free access while I tighten the pilot. It helps when the agent forgets what mattered, drifts during longer work, or produces an output you do not fully trust. The practical path is: - remember-progress / remember-this - consult-brain Over time that memory pile should help the agent stay more grounded and avoid repeating the same mistakes. If you want in, reply here and I’ll send the exact steps. Email and Telegram are on my profile too. Cheers, Mads. — Reply to this email directly, view it on GitHub <https://github.com/anthropics/claude-code/issues/19471#issuecomment-4404860317>, or unsubscribe <https://github.com/notifications/unsubscribe-auth/B6O5Q4WNHDHSDGOUZHHR2P34ZWJ5JAVCNFSM6AAAAACSIEIQ22VHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHM2DIMBUHA3DAMZRG4> . Triage notifications on the go with GitHub Mobile for iOS <https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675> or Android <https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub>. You are receiving this because you commented.Message ID: @.***>
hipvlady · 2 months ago

This is the post-compaction instruction loss documented in #59309. After context compaction, CLAUDE.md instructions appear to be deprioritized, even though the text is still in your context.

Root cause: Compaction is a checkpoint boundary that doesn't preserve rule priority. Rules survive as text but lose their effective weight.

Solution: An external coordination layer (not inside Claude Code) that tracks instruction-artifact versions and surfaces drift on every tool call. The mechanism is hook-based: PreToolUse Read checks whether you're operating against a stale CLAUDE.md. If so, additionalContext warns, and you typically re-read.

The key insight: the problem isn't that instructions disappear — it's that they're deprioritized post-compaction. Surfacing version drift on each tool call forces a re-read, keeping them visible throughout the session.

I'm implementing this in agent-coherence (private alpha). It's the canonical solution to this class of problem (stale rules post-compaction across many frameworks).

v0.1 releases soon. If you'd want early access, I can add you.

hipvlady · 1 month ago

A simpler native solution exists for the specific failure mode here.

@phpmac just documented (in #59309) that SubagentStart + PreCompact hooks with additionalContext cover the CLAUDE.md rule propagation case in ~40 lines of Python with no external dependencies — the hook fires at subagent spawn and before compaction, reads CLAUDE.md, and injects it as a system reminder. Verified working (subagent switched from grep to rg on spawn).

My earlier comment framed this as a state-coordination failure requiring a MESI coordinator. That was the wrong diagnosis. The root cause here is instruction-propagation (rule absent from subagent context), not state-coherence (concurrent sessions disagreeing on a shared file version). The hook approach is the right fix for this class of problem.

The MESI coordinator is relevant when CLAUDE.md itself changes mid-session and running subagents are still working from a stale injected snapshot — a version-divergence problem rather than a rule-absence one. Different failure mode.

Leaving this correction so the thread stays accurate.

github-actions[bot] · 29 days ago

Closing for now — inactive for too long. Please open a new issue if this is still relevant.