[BUG] Claude Code Infinite Loop on Corrupted Project Cache
Resolved 💬 3 comments Opened Jan 30, 2026 by smartwatermelon Closed Jan 30, 2026
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?
Summary
Claude Code enters an unrecoverable infinite CPU loop (99% CPU, ignores SIGTERM) when the project cache in ~/.claude/projects/ contains orphaned session files not listed in sessions-index.json.
Environment
- Claude Code Version: 2.1.27
- OS: macOS Darwin 26.2.0 (Apple Silicon)
- Shell: Bash 5.3.9
Symptoms
- Claude Code starts normally and accepts the first prompt
- After submitting the first prompt, the UI freezes completely:
- No cursor blinking
- No token counter updates
- No status messages
- No tool execution indicators
- The
claudeprocess consumes 99% CPU indefinitely kill <pid>(SIGTERM) is ignored - must usekill -9- After
kill -9, terminal is left in corrupted state (control characters echoed)
What Should Happen?
Claude Code should:
- Handle orphaned session files gracefully (ignore or clean up)
- Handle sessions with only
file-history-snapshotentries (no messages) - Handle index/file mismatches without entering an infinite loop
- Remain responsive to SIGTERM signals even during cache processing
- Not corrupt terminal state on abnormal exit
Error Messages/Logs
Steps to Reproduce
- Have a project with session history in
~/.claude/projects/<project-path>/ - Create a state where
sessions-index.jsonreferences fewer sessions than exist on disk (orphaned files) - Start Claude Code in that project directory
- Submit any prompt
- Observe freeze
Claude Model
Opus
Is this a regression?
Yes, this worked in a previous version
Last Working Version
2.1.26
Claude Code Version
2.1.27 (Claude Code)
Platform
Anthropic API
Operating System
macOS
Terminal/Shell
iTerm2
Additional Information
Root Cause Analysis
Investigation revealed the following cache anomalies that trigger the bug:
1. Index/File Mismatch
sessions-index.jsonlisted 3 sessions- 16 session files existed on disk
- 13 orphaned files not tracked by the index
2. Abnormal Session File Structure
File 0380e9f4-23c7-4222-bf1e-79d86a83a258.jsonl:
- Contains 28 lines of ONLY
file-history-snapshotentries - No conversation messages (user/assistant entries)
- All JSON is valid, but the session structure is abnormal
Line 1: valid - type=file-history-snapshot
Line 2: valid - type=file-history-snapshot
... (28 total, all file-history-snapshot)
3. Index Inconsistency
- Session
9305d757-5c89-45bd-b1ed-168728509508has a proper"type":"summary"entry (indicating completed session) - But this session is NOT listed in sessions-index.json
Workaround
Deleting the project cache immediately resolves the issue:
rm -rf ~/.claude/projects/-Users-*-Developer-<project-name>
Claude Code then starts normally (though session history is lost).
Attached Files
Sanitized session files demonstrating the cache state (username redacted):
sessions-index.json- The index file listing only 3 of 16 sessions0380e9f4-23c7-4222-bf1e-79d86a83a258.jsonl- Abnormal session with only file-history-snapshots9305d757-5c89-45bd-b1ed-168728509508.jsonl- Session with summary but not in index2583a481-538c-4e82-b2f3-facaaf89e24e.jsonl- Another orphaned session file
Additional Context
- Issue occurred in multiple projects simultaneously
- All affected projects had MCP servers configured (though disabling MCP did not fix the issue)
- Projects without session history worked normally
- Empty directories worked normally
- The bug appears to be in session/cache loading logic, not MCP or project configuration
Impact
- Complete loss of productivity until cache is manually deleted
- Loss of session history when cache is deleted
- Potential terminal corruption requiring reset
- No error messages or logs to diagnose the issue
This issue has 3 comments on GitHub. Read the full discussion on GitHub ↗