Repository navigation
[BUG] CLAUDE.md instructions completely ignored after context compaction #19471
Copy link
Copy link
Closed as not planned
Closed as not planned
Copy link
Labels
area:corearea:modelbugSomething isn't workingSomething isn't workinghas reproHas detailed reproduction stepsHas detailed reproduction stepsmemoryplatform:windowsIssue specifically occurs on WindowsIssue specifically occurs on WindowsstaleIssue is inactiveIssue is inactive
Description
Preflight Checklist
- I have searched existing issues for similar behavior reports
- 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
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
area:corearea:modelbugSomething isn't workingSomething isn't workinghas reproHas detailed reproduction stepsHas detailed reproduction stepsmemoryplatform:windowsIssue specifically occurs on WindowsIssue specifically occurs on WindowsstaleIssue is inactiveIssue is inactive
Activity
rccnw commentedon Jan 21, 2026
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 commentedon Jan 27, 2026
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.
asvishnyakov commentedon Jan 29, 2026
Duplicate of #6354
rstierli commentedon Feb 3, 2026
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)
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.
kpconnell commentedon Feb 4, 2026
We are experiencing this as well with CLAUDE.md. Long running conversations consistently lose the context of rules.
kpconnell commentedon Feb 10, 2026
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 commentedon Feb 10, 2026
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:
pip install cozempic cozempic init # auto-wires hooks + guard daemonThe 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.
11 remaining items
VoxCore84 commentedon Mar 27, 2026
+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)
m13v commentedon Mar 27, 2026
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 commentedon Mar 29, 2026
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):
{ "hooks": { "UserPromptSubmit": [{ "hooks": [{ "type": "command", "command": "bash ~/.claude/hooks/reinject-rules.sh" }] }] } }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.m13v commentedon Mar 29, 2026
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 commentedon Apr 3, 2026
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.
iLord-DEV commentedon Apr 28, 2026
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.
mahdikayvan commentedon May 8, 2026
@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.
hifriendbot commentedon May 8, 2026
hipvlady commentedon May 17, 2026
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.
hipvlady commentedon May 17, 2026
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.
github-actions commentedon Jun 16, 2026
Closing for now — inactive for too long. Please open a new issue if this is still relevant.
github-actions commentedon Aug 19, 2026
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.