Skip to content

bug(perf): Mac overheats — 8 claude.exe bg-spare worker pairs leak (loadavg 88 on 8-core M1) #459

Description

@LiuShiyuMath

Symptom

Mac feels physically hot, UI lag (mouse/keyboard/Terminal stutter, WindowServer at 31% CPU). Reported by user 2026-05-14.

Root cause

Claude Code CLI --bg-spare worker leak — same pathology as documented in docs/debugging/toohot-many-bg-spare-workers.md (2026-05-12 case at loadavg 61). Current state is worse:

Metric 2026-05-12 case (doc) 2026-05-14 (this report)
loadavg (1/5/15) 27 / 46 / 46 88.76 / 69.69 / 62.94
oversubscription (loadavg ÷ cores) 3-7× 11×
bg-spare / bg-pty-host pairs 20 8 (× 2 = 16 procs)
daemon claude.exe processes 1 7 (in ~/.claude/jobs/)
pmset -g therm flag normal normal (NOT thermal wall)

TeamBrain attribution: NOT a TeamBrain code bug. The leak is in @anthropic-ai/claude-code CLI daemon (claude.exe daemon run). However, TeamBrain's multi-worktree / multi-driver workflow (/fixed-flow-driver, /review subagent fan-out, 35+ subcommands, FIXEDFLOW parallelism) drives users toward N concurrent claude sessions → amplifies the leak.

Reproduction

# 1) Open ≥3 TeamBrain worktrees in parallel Claude Code sessions
# 2) Run any of: /fixed-flow-driver, /review, claudefast probes
# 3) Let sessions idle for 30+ min between turns
# 4) Check:
ps -axwwwo pid,ppid,pcpu,command | grep -E "bg-spare|bg-pty-host" | grep -v grep | wc -l
sysctl -n vm.loadavg
pmset -g therm                       # confirms scheduler-overload, not thermal
ls -la ~/.claude/jobs/               # count daemon sessions

Expected on a hot machine: loadavg > 2× cores, multiple bg-spare/bg-pty-host pairs per claude session, thermal flag normal.

Evidence captured (2026-05-14 11:30 local)

loadavg  = { 88.76 69.69 62.94 }   # M1 8-core → 11× oversubscription
ncpu     = 8
thermal  = normal (pmset -g therm: no warnings recorded)

bg-spare/bg-pty-host pairs:
  daemon 26072 (origin: /Users/m1/projects/metrixMarkets)
    ├── 4365  ──┬── 4405   bg-spare  0.2% CPU
    ├── 26105 ──┬── 26111  bg-spare  0.8%
    ├── 26115 ──┬── 26121  bg-spare  0.6%
    ├── 26300 ──┬── 26308  bg-spare  2.4%
    ├── 28553 ──┬── 28564  bg-spare  2.6%
    ├── 29861 ──┬── 29878  bg-spare 16.2%
    ├── 43719 ──┬── 43733  bg-spare 10.1%
    └── 46939 ──┬── 46973  bg-spare 39.4%  ← worst offender

top CPU: claude.exe 44.3%, node 32.5%, WindowServer 31.6%, coreaudiod 20.7%

Mitigation (existing playbook)

Kill recipe in docs/debugging/toohot-many-bg-spare-workers.md:

  1. Identify own PID chain (P=$$; while [ "$P" != 1 ]; do ps -o pid,ppid,command -p "$P"; P=$(ps -o ppid= -p "$P"); done)
  2. ps -axo pid,command | awk '/--bg-spare/ {print $1}' | grep -v MY_PIDS | xargs kill -TERM
  3. Wait 2s, SIGKILL stragglers, daemon auto-prewarms 3-5 spares.

What this issue asks for

Doc-only post-hoc recipe is not enough — 2026-05-12 → 2026-05-14 we hit the same wall twice in 2 days, and the second time loadavg was 45% higher. Proposed scope (needs grill before driver dispatch):

  • Detection: ship a pnpm teamagent doctor --bg-spare probe that counts bg-spare/bg-pty-host pairs and yells if > 2× active worktree sessions
  • Prevention: SessionStart hook warns if total bg-spare workers > threshold before user opens another session
  • Auto-reaper (cautious): opt-in pnpm teamagent reap-bg-spare that does the safe SIGTERM-then-KILL recipe with own-PID-chain protection baked in
  • Upstream report: file the leak with @anthropic-ai/claude-code if not already known

Related

  • docs/debugging/toohot-many-bg-spare-workers.md — existing post-hoc kill recipe
  • docs/adr/0013-inner-loop-on-ci.md — same scheduler-overload mechanism, different trigger (vitest fork burst)
  • User-level CLAUDE.md show temperature recipe — Bash-only Top7 monitor

Notification

User asked for @libz mention in Slack when this is fixed. Slack ping has been queued separately.


Filed via /investigate skill on 2026-05-14.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions