[BUG] Critical bug: Claude Code ignores custom rules after context compression
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
- Create rule file
~/.claude/rules/common.mdwith content:
````
NEVER use emojis in any output, including log messages, comments, and documentation
- Start new Claude Code session with any Rust/Python project
- Request several iterations of work:
- "Add database connection pooling"
- "Add retry logic"
- "Add logging"
- "Refactor the error handling"
- Continue making requests...
- Observe: After context compression (usually around iteration 10-15), Claude Code starts inserting emojis in error messages, logs, and comments despite the explicit rule
- 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.
This issue has 4 comments on GitHub. Read the full discussion on GitHub ↗