anthropics / anthropics/claude-code

[BUG] 2.1.261 macOS arm64: session hangs, main thread 100% CPU in JIT loop while waiting on a background subagent (sample attached)

Offen
#92,393 1 Kommentar 0 Reaktionen 0 zugewiesene Personen Auf GitHub ansehen
area:agents area:core bug duplicate perf:cpu platform:macos
Vorherrschende Sprache
Python
Sterne
145k
Forks
23.1k
PR-Merge-Kennzahlen
PR-Kennzahlen ausstehend

Beschreibung

### Preflight Checklist

- [x] I have searched [existing issues](https://github.com/anthropics/claude-code/issues?q=is%3Aissue%20state%3Aopen%20label%3Abug) 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?

Mid-session (about 32 minutes in, right after dispatching a background subagent), the TUI stops repainting and accepts no input. The process stays alive but is wedged:

- Main thread `R+` at 98–100% CPU continuously; the other 10 threads idle (`ps -M`).
- RSS flat at ~750 MB (physical footprint 401 MB, peak 423 MB) — not a memory leak.
- Zero child processes. No hook, MCP server or statusline process running.
- All three HTTPS sockets to the API in `CLOSED` state; a healthy sibling session on the same machine shows 5 `ESTABLISHED`.
- System memory fine (81% free, swap 1.1 GB). Two other Claude Code sessions on the same Mac kept working normally.
- On an earlier occurrence (2026-08-27, second Mac) `SIGTERM` was ignored and `SIGKILL` was required. `claude --resume` recovers the transcript.

Same signature as #89062 (regression since ~2026-08-21, subagent-heavy sessions) and the older #51560. Per #89062, `BUN_JSC_useDFGJIT=0` still hangs and `BUN_JSC_useJIT=0` crashes at startup, so JIT tuning is not a workaround.

### `sample 5` — main thread, 3637/3637 samples in one identical stack
Load address 0x1041f0000 (binary `2.1.261`). Offsets from load address, outermost → innermost:

```
+0x112efd4 +0x104eb84 +0x1053528 +0xdfa30c +0xfe7b40 +0x79bf4c +0x79b9d8
+0x15ab938 +0x15ab4d4 +0x15abfa0 +0x11286f4 +0x13a0d38 +0x6ed9d4 +0x1a73c8
+0x2bde880 +0x28affe4 +0x35418b4
[JIT 0x116316224] [JIT 0x1163161f4]
+0x588f44 +0x31d337c +0x3074cbc +0x2dd5068 +0x2dd9b58 +0x35418b4
[JIT 0x1173ead10]
+0x3564f90 +0x3564f90 +0x3564f90 <- same frame three times
[JIT 0x115905978] [JIT 0x1169eace8] [JIT 0x115cb3fbc] [JIT 0x1163a7060]
+0x219819c +0x2198318 +0x30d4224 +0x30d4224 <- same frame twice
leaf (JIT, 100% of samples within 0x115904880–0x115904944):
2247 0x1159048dc | 1162 0x1159048b4 | 66 0x115904930 | 57 0x11590493c | 51 0x1159048a4 | 43 0x115904880
```

The leaf never leaves a ~200-byte JIT region, i.e. a tight loop in JavaScript (regex backtracking / O(n²) string or array processing), not a lock or a syscall. Full `sample` output attached under Additional Information; the process was still spinning after the 5 s window.

### Ruled out on this machine
- Fullscreen renderer: reproduced with `"tui": "default"` (and earlier with `fullscreen`).
- Hooks / MCP: no child processes at freeze time; project hooks measured 45–100 ms each.
- Memory pressure: 81% free, RSS flat.
- Terminal emulator: seen in Zed, VS Code integrated terminal and Warp.

### What Should Happen?

The parent session should keep rendering and accept input while a backgrounded subagent runs, and surface the subagent's completion. If the main thread is starved for more than a few seconds, a watchdog should log the JS stack (and SIGTERM/SIGINT should still work) instead of requiring `kill -9`.

Ask: symbolicate the offsets above against the 2.1.261 arm64 build.

### Error Messages/Logs

```shell
No error message: the TUI simply stops updating. Process state at capture time (~32 min after launch, ~25 min after the freeze):

PID PPID %CPU RSS STAT ELAPSED TTY COMM
10745 10578 100.0 750512 R+ 32:17 ttys001 claude

ps -M -p 10745 (main thread vs others):
USER PID TT %CPU STAT PRI STIME UTIME COMMAND
jm 10745 s001 98.6 R 31T 0:07.37 12:45.65 claude
10745 0.0 S 31T 0:01.33 0:08.95
10745 0.0 S 31T 0:00.20 0:00.06
... (8 more idle threads)

lsof -i -p 10745 (frozen):
TCP 192.168.0.101:51528->160.79.104.10:https (CLOSED)
TCP 192.168.0.101:50169->165.66.149.34.bc.googleusercontent.com:https (CLOSED)
TCP 192.168.0.101:50158->160.79.104.10:https (CLOSED)
lsof -i -p 8598 (healthy session, same machine, same minute): 5 x TCP ...:https (ESTABLISHED)

===== sample 10745 5 -f (main-thread excerpt; full 120 KB file available on request) =====
Analysis of sampling claude (pid 10745) every 1 millisecond
Process: 2.1.261 [10745]
Path: /Users/USER/*/2.1.261
Load Address: 0x1041f0000
Identifier: 2.1.261
Code Type: ARM64
Parent Process: zsh [10578]
Date/Time: 2026-09-06 06:58:19.163 +1000
Launch Time: 2026-09-06 06:25:43.724 +1000
OS Version: macOS 26.6.2 (25G83)
Physical footprint: 401.6M
Physical footprint (peak): 423.3M

Call graph:
3637 Thread_124058 DispatchQueue_1: com.apple.main-thread (serial)
+ 3637 start (in dyld) + 6992 [0x185dc44e4]
+ 3637 ??? (in 2.1.261) load address 0x1041f0000 + 0x112efd4 [0x10531efd4]
+ 3637 ??? (in 2.1.261) load address 0x1041f0000 + 0x104eb84 [0x10523eb84]
+ 3637 ??? (in 2.1.261) load address 0x1041f0000 + 0x1053528 [0x105243528]
+ 3637 ??? (in 2.1.261) load address 0x1041f0000 + 0xdfa30c [0x104fea30c]
+ 3637 ??? (in 2.1.261) load address 0x1041f0000 + 0xfe7b40 [0x1051d7b40]
+ 3637 ??? (in 2.1.261) load address 0x1041f0000 + 0x79bf4c [0x10498bf4c]
+ 3637 ??? (in 2.1.261) load address 0x1041f0000 + 0x79b9d8 [0x10498b9d8]
+ 3637 ??? (in 2.1.261) load address 0x1041f0000 + 0x15ab938 [0x10579b938]
+ 3637 ??? (in 2.1.261) load address 0x1041f0000 + 0x15ab4d4 [0x10579b4d4]
+ 3637 ??? (in 2.1.261) load address 0x1041f0000 + 0x15abfa0 [0x10579bfa0]
+ 3637 ??? (in 2.1.261) load address 0x1041f0000 + 0x11286f4 [0x1053186f4]
+ 3637 ??? (in 2.1.261) load address 0x1041f0000 + 0x13a0d38 [0x105590d38]
+ 3637 ??? (in 2.1.261) load address 0x1041f0000 + 0x6ed9d4 [0x1048dd9d4]
+ 3637 ??? (in 2.1.261) load address 0x1041f0000 + 0x1a73c8 [0x1043973c8]
+ 3637 ??? (in 2.1.261) load address 0x1041f0000 + 0x2bde880 [0x106dce880]
+ 3637 ??? (in 2.1.261) load address 0x1041f0000 + 0x28affe4 [0x106a9ffe4]
+ 3637 ??? (in 2.1.261) load address 0x1041f0000 + 0x35418b4 [0x1077318b4]
+ 3637 ??? (in ) [0x116316224]
+ 3637 ??? (in ) [0x1163161f4]
+ 3637 ??? (in 2.1.261) load address 0x1041f0000 + 0x588f44 [0x104778f44]
+ 3637 ??? (in 2.1.261) load address 0x1041f0000 + 0x31d337c [0x1073c337c]
+ 3637 ??? (in 2.1.261) load address 0x1041f0000 + 0x3074cbc [0x107264cbc]
+ 3637 ??? (in 2.1.261) load address 0x1041f0000 + 0x2dd5068 [0x106fc5068]
+ 3637 ??? (in 2.1.261) load address 0x1041f0000 + 0x2dd9b58 [0x106fc9b58]
+ 3637 ??? (in 2.1.261) load address 0x1041f0000 + 0x35418b4 [0x1077318b4]
+ 3637 ??? (in ) [0x1173ead10]
+ 3637 ??? (in 2.1.261) load address 0x1041f0000 + 0x3564f90 [0x107754f90]
+ 3637 ??? (in 2.1.261) load address 0x1041f0000 + 0x3564f90 [0x107754f90]
+ 3637 ??? (in 2.1.261) load address 0x1041f0000 + 0x3564f90 [0x107754f90]
+ 3637 ??? (in ) [0x115905978]
+ 3637 ??? (in ) [0x1169eace8]
+ 3637 ??? (in ) [0x115cb3fbc]
+ 3637 ??? (in ) [0x1163a7060]
+ 3637 ??? (in 2.1.261) load address 0x1041f0000 + 0x219819c [0x10638819c]
+ 3637 ??? (in 2.1.261) load address 0x1041f0000 + 0x2198318 [0x106388318]
+ 3637 ??? (in 2.1.261) load address 0x1041f0000 + 0x30d4224 [0x1072c4224]
+ 3637 ??? (in 2.1.261) load address 0x1041f0000 + 0x30d4224 [0x1072c4224]
+ 2247 ??? (in ) [0x1159048dc]
+ 1162 ??? (in ) [0x1159048b4]
+ 66 ??? (in ) [0x115904930]
+ 57 ??? (in ) [0x11590493c]
+ 51 ??? (in ) [0x1159048a4]
+ 43 ??? (in ) [0x115904880]
+ 5 ??? (in ) [0x115904928]
+ 3 ??? (in ) [0x1159048b0]
+ 2 ??? (in ) [0x1159048d0]
+ 1 ??? (in ) [0x115904944]
[other 10 threads (mi-scavenger, Bun Pool 0-8): all idle in __ulock_wait / __ulock_wait2 / kevent64]

Binary Images:
0x1041f0000 - 0x107fef9bf +2.1.261 (???) <4C4C4401-5555-3144-A13C-E92490FFBCBC> /Users/*/2.1.261
0x11b874000 - 0x11b98fb4f +.bun-501-b163af53257b65ef.node (0) /var/folders/*/.bun-501-b163af53257b65ef.node
```

### Steps to Reproduce

No deterministic reproducer; it happens 30 min to 2 h into sessions that use subagents (same as #89062). Exact sequence of the captured occurrence:

1. `cd` into a project whose `.claude/settings.json` defines PreToolUse, UserPromptSubmit and SessionStart command hooks (bash + jq); start `claude` in auto permission mode, classic renderer (`"tui": "default"`), from Zed's integrated terminal (also seen in VS Code terminal and Warp).
2. Prompt: "pull the latest version" → Claude runs one Bash call (`git pull --ff-only … && git log … && git status`) and answers. Status line shows "1 shell still running".
3. Run a project slash command (`/pm-loop`) whose instructions make Claude run three short Bash calls, `CronList`, then dispatch a **background** subagent via the Agent tool (`project-manager`, model Opus 5 with 1M context). The UI shows "Backgrounded agent" and Claude prints "Waiting for the tick's completion notification", spinner "Waiting for 1 background agent to finish".
4. The screen never updates again. The background agent's result is never surfaced. Ctrl+C does nothing.
5. From another terminal: `ps -M -p ` shows the main thread at ~100% CPU; `sample 5` shows one identical stack for every sample (above).
6. Only `kill -9 ` ends it; `claude --resume` recovers the transcript.

So the hang happens while the parent turn is idle waiting on a backgrounded subagent (plus one still-running background shell), i.e. in the background-agent / task-notification path, not while streaming. Possibly related to the 2.1.261 changelog entry "Fixed sustained high CPU usage when a background agent could not be resumed".

### Claude Model

None

### Is this a regression?

Yes, this worked in a previous version

### Last Working Version

Unknown. Did not happen before ~mid/late August 2026 on either of two Macs; #89062 dates the same regression to ~2026-08-21 (2.1.231+). Reverting to a much older build was tried but that build was unusable for other reasons.

### Claude Code Version

2.1.261 (Claude Code) — native install; also reproduced on 2.1.252, 2.1.258, 2.1.259

### Platform

Anthropic API

### Operating System

macOS

### Terminal/Shell

Other

### Additional Information

Environment
- Hardware: MacBook Air M1 (MacBookAir10,1), 8 cores, 16 GB. Also seen on a second Mac cloned from the same config.
- macOS 26.6.2 (25G83); earlier occurrences on macOS 26.3 (25D125).
- Install: native (`claude.ai/install.sh`), binary `~/.local/share/claude/versions/2.1.261`, `autoUpdates: false`.
- Terminal: Zed 1.18.1 integrated terminal (login -> zsh -> claude). Previously reproduced in VS Code integrated terminal and Warp, so terminal-independent.
- Renderer: `"tui": "default"` at the time of this capture; earlier freezes with `"tui": "fullscreen"`.
- Permission mode: auto. Output style: Brief. Status line: a bash+jq script (~120 ms).
- Project-level hooks (all bash+jq, measured): PreToolUse (no matcher, 79 ms; Bash matcher, 97 ms), UserPromptSubmit (1.3 s), SessionStart (2.7 s). No MCP servers configured in this project. Plugins enabled: superpowers, typescript-lsp, security-guidance (official marketplace).
- Frequency: several times per day across sessions in this and sibling projects; always during or after subagent use; two other sessions on the same machine at the same time were unaffected.

The main-thread excerpt of `sample 5 -f` (1 ms interval, 3637 samples) is in the Logs field above, with the Binary Images UUID for symbolication. The full 120 KB sample (all threads) is saved locally and I can attach it on request.

A second, older sample from 2026-08-27 (different Mac, 2.1.24x) showed the same shape: 100% CPU main thread, flat RSS, SIGTERM ignored. Happy to run any diagnostic build or `--debug` flags on the next occurrence — it recurs within hours.

Not a duplicate of #83237 (there the main thread is idle and mi-scavenger spins; here the main thread spins and every other thread is idle).

Beitragsleitfaden

Für dieses Repository ist kein Beitragsleitfaden indexiert

Rechercherichtung

Start with the attached sample and the 2.1.261 arm64 binary, then compare the reported stack and subagent sequence with #89062 and #51560. No source file, test, or deterministic reproducer is named; progress would require symbolication or a reliable reproduction, followed by verifying that background-agent sessions keep repainting and accept input.

Vom Indexierungsmodell aus dem Issue-Text verfasst.

Bewertung

Tech-Stack
bash, bun, javascript, macos
Bereich
cli, performance
Issue-Typ
Bug
Schwierigkeit
5/5
Geschätzter Aufwand
Über eine Woche
Aktivitätsstatus
Aktiv
Klarheit
Muss geklärt werden
Anfängerfreundlichkeit
25/100

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.