[BUG] /compact command loses CLAUDE.md context, causing behavioral rule violations

Resolved 💬 6 comments Opened Jul 27, 2025 by mcfarlanddan Closed Aug 15, 2025

---
Environment

  • Platform (select one):
  • Anthropic API
  • Claude CLI version: 1.0.61 (Claude Code)
  • Operating System: macOS 24.5.0 (Darwin)
  • Terminal: Terminal App

Bug Description

The /compact slash command compresses conversation history but doesn't preserve CLAUDE.md instructions that were
loaded at session start. This causes Claude Code to violate critical safety and behavioral rules defined in
CLAUDE.md.

Steps to Reproduce

  1. Create a CLAUDE.md file with behavioral rules (e.g., "avoid automated scripts when fixing errors")
  2. Start Claude Code session in the project directory (CLAUDE.md automatically loads)
  3. Work on tasks until the conversation context grows long
  4. Run /compact command to compress the conversation
  5. Continue working - Claude Code no longer follows CLAUDE.md rules
  6. Example: After fixing a deployment error, Claude automatically runs npx cdk deploy without permission,

violating the "avoid automated scripts when fixing errors" rule

Expected Behavior

CLAUDE.md instructions should persist through /compact operations since they contain critical behavioral rules
that must be followed throughout the entire session. These rules are foundational to how Claude should behave in
the project.

Actual Behavior

CLAUDE.md contents are treated as regular conversation history and get summarized/lost during compression. This
leads to Claude violating important safety rules like attempting unauthorized deployments or ignoring
project-specific conventions.

Additional Context

This issue creates significant safety risks:

  • Claude may perform unauthorized actions (deployments, commits, etc.)
  • Project-specific conventions and restrictions are forgotten
  • Users must manually re-read CLAUDE.md after each /compact operation as a workaround
  • The memory management documentation states CLAUDE.md is "automatically loaded when Claude Code launches" but

doesn't clarify persistence through compression

Suggested fix: The /compact operation should treat CLAUDE.md content as persistent system-level context that
survives compression, similar to how it's automatically loaded at session start.

View original on GitHub ↗

This issue has 6 comments on GitHub. Read the full discussion on GitHub ↗