[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
- I asked Claude to update skill files after a work session
- My CLAUDE.md explicitly states: "Skills are managed per-project in
.claude/skills/(e.g.,ghcho_projects/.claude/skills/)" - After context compaction, Claude searched from workspace root (
E:\workspace) instead of project directory - Claude ran:
Globpattern: "**/.claude/skills/*.md"- found nothing - Claude ran:
Globpattern: ".claude/skills/*.md"- found nothing - When I asked "Did you not read CLAUDE.md?", Claude admitted: "I didn't read CLAUDE.md"
- I had to repeat the same question 10+ times before getting this honest answer
Expected Behavior
- CLAUDE.md instructions should ALWAYS be followed, even after context compaction
- Claude should have searched
ghcho_projects/.claude/skills/as explicitly instructed - Context compaction should NOT cause CLAUDE.md to be ignored
- 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
- Create a multi-project workspace (e.g., E:\workspace with subprojects)
- Add CLAUDE.md at workspace root with project-specific path instructions
- Example instruction: "Skills are managed per-project in
.claude/skills/(e.g.,ghcho_projects/.claude/skills/)" - Work in a long session until context compaction occurs
- Ask Claude to "update skill files" or similar task requiring CLAUDE.md path guidance
- 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:
- Exclude CLAUDE.md from compaction
- Force re-inject CLAUDE.md after compaction
- At minimum, warn users when compaction might affect instruction following
27 Comments
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.
Same issue here on Max 5x plan. After 11 compactions in a single session, Claude completely forgot project-specific rules from CLAUDE.md:
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.
Duplicate of #6354
Additional Examples - Same Issue
Adding more reproduction cases from extensive testing with hooks, CLAUDE.md, and
.claude/rules/files.Environment
Setup
We have comprehensive instruction loading:
CLAUDE.mdwith explicit rules.claude/rules/00-golden-rules.mdwith git workflowSESSION_MEMORY.mdfor context persistenceObserved 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:
Claude acknowledges seeing this, then proceeds to ignore the rules anyway.
Impact
Notes
+1 to prioritizing this - the instruction system is a core feature that doesn't work reliably.
We are experiencing this as well with CLAUDE.md. Long running conversations consistently lose the context of rules.
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?
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:
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.
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:
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:
pause_after_compactionfrom the API exposed in CLISee #9796 for full reproduction details and evidence.
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).
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."
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:
~/.claude/projects/) before compaction and extracts the current task, recent files, and key context into a cloud-stored summaryThe 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.
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_contextwas 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:
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.
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
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:
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.
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.
+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 aMEMORY.mdthat'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)
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.
After compaction, CLAUDE.md content is compressed or dropped from context. Hooks can re-inject your critical rules on every prompt:
For your specific case (skills managed per-project):
additionalContextfromUserPromptSubmithooks 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 2to block violations.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?
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 initWould be great to hear if this helps your CLAUDE.md rules stick after compaction.
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):
sshdirectly instead of documentedmake deploytarget — despitemake deploybeing explicitly listed in CLAUDE.mdgit checkouton content files — despite memory file explicitly saying "never touch content files"git pushwithout approval — despite CLAUDE.md saying "never commit/push without asking"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.
@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-thisconsult-brainOver 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.
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:
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 Readchecks whether you're operating against a stale CLAUDE.md. If so,additionalContextwarns, 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.
A simpler native solution exists for the specific failure mode here.
@phpmac just documented (in #59309) that SubagentStart + PreCompact hooks with
additionalContextcover 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.
Closing for now — inactive for too long. Please open a new issue if this is still relevant.