claude-code icon indicating copy to clipboard operation
claude-code copied to clipboard

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

Open nickfox opened this issue 4 months ago • 4 comments

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:

    **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.**
    
  2. Start a conversation with Claude Code in this project

  3. 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
  4. Continue conversation until context compaction triggers (usually after ~15-20 turns with tool use)

  5. 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)
  6. 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.

nickfox avatar Oct 17 '25 22:10 nickfox

Any updates on This Antropic?

WGSTecnologia avatar Nov 19 '25 01:11 WGSTecnologia

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

nickfox avatar Nov 29 '25 14:11 nickfox

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.

github-actions[bot] avatar Dec 30 '25 10:12 github-actions[bot]

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

nickfox avatar Dec 30 '25 10:12 nickfox

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.

ThatDragonOverThere avatar Jan 26 '26 16:01 ThatDragonOverThere

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.

nickfox avatar Jan 26 '26 16:01 nickfox

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.

ThatDragonOverThere avatar Jan 27 '26 16:01 ThatDragonOverThere