[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

  1. Claude Code starts normally and accepts the first prompt
  2. After submitting the first prompt, the UI freezes completely:
  • No cursor blinking
  • No token counter updates
  • No status messages
  • No tool execution indicators
  1. The claude process consumes 99% CPU indefinitely
  2. kill <pid> (SIGTERM) is ignored - must use kill -9
  3. After kill -9, terminal is left in corrupted state (control characters echoed)

What Should Happen?

Claude Code should:

  1. Handle orphaned session files gracefully (ignore or clean up)
  2. Handle sessions with only file-history-snapshot entries (no messages)
  3. Handle index/file mismatches without entering an infinite loop
  4. Remain responsive to SIGTERM signals even during cache processing
  5. Not corrupt terminal state on abnormal exit

Error Messages/Logs

Steps to Reproduce

  1. Have a project with session history in ~/.claude/projects/<project-path>/
  2. Create a state where sessions-index.json references fewer sessions than exist on disk (orphaned files)
  3. Start Claude Code in that project directory
  4. Submit any prompt
  5. 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.json listed 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-snapshot entries
  • 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-168728509508 has 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):

  1. sessions-index.json - The index file listing only 3 of 16 sessions
  2. 0380e9f4-23c7-4222-bf1e-79d86a83a258.jsonl - Abnormal session with only file-history-snapshots
  3. 9305d757-5c89-45bd-b1ed-168728509508.jsonl - Session with summary but not in index
  4. 2583a481-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

claude-bug-report.zip

  • No error messages or logs to diagnose the issue

View original on GitHub ↗

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