[BUG] Context compaction erases .claude/project-context.md instructions
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
- Create
.claude/project-context.mdin your project with critical instructions:
``markdownbd quickstart
**CRITICAL: We track work in Beads instead of Markdown. Run to see how.**``
**CRITICAL: Do NOT apologize about anything for any reason.**
**CRITICAL: Always activate venv before running Python scripts.**
- Start a conversation with Claude Code in this project
- 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
- Continue conversation until context compaction triggers (usually after ~15-20 turns with tool use)
- 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)
- 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:
- Mark project-context.md as non-compactable
- Always include full contents in context even after compaction
- 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.
25 Comments
Any updates on This Antropic?
One thing I do know, this doesn't happen in Cursor.
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.
Correct, it's been inactive because no one from Anthropic has dealt with it. Please fix this.
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.
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.
Another instance: After compaction, Claude Code completely forgot previous context and started working on tasks that had already been solved.
Behavior observed:
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.
We are experiencing this as well with CLAUDE.md. Long running conversations consistently lose the context of rules.
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
compactmatcher — 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: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:
The output after compaction was:
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:
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
instructionsfield that gets injected as a system-level directive, not user-level contextpause_after_compactionexposed 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
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
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)
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_compactionexists 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
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:
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
I think the horse is nearly dead here.
On Fri, Feb 20, 2026 at 7:17 PM ThatDragonOverThere <
@.***> wrote:
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:
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:
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
Instance #6 — Feb 22, 2026: Context Window Exhausted in Minutes After Compaction
The Cycle
The Death Spiral (Documented)
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:
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
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
@ThatDragonOverThere seriously, I think the team gets it.
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?
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 initThe behavioral digest also persists your corrections across compactions by syncing them to Claude Code's native memory system.
@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:
remember-progressorremember-thiswhen something important should not be lostconsult-brainwhen the current task needs more grounded feedback on what to do nextOver 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.
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 viarememberare retrieved viarecallon 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.
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?CLAUDE.md re-injects each turn so it survives compaction; a file you Read once just lives in the transcript and gets summarized away.
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:
.claude/project-context.md,CLAUDE.md, etc.)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.
@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.
nor OpenCode