[BUG] Compaction loop triggered by reading rules — immediate re-compaction after rules read
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?
In Claude Code, when I trigger compaction (manually with /compact or automatically), the tool starts “Compacting conversation…”, then immediately reads the rules files (e.g., .claude/rules/*), and then immediately restarts the compaction process again without completing the operation or making observable progress.
This cycle — reading the rules and re-entering compaction — repeats indefinitely (or until manual interruption), wasting tokens and preventing normal use. This is not simply slow compaction; it’s a loop triggered specifically after reading the rules.
What Should Happen?
/compact starts and displays “Compacting conversation…”.
The engine reads the rules files.
Instead of finishing, Claude Code goes back to “Compacting conversation…” again.
This loop continues unexpectedly, consuming tokens.
No completion or stable compact output occurs.
This differs from other compaction bugs where the process gets stuck because of context size — here the loop seems tied specifically to rule reads.
Error Messages/Logs
The expected behavior is:
Compaction starts once when triggered.
The conversation is summarized and reduced.
Compaction ends normally without re-triggering automatically.
Normal execution continues.
Reading rules should not immediately restart the compaction loop
Steps to Reproduce
Create persistent custom rules in .claude/rules/.
Start a Claude Code session using those rules.
Issue /compact, or let auto-compaction run.
Observe that compaction starts, reads rules, and immediately loops back into compaction repeatedly.
Claude Model
Sonnet (default)
Is this a regression?
I don't know
Last Working Version
_No response_
Claude Code Version
2.1.17
Platform
Anthropic API
Operating System
macOS
Terminal/Shell
Terminal.app (macOS)
Additional Information
_No response_
This issue has 3 comments on GitHub. Read the full discussion on GitHub ↗