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

[BUG] Claude Code v2.1.9 Complete Freeze - 100% CPU, Main Thread Stuck in Infinite Loop (macOS ARM64)

Open smconner opened this issue 3 weeks ago • 6 comments

Summary

Claude Code v2.1.9 session became completely unresponsive, consuming 100% CPU and ~7GB RAM for nearly 2 hours. The main thread is stuck in an infinite loop with no progress. This appears to be a continuation of the freeze/hang issues reported in earlier versions.

Keywords for discoverability: freeze, hang, stuck, unresponsive, 100% CPU, spinning, infinite loop, main thread blocked, macOS, ARM64, Apple Silicon, M4, Bun runtime, kill -9 required


Related Issues

This bug is related to and may be a regression of:

Issue Title Version Status
#1554 Hanging/Freezing in the middle of work v1.0.10 OPEN
#6474 Unresponsive hang with 120% CPU usage v1.0.89, v2.0.x OPEN
#11339 100% CPU in interactive mode on macOS v2.0.36 Closed (Fixed)
#11377 Memory leak with 143% CPU after 14 hours v2.0.22 Closed
#4580 100% CPU during multi-agent task JSON serialization v1.x OPEN
#6705 claude doctor hangs indefinitely, 100% CPU v1.0.95 OPEN
#10481 Complete UI Freeze - ReadFileUtf8 I/O Block v2.0.28 OPEN

Environment

Component Value
Claude Code Version 2.1.9
Platform macOS 15.7.3 (Build 24G419)
Architecture ARM64 (Apple Silicon)
CPU Apple M4, 10 cores
RAM 32GB
Kernel Darwin 24.6.0
Terminal /dev/ttys011

Symptoms

  • Complete UI freeze - No response to any input
  • 100% CPU on single core - Main thread spinning indefinitely
  • ~7GB memory consumption (RSS), 2GB physical footprint
  • Cannot interrupt - Only kill -9 terminates the process
  • Work lost - Must force quit and lose session state
  • Network connections remain open - Server-side appears fine

Process State When Frozen

PID     CPU%    MEM%    RSS        STATE   ELAPSED     COMMAND
36202   100.1   20.9    6.7GB      R+      01:55:44    claude
Metric Value
CPU Time Consumed 8+ minutes
Wall Clock Time Frozen ~2 hours
Launch Time 13:24:28
Sample Time 15:20:12

Stack Sample Analysis

A 10-second sample (8500 samples at 1ms intervals) shows 100% of samples on the main thread in a tight loop.

Thread Summary

Thread Role Status
Main Thread (com.apple.main-thread) Event loop 🔴 SPINNING - 8500/8500 samples
Bun Pool 0-7 Worker threads Idle
HTTP Client Network Idle
File Watcher FS events Idle
JavaScriptCore libpas scavenger GC Idle
Heap Helper Threads (x3) GC Idle

Hot Path (Main Thread)

The main thread is stuck in this call path (symbols stripped, showing offsets):

8500 start (in dyld)
└─ 8500 ??? (in 2.1.9) + 0x3f90
   └─ 8500 ??? (in 2.1.9) + 0x536c
      └─ 8500 ??? (in 2.1.9) + 0x26a430
         └─ 8500 ??? (in 2.1.9) + 0x1121cd0
            └─ 8500 ??? (in 2.1.9) + 0x2ab770
               └─ ... (deep into JS/Bun runtime)

System Calls in Hot Path

_platform_memmove (libsystem_platform.dylib)     ← Memory copy operations
__bzero (libsystem_platform.dylib)               ← Memory zeroing
pthread_getspecific (libsystem_pthread.dylib)    ← Thread-local storage
os_unfair_lock_lock/unlock (libsystem_platform)  ← Lock operations
task_info (libsystem_kernel.dylib)               ← Process info queries

This pattern suggests:

  • Possible infinite loop with repeated memory allocations
  • Or runaway JSON serialization/parsing
  • Or regex catastrophic backtracking
  • Or busy-wait polling loop (similar to #11339)

Network State

The process maintained active connections to Anthropic servers:

tcp4  192.168.1.136:59404 -> 160.79.104.10:443  ESTABLISHED
tcp4  192.168.1.136:58472 -> 160.79.104.10:443  ESTABLISHED

IP 160.79.104.10 confirmed as Anthropic infrastructure (ARIN: AP-2440). This indicates the freeze is client-side - server connections remain healthy.


Open File Descriptors

FD   TYPE   NAME
0-2  CHR    /dev/ttys011 (terminal)
12   TCP    -> 160.79.104.10:443 (Anthropic API)
37   TCP    -> 160.79.104.10:443 (Anthropic API)
43   REG    ~/.claude/settings.local.json
47   REG    ~/.claude/history.jsonl

System State (Not Overloaded)

Load Average: 1.78, 1.64, 1.60
CPU: 20.70% user, 12.33% sys, 66.96% idle
RAM: 31GB used, 654MB free (32GB total)
Processes: 740 total, 5 running

The system was not under heavy load - this is isolated to the Claude Code process.


Reproduction

Unable to determine exact trigger - the freeze occurred during normal interactive usage. However, based on related issues, potential triggers include:

  • Search/grep operations (#6474)
  • Multi-agent/Task tool usage (#4580)
  • Large context or file operations (#1554)
  • Interactive prompt mode (#11339)

Workaround

Force kill the frozen process:

kill -9 $(pgrep -f "claude" | head -1)

Suggested Fixes

Based on analysis and related issues:

  1. Add watchdog timer - Detect main thread stalls > N seconds
  2. Implement operation timeouts - Prevent infinite loops in parsing/serialization
  3. Use async I/O properly - Avoid busy-wait polling (fix from #11339 may have regressed)
  4. Add SIGINT handler - Allow graceful interrupt even when stuck
  5. Memory operation limits - Cap allocation loops

Attachments

Full stack sample available (175KB, 8500 samples over 10 seconds). Happy to provide if needed.


For Other Users Experiencing This

If you're finding this issue because Claude Code froze on you:

  1. To kill a frozen session:

    # Find the PID
    ps aux | grep claude
    
    # Kill it (only -9 works when frozen)
    kill -9 <PID>
    
  2. To capture diagnostic info before killing:

    # Get stack sample (macOS)
    sample <PID> -f /tmp/claude_sample.txt
    
    # Get process info
    ps -p <PID> -o pid,ppid,state,time,etime,pcpu,pmem,rss,command
    
    # Get open files
    lsof -p <PID>
    
  3. Workarounds that may help:

    • Use shorter sessions
    • Avoid very large file operations
    • Try claude --resume instead of --continue after recovery

/cc @bcherny (assigned on #1554)

smconner avatar Jan 16 '26 08:01 smconner

Found 3 possible duplicate issues:

  1. https://github.com/anthropics/claude-code/issues/11473
  2. https://github.com/anthropics/claude-code/issues/3214
  3. https://github.com/anthropics/claude-code/issues/17540

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 Jan 16 '26 08:01 github-actions[bot]

M4 Pro Mac, getting same on 2.1.9. Running "claude" nothing happens - have to kill it.

richbradshaw avatar Jan 16 '26 09:01 richbradshaw

I had few freezes yesterday and I opened other terminal with -c continue and the app refreshed.

superresistant avatar Jan 16 '26 11:01 superresistant

This issue appeared in recent versions of CC, since ~2.1.0 I'm getting increased number of freezes (many per day), sometimes when claude tries to read large files/command outputs, sometimes it just gets stuck after a Bash tool use.

acorbellini avatar Jan 16 '26 12:01 acorbellini

My report was a mistake. I was sshed in and Claude had a macOS pop up saying it was an app from Internet and I needed to click yes. But Ui via ssh doesn't make that clear etc

richbradshaw avatar Jan 18 '26 00:01 richbradshaw

It seems that it's somehow related to working with large files or MCP responses. For me, it's mostly when I do stuff with playwright.

genail avatar Jan 18 '26 11:01 genail

Same here, HP Spectre x360 with arch and froze after using grep on a really big markdown file. Closing tab doesn't kill the process and in some cases just hitting the button to resume the conversation freezes too so I can't continue the same chat.

albiol2004 avatar Jan 18 '26 15:01 albiol2004

same issue when grep big xml, log, md files.

Krakazybik avatar Jan 19 '26 12:01 Krakazybik

Worth mentioning: for me it started happening only after a while, once the conversation got bigger. I switched back to 2.0.x, which doesn’t have this bug. When I find a moment, I’ll try to grab a stack trace and process info (if possible).

genail avatar Jan 19 '26 15:01 genail

I finally gave up and switched back to 2.0.76; 100% reproducible freezing immediately went away.

2.1.12 was reproducibly freezing with 100% cpu on macos when reviewing a PR that had a large (>2k lines) VCR cassette diff.

Unfortunately 2.1.x appears "literally unusable" right now; only switched back to 2.0 because this happened multiple times in multiple different situations; this is really a show-stopper right now and makes claude code pretty much unusable.

jonaustin avatar Jan 19 '26 22:01 jonaustin