Skip to content

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

Closed as not planned

Description

@OWT-GwanHeeCho

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

  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

Activity

  1. rccnw commented on Jan 21, 2026

    @rccnw

    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.

  2. mark-hubers commented on Jan 27, 2026

    @mark-hubers

    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.

  3. asvishnyakov commented on Jan 29, 2026

    @asvishnyakov

    Duplicate of #6354

  4. rstierli commented on Feb 3, 2026

    @rstierli

    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.

  5. kpconnell commented on Feb 4, 2026

    @kpconnell

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

  6. kpconnell commented on Feb 10, 2026

    @kpconnell

    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?

  7. junaidtitan commented on Feb 10, 2026

    @junaidtitan

    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.

  8. 11 remaining items

  9. VoxCore84 commented on Mar 27, 2026

    @VoxCore84

    +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)

  10. m13v commented on Mar 27, 2026

    @m13v

    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.

  11. yurukusa commented on Mar 29, 2026

    @yurukusa

    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.

  12. m13v commented on Mar 29, 2026

    @m13v

    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?

  13. junaidtitan commented on Apr 3, 2026

    @junaidtitan

    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.

  14. iLord-DEV commented on Apr 28, 2026

    @iLord-DEV

    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.

  15. mahdikayvan commented on May 8, 2026

    @mahdikayvan

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

  16. hifriendbot commented on May 8, 2026

    @hifriendbot
  17. hipvlady commented on May 17, 2026

    @hipvlady

    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.

  18. hipvlady commented on May 17, 2026

    @hipvlady

    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.

  19. github-actions commented on Jun 16, 2026

    @github-actions

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

  20. github-actions commented on Aug 19, 2026

    @github-actions

    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.

  21. locked as resolved and limited conversation to collaborators on Aug 19, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions