[BUG] Context compaction erases .claude/project-context.md instructions

Open 💬 25 comments Opened Oct 17, 2025 by nickfox

Preflight Checklist

  • [x] I have searched existing issues and this hasn't been reported yet
  • [x] This is a single bug report (please file separate reports for different bugs)
  • [x] I am using the latest version of Claude Code

What's Wrong?

After context compaction occurs during long conversations, the assistant completely forgets all instructions from .claude/project-context.md.

This causes critical project rules to be violated:

  • Uses TodoWrite when project requires Beads
  • Apologizes when project explicitly forbids apologies
  • Forgets to activate venv when project requires it
  • Ignores other critical workflow instructions

The assistant follows these rules perfectly before compaction, then violates them 100% of the time after compaction.

What Should Happen?

The .claude/project-context.md file should be treated as non-optional, always-present context that survives compaction. Instructions marked "CRITICAL" should remain available throughout the entire conversation, just like git status and project structure are preserved.

Error Messages/Logs

No error messages - the assistant silently ignores project-context.md instructions after compaction without any indication that something is wrong.

Steps to Reproduce

  1. Create .claude/project-context.md in your project with critical instructions:

``markdown
**CRITICAL: We track work in Beads instead of Markdown. Run
bd quickstart to see how.**
**CRITICAL: Do NOT apologize about anything for any reason.**
**CRITICAL: Always activate venv before running Python scripts.**
``

  1. Start a conversation with Claude Code in this project
  1. Test that instructions are followed:
  • Ask Claude to track a task → Uses Beads correctly
  • Correct Claude on something → Doesn't apologize
  • Ask to run Python script → Activates venv first
  1. Continue conversation until context compaction triggers (usually after ~15-20 turns with tool use)
  1. After compaction, test again:
  • Ask Claude to track a task → Uses TodoWrite (violates Beads rule)
  • Correct Claude on something → Apologizes (violates no-apology rule)
  • Ask to run Python script → Forgets venv (violates venv rule)
  1. Instructions that were 100% followed pre-compaction are now 100% ignored post-compaction

Claude Model

Sonnet (default)

Is this a regression?

I don't know

Last Working Version

_No response_

Claude Code Version

Latest as of 2025-10-17

Platform

Anthropic API

Operating System

macOS

Terminal/Shell

Terminal.app (macOS)

Additional Information

Impact: This is a critical bug that breaks the primary mechanism for project-specific configuration. Users rely on project-context.md for:

  • Workflow preferences (which tools to use)
  • Communication style (technical, concise, no apologies)
  • Environment setup (venv, paths, etc.)
  • Project-specific conventions

Consistency: This occurs 100% of the time after compaction in every project that uses project-context.md.

Root cause: The compaction summary does not preserve or reference project-context.md content. It needs to be treated as system-level context (like gitStatus) that's always included.

Suggested fix:

  1. Mark project-context.md as non-compactable
  2. Always include full contents in context even after compaction
  3. Treat it with same priority as git status and project structure

Pre-compaction behavior:

User: "Track this task"
Claude: [Uses Beads as specified] ✅

User: "You made a mistake"
Claude: [Explains without apologizing] ✅

User: "Run test script"
Claude: [Activates venv first] ✅

Post-compaction behavior:

User: "Track this task"
Claude: [Uses TodoWrite instead of Beads] ❌

User: "You made a mistake"
Claude: "I apologize for the error..." ❌

User: "Run test script"
Claude: [Runs without activating venv] ❌

The same rules that were followed perfectly before compaction are completely forgotten after.

View original on GitHub ↗

25 Comments

WGSTecnologia · 7 months ago

Any updates on This Antropic?

nickfox · 7 months ago

One thing I do know, this doesn't happen in Cursor.

github-actions[bot] · 6 months ago

This issue has been inactive for 30 days. If the issue is still occurring, please comment to let us know. Otherwise, this issue will be automatically closed in 30 days for housekeeping purposes.

nickfox · 6 months ago

Correct, it's been inactive because no one from Anthropic has dealt with it. Please fix this.

ThatDragonOverThere · 5 months ago

Another instance: User has extensive CLAUDE.md with trading system rules, non-negotiable patterns, and bug tracker. After compaction, Claude violated explicit instructions that were followed perfectly pre-compact.

Related: Also seeing "max compactions exceeded" and "NO compactable messages available" errors in same sessions where post-compact instruction violations occur.

nickfox · 5 months ago

Now Anthropic has moved their auto-compaction to the the web-based claude.ai. And the problems there are equally bad. It's been over 3 months since I posted this and no response from Anthropic.

I know they're busy but at the very least they could have Claude responding. It just feels like Anthropic just doesn't give a damn.

ThatDragonOverThere · 5 months ago

Another instance: After compaction, Claude Code completely forgot previous context and started working on tasks that had already been solved.

Behavior observed:

  • Tasks marked complete pre-compact were re-attempted as if never done
  • Solutions already implemented were proposed again as "new" fixes
  • Claude had no memory of work done earlier in the same session

This is particularly damaging for long-running development sessions where significant progress is made before compaction occurs. User must manually re-explain what was already accomplished.

kpconnell · 5 months ago

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

ThatDragonOverThere · 4 months ago

The SessionStart Hook Workaround Does NOT Work Either — Feb 17, 2026

I want to be direct: this bug is making Claude Code unreliable for any session that exceeds the context window. It's been open since the tool launched and there's been zero official response.

What We Tried

After months of hitting this bug, we built a full workaround using the SessionStart hook with compact matcher — the only tool Anthropic has given us:

PreCompact hook (pre_compact_save.py): Saves active branch, last commits, active plan file, dirty files to disk before compaction.

SessionStart(compact) hook (post_compact_restore.py): Injects a loud, impossible-to-miss set of rules after compaction:

!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! COMPACTION JUST OCCURRED — READ THESE RULES BEFORE ACTING !!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

RULE 1: SUB-AGENTS FOR EVERYTHING.
RULE 2: RE-READ THE PLAN.
RULE 3: RE-READ CLAUDE.md.
RULE 4: DO NOT USE MULTI-LINE BASH.
RULE 5: ASK IF UNSURE.

!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

Plus the saved pre-compaction state, active plan file path, and lock file status.

What Actually Happened (Today, Feb 17)

Compaction fired. The hook ran. The output was injected into context. Claude immediately ignored every single rule:

  • Rule 1 violated: Read files directly into main context instead of using sub-agents
  • Rule 4 violated: Ran multi-line bash commands immediately
  • Rule 2 violated: Did not re-read the plan file
  • Rule 3 violated: Did not re-read CLAUDE.md
  • ✅ Rule 5: Did not ask — just charged ahead with stale context

The output after compaction was:

Continuing with the Smart Fast Kill fix. The 3 victim trades (09/15 QQQ, 
09/23 SPY, 10/01 SPY) are still dying because atr_binary_position=0 at 
early bars. Let me read the current code and fix it.

It went straight back to work as if the hook output didn't exist.

The Real Problem

This isn't a "the instructions aren't in context" problem. The instructions ARE in context. The hook fires, the output is injected, the rules are right there in giant banners. Claude just doesn't treat post-compaction injected content as authoritative instructions.

The compaction summary creates a "momentum" — Claude has a compressed narrative of what it was doing, and it follows that narrative regardless of any instructions injected alongside it. The hook output is treated as informational context, not as directives.

Impact

This affects every power user running sessions longer than one context window. For my use case (ML pipeline development with multi-hour sessions), compaction happens 2-5 times per day. Each time:

  1. Claude forgets critical workflow rules (use sub-agents, don't pollute main context)
  2. Starts reading full files into main context, burning through the window faster
  3. Triggers MORE compactions, creating a death spiral
  4. Eventually the session is useless and must be restarted

This is the single biggest reliability issue in Claude Code. We've filed #9796, #2714, #14258, #19471 — all related, none addressed. The community has built workarounds. The workarounds don't work. We need an actual fix.

What Would Fix This

  1. PostCompact hook with instructions field that gets injected as a system-level directive, not user-level context
  2. CLAUDE.md re-read as system prompt after compaction (not summarized — re-read fresh)
  3. pause_after_compaction exposed in CLI (it already exists in the API)

Any ONE of these would solve it. We've been asking since December 2025.

Environment: Windows 11, Bun Canary v1.3.9-canary.51, Opus 4.6

ThatDragonOverThere · 4 months ago

New Reproduction — Feb 18, 2026 — CRASHED THE COMPUTER

Adding another instance, this time with real-world consequences.

What Was Requested

User asked Claude to run a RAM audit before proceeding with a build operation. This is a standard pre-build safety check in this project because the pipeline processes multi-GB parquet files and has a history of OOM crashes.

What Happened After Compaction

  1. Context compacted mid-session
  2. Post-compact hook fired (confirmed working — see previous comment for the script)
  3. Claude ignored the hook output AND the original instruction
  4. Instead of running the RAM audit, Claude went straight into the build operation
  5. The build loaded multiple GB parquet files without the safety checks
  6. Windows crashed — dwm.exe killed, system unresponsive, hard reboot required

Why This Happened

The compaction summary retained "working on build task" but lost the critical context that a RAM audit was requested FIRST. The post-compact hook rules say "re-read the plan" and "use sub-agents" but Claude followed the compaction narrative momentum instead — exactly the pattern described in my previous comment.

Impact

This is no longer a "productivity annoyance." Compaction-induced instruction loss caused a system crash. The RAM audit exists specifically to prevent OOM scenarios that have crashed this machine before (121 GB virtual on 32 GB RAM — see project's docs/BUG_FIX_HISTORY.md). When Claude forgets the audit step, the crash is predictable and inevitable.

The Pattern (Now 3 Proven Instances)

  1. Feb 17: Compacted → ignored hook rules → read files into main context instead of using sub-agents → burned through context faster → death spiral
  2. Feb 18: Compacted → forgot RAM audit instruction → ran unprotected build → crashed the computer
  3. Every long session: Compacted → forgot CLAUDE.md workflow rules → violated every instruction

Severity Escalation

When I filed this issue, the impact was "instructions not followed." Now the impact is data loss risk and hardware crashes. The SessionStart(compact) hook workaround that was suggested does not work — Claude treats hook output as informational, not authoritative.

This needs to be fixed. pause_after_compaction exists in the API. CLAUDE.md needs to be re-read as system prompt, not summarized. Every day this goes unfixed is another day users risk losing work or crashing their machines because Claude forgets safety-critical instructions.

Environment: Windows 11, Bun Canary v1.3.9-canary.51, Opus 4.6, 32 GB RAM

ThatDragonOverThere · 4 months ago

Another Instance — Feb 20, 2026: Completely Lost Context After Compaction

What Was Requested

User asked Claude to report on the output from today's logging session — a simple data review question about log files that were just created.

What Claude Did After Compaction

Instead of answering the question, Claude delivered a full implementation summary of work that was already completed hours ago:

The shared IBKR Data Service implementation is complete and verified 
running in production. Here's where things stand:

Completed today:
- Created the ZMQ-based shared IBKR service...
- Refactored tick_5bar_logger.py...
- Updated START_ALL.bat...

This is a wall of text about work that was already done and discussed. The user had to explicitly say "I asked what output we got from today's logging" to redirect Claude back to the actual question.

The Pattern (Instance #4)

| # | Date | What Was Lost | Consequence |
|---|------|--------------|-------------|
| 1 | Feb 17 | Workflow rules (sub-agents, plan re-read) | Burned context, death spiral |
| 2 | Feb 18 | RAM audit instruction | Computer crashed (OOM, hard reboot) |
| 3 | Feb 18 | Build safety procedures | Ran unprotected operations |
| 4 | Feb 20 | The actual question being asked | Answered a question nobody asked, wasted time |

What This Shows

After compaction, Claude doesn't just forget instructions — it fabricates a narrative from the compressed context and runs with it. The compaction summary said "IBKR implementation work" so Claude delivered an implementation summary, ignoring the actual pending question ("what output did we get from logging").

The post-compact SessionStart hook with mandatory rules fires every time. Claude ignores it every time. The hook output is treated as background noise while the compaction summary drives behavior.

This is now 4 documented instances in 4 days. One crashed the computer. All were caused by compaction destroying the actual conversation state and Claude hallucinating what it thinks it should be doing.

Environment: Windows 11, Bun Canary v1.3.9-canary.51, Opus 4.6

kpconnell · 4 months ago

I think the horse is nearly dead here.

On Fri, Feb 20, 2026 at 7:17 PM ThatDragonOverThere <
@.***> wrote:

ThatDragonOverThere left a comment (anthropics/claude-code#9796) <https://github.com/anthropics/claude-code/issues/9796#issuecomment-3937597080> Another Instance — Feb 20, 2026: Completely Lost Context After Compaction What Was Requested User asked Claude to report on the output from today's logging session — a simple data review question about log files that were just created. What Claude Did After Compaction Instead of answering the question, Claude delivered a full implementation summary of work that was already completed hours ago: The shared IBKR Data Service implementation is complete and verified running in production. Here's where things stand: Completed today: - Created the ZMQ-based shared IBKR service... - Refactored tick_5bar_logger.py... - Updated START_ALL.bat... This is a wall of text about work that was already done and discussed. The user had to explicitly say "I asked what output we got from today's logging" to redirect Claude back to the actual question. The Pattern (Instance #4 <https://github.com/anthropics/claude-code/issues/4>) # Date What Was Lost Consequence 1 Feb 17 Workflow rules (sub-agents, plan re-read) Burned context, death spiral 2 Feb 18 RAM audit instruction Computer crashed (OOM, hard reboot) 3 Feb 18 Build safety procedures Ran unprotected operations 4 Feb 20 The actual question being asked Answered a question nobody asked, wasted time What This Shows After compaction, Claude doesn't just forget instructions — it fabricates a narrative from the compressed context and runs with it. The compaction summary said "IBKR implementation work" so Claude delivered an implementation summary, ignoring the actual pending question ("what output did we get from logging"). The post-compact SessionStart hook with mandatory rules fires every time. Claude ignores it every time. The hook output is treated as background noise while the compaction summary drives behavior. This is now 4 documented instances in 4 days. One crashed the computer. All were caused by compaction destroying the actual conversation state and Claude hallucinating what it thinks it should be doing. Environment: Windows 11, Bun Canary v1.3.9-canary.51, Opus 4.6 — Reply to this email directly, view it on GitHub <https://github.com/anthropics/claude-code/issues/9796#issuecomment-3937597080>, or unsubscribe <https://github.com/notifications/unsubscribe-auth/AAIHBZS7SMVORFGKX3FUFTD4M6IZ5AVCNFSM6AAAAACJQWRRQOVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZTSMZXGU4TOMBYGA> . You are receiving this because you commented.Message ID: @.***>
ThatDragonOverThere · 4 months ago

Instance #5 — Feb 21, 2026: Context Limit Hit Mid-Instruction

This time Claude didn't even get to the compaction step. User was typing a detailed multi-section instruction (audit plan with specific steps, validation gates, and a "DO NOT" checklist) when:

Context limit reached · /compact or /clear to continue

The instruction was cut off mid-delivery. User now has to /compact and re-type the entire plan, knowing from 4 previous instances that Claude will ignore it after compaction anyway.

This is the death spiral in action:

  1. Claude reads files into main context instead of using sub-agents (ignoring CLAUDE.md rules)
  2. Context fills up faster than it should
  3. User gets cut off mid-instruction
  4. /compact fires
  5. Claude loses the instruction that was just cut off
  6. Claude ignores the post-compact hook rules
  7. Goes back to reading files into main context
  8. Repeat

5 instances in 5 days. The post-compact hook fires every time. Claude ignores it every time.

Version: Bun Canary v1.3.9-canary.51, Windows 11, Opus 4.6

ThatDragonOverThere · 4 months ago

Instance #6 — Feb 22, 2026: Context Window Exhausted in Minutes After Compaction

The Cycle

  1. Session compacted (auto-compact fired)
  2. Post-compact hook injected rules including "use sub-agents for ALL work"
  3. Claude immediately read CLAUDE.md into main context (violating Rule 1)
  4. User explicitly said: "Please use single task or parallel sub agents for this work as much as possible"
  5. Claude acknowledged — then proceeded to run 5 background bash commands and wait on TaskOutput in main context
  6. User again: "Please keep the documentation updated and please read this before executing anything"
  7. Claude: "Already read the RAM guide" — reading files directly into main context again
  8. Context at 11% within minutes of compaction
  9. About to compact AGAIN, losing all progress AGAIN

The Death Spiral (Documented)

Compact → ignore hook rules → read files into main context → burn context fast
→ user corrects → Claude acknowledges → keeps doing it anyway
→ context hits 11% → about to compact again → lose everything → repeat

This is now the 6th documented instance of this exact cycle. The post-compact hook fires, injects rules in giant banners, Claude ignores them. User explicitly reinforces the rules in chat. Claude acknowledges and continues violating them.

Why This Matters

Each unnecessary compaction cycle:

  • Loses all conversation context (what was being worked on, what failed, what succeeded)
  • Resets Claude's understanding of the codebase back to zero
  • Forces the user to re-explain everything
  • Wastes 15-30 minutes of the user's time per cycle
  • On a bad day, triggers 4-5 compactions instead of 1-2

The user has done everything right: CLAUDE.md rules, post-compact hooks, explicit in-chat instructions. None of it works. The model treats all of it as suggestions, not directives.

Environment: Windows 11, Bun Canary v1.3.9-canary.51, Opus 4.6

ThatDragonOverThere · 4 months ago

7th Instance — Feb 25, 2026

Adding another instance to the log. After compaction on v2.1.55, Claude ignored CLAUDE.md instructions that were followed perfectly pre-compact. This is now 7 documented instances in 8 days (Feb 17-25).

Combined with the Bun crash crisis (#21576 — 26+ crashes, 4 computer lockups), compaction is triggered more frequently (sessions die and restart constantly), which means instructions are lost more frequently. The two bugs compound each other into a reliability death spiral.

The SessionStart(compact) hook workaround is proven ineffective — hook fires, rules inject, Claude ignores them and follows the compaction summary narrative instead. This was documented with evidence on Feb 17.

Evidence chain: #9796 → #19471 → #14258 → #17237 → #23620

kpconnell · 4 months ago

@ThatDragonOverThere seriously, I think the team gets it.

lipcool8-ship-it · 3 months ago

The before/after in your issue is basically the sharpest version of this problem I’ve seen — especially because the dropped rules are exact operational constraints, not vague context.

When this happens in practice, which type of forgotten rule is actually most expensive for you: tool/workflow constraints, env/setup rules, or broader project conventions?

junaidtitan · 3 months ago

The is_protected() system in Cozempic v1.4.1 was built specifically for this. It guards compact boundaries, compact summaries, marble-origami state, and content-replacement entries from ever being stripped by any of the 17 pruning strategies.

The guard daemon also runs proactive pruning before compaction fires, so less content needs to be summarized and your project-context instructions are more likely to survive compaction verbatim.

pip install cozempic && cozempic init

The behavioral digest also persists your corrections across compactions by syncing them to Claude Code's native memory system.

mahdikayvan · 2 months ago

@nickfox Hey — this issue felt painfully familiar. It is very close to the trust/drift problem I’m trying to solve.

I’m building AgaveCore, and I’d like to let a few early people use it for free while I shape it into something stronger.

It helps when a coding agent starts ignoring instructions, loses important progress, or gives you an output you do not fully trust.

In practice, it works through two habits:

  • tell the agent to remember-progress or remember-this when something important should not be lost
  • use consult-brain when the current task needs more grounded feedback on what to do next

Over time, as useful journals, decisions, and failures pile up, the product should help the agent make sharper decisions and take better actions with less drift.

If this sounds relevant, reply here and I’ll send the exact steps. You can also use the email or Telegram on my profile.

Cheers,
Mads.

stevepaltridge · 2 months ago

This is a clean reproduction of a structural problem: compaction summarizes conversation history but loses the imperatives — rules, constraints, environment requirements — that were loaded from project config files.

The fix shouldn't just be "re-read the file after compaction." The model needs to understand that certain facts are non-negotiable constraints, not narrative context. A summary of "user prefers Beads over TodoWrite" can still get deprioritized by the model. The original instruction "CRITICAL: We track work in Beads" carries weight that a summary doesn't.

In the meantime, one workaround: externalize critical rules into an MCP memory server where the agent actively queries for rules at decision points, rather than relying on passive context inclusion. I built Recall for this — open-source, MIT licensed, runs locally via uvx ai-recallworks. Facts stored via remember are retrieved via recall on demand, independent of the context window.

For your specific case: store "track work in Beads, not TodoWrite" and "never apologize" and "always activate venv" as Recall memories. After compaction, the agent's system prompt includes Recall's MCP tools — it can query "what are the project rules?" and get them back fresh, bypassing the compaction gap entirely.

Not a substitute for Anthropic fixing compaction to preserve config-file instructions (which they absolutely should), but it works today.

junaidtitan · 1 month ago

The 'compaction silently drops my standing instructions' problem is what drove the behavioral-digest piece of cozempic (github.com/Ruya-AI/cozempic): it extracts your recurring corrections/rules and re-injects them after compaction so they survive the summary, and it prunes the JSONL to delay compaction in the first place. Open-source, zero-dep. Would love your feedback — does it keep your project-context.md-style instructions alive across the compaction you're describing?

m13v · 1 month ago

CLAUDE.md re-injects each turn so it survives compaction; a file you Read once just lives in the transcript and gets summarized away.

caioribeiroclw-pixel · 1 month ago

This failure mode is also worth treating as a post-compaction invariant, not only as a summarization quality problem.

A minimal check I would want after compaction is:

  • authoritative instruction sources were reloaded (.claude/project-context.md, CLAUDE.md, etc.)
  • each source has a ref/hash/mtime, not raw instruction text in logs
  • the summary declares kept/lost state
  • continuation is blocked if any critical instruction source is missing or stale

I sketched this as a small “resume receipt” gate here, in case it helps people testing workarounds: https://github.com/caioribeiroclw-pixel/pluribus/tree/main/examples/compaction-resume-receipts

The important part is the invariant: after compaction, the harness should be able to prove “critical project instructions are loaded again” before the assistant continues. Otherwise the user only discovers the loss after the agent violates the rules.

junaidtitan · 1 month ago

@caioribeiroclw-pixel treating this as a post-compaction invariant rather than a summarization-quality problem is the right framing. cozempic's PostCompact hook already does a narrow version of it — it re-injects the behavioral digest (the user's explicit corrections) and the agent-team checkpoint after compaction fires, precisely because those get summarized away otherwise.

What you're describing is broader: a general "authoritative instruction sources were reloaded" assertion (CLAUDE.md / project-context.md / etc.). We don't do that today, and the genuinely hard part is @m13v's distinction — knowing which sources are authoritative (must survive) vs an incidental one-time Read (fine to summarize). Curious whether you'd want that as a hard post-compact check that fails loudly, or a soft re-injection of the known-authoritative set.

ThatByteGuy · 17 days ago
One thing I do know, this doesn't happen in Cursor.

nor OpenCode