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

[BUG] Critical bug: Claude Code ignores custom rules after context compression

Open koshak01 opened this issue 2 months ago • 2 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?

Claude Code systematically ignores custom rules defined in ~/.claude/rules/ after context compression or extended work sessions. Rules that are initially followed correctly (like "NEVER use emojis") are violated after approximately 10-15 iterations of work.

The tool correctly applies rules at the start of a session but loses them during operation, making it unreliable for any production use where coding standards must be maintained.

What Should Happen?

Custom rules defined in ~/.claude/rules/ should persist throughout the entire session regardless of:

  • Number of iterations
  • Context compression events
  • Length of the session
  • Complexity of tasks

Rules are configuration, not conversation context. They should be immutable during a session.

Error Messages/Logs

Example of rule violation after context operations:


// Rule: NEVER use emojis in any output
// Initial behavior (correct):
error!("Database Service not started after {} attempts. Terminating!", max_retries);

// After ~10-15 iterations (rule violated):
error!("❌ Database Service не запущен после {} попыток. Завершаю работу!", max_retries);


No error messages from Claude Code itself - it silently stops following rules.

Steps to Reproduce

  1. Create rule file ~/.claude/rules/common.md with content:

    NEVER use emojis in any output, including log messages, comments, and documentation
    
  2. Start new Claude Code session with any Rust/Python project

  3. Request several iterations of work:

    • "Add database connection pooling"
    • "Add retry logic"
    • "Add logging"
    • "Refactor the error handling"
    • Continue making requests...
  4. Observe: After context compression (usually around iteration 10-15), Claude Code starts inserting emojis in error messages, logs, and comments despite the explicit rule

  5. Attempting to remind about rules via prompt is ignored after compression

Claude Model

Not sure / Multiple models

Is this a regression?

I don't know

Last Working Version

No response

Claude Code Version

v2.0.36

Platform

Anthropic API

Operating System

macOS

Terminal/Shell

Terminal.app (macOS)

Additional Information

  • Claude Code version: Latest
  • OS: Linux/MacOS
  • Project type: Rust/Python
  • Rules location: ~/.claude/rules/
  • Reproducibility: 100% after sufficient iterations

This is not a minor inconvenience - it breaks the fundamental contract of the rules system and makes the tool unsuitable for teams with strict coding standards.

koshak01 avatar Nov 10 '25 16:11 koshak01

Found 3 possible duplicate issues:

  1. https://github.com/anthropics/claude-code/issues/6677
  2. https://github.com/anthropics/claude-code/issues/2978
  3. https://github.com/anthropics/claude-code/issues/8961

This issue will be automatically closed as a duplicate in 3 days.

  • If your issue is a duplicate, please close it and 👍 the existing issue instead
  • To prevent auto-closure, add a comment or 👎 this comment

🤖 Generated with Claude Code

github-actions[bot] avatar Nov 10 '25 16:11 github-actions[bot]

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 11 '25 10:12 github-actions[bot]