Bug: caffeinate processes leak — thousands spawned per session, never cleaned up
---
Bug Description
Claude Code spawns a new caffeinate process on repeated actions within a session but never cleans up prior instances. Over the course of a single session, this results in thousands of orphaned caffeinate processes accumulating, causing severe system resource exhaustion, extreme battery drain, and thermal throttling.
Impact
This is a critical resource leak that can make a laptop essentially unusable:
- Battery: Battery drain accelerated dramatically — 47% remaining showed only ~40 minutes of estimated life on a MacBook Pro M4 Pro with 48GB RAM
- CPU: System CPU hit 97% utilization (only 3% idle) with load averages of 28–31
- Memory: 47GB of 48GB RAM consumed, only 183MB free
- Thermal: Machine was extremely hot to the touch
- Processes: Total system process count ballooned to 6,000 (normally ~900)
Reproduction Details
A single Claude Code session (launched with claude --dangerously-skip-permissions) spawned 4,567 caffeinate processes, all with the same parent PID. None were ever cleaned up during the session.
Evidence
Process count:
$ pgrep caffeinate | wc -l
4567
All caffeinate processes traced to one Claude Code session:
$ ps -o ppid= -p $(pgrep caffeinate | head -20) | sort -u
54880
$ ps aux | grep 54880
cbrane 54880 10.2 2.1 509555648 1041632 s019 S+ 7:31PM 14:51.27 claude --dangerously-skip-permissions
System state before fix (from top):
Processes: 6000 total, 9 running, 5991 sleeping, 15836 threads
Load Avg: 28.31, 31.21, 23.58
CPU usage: 48.41% user, 48.29% sys, 3.28% idle
PhysMem: 47G used (4844M wired, 6126M compressor), 183M unused
PerfPowerServices (macOS power management daemon) was at 184% CPU trying to cope with all the processes:
root 4431 184.1 0.1 435407648 30160 ?? Rs 3:02AM 5:07.49 /usr/libexec/PerfPowerServices
System state after running killall caffeinate:
Processes: 897 total, 3 running, 894 sleeping, 5586 threads
Load Avg: 14.05, 25.77, 22.81 (still recovering)
CPU usage: 8.16% user, 18.44% sys, 73.39% idle
PhysMem: 39GB used (3468M wired, 5969M compressor), 8782M unused
Recovery was immediate and dramatic — ~5,100 processes eliminated, 8.5GB RAM freed, CPU went from 3% idle to 73% idle.
Expected Behavior
Claude Code should spawn one caffeinate process per session and either:
- Reuse the existing
caffeinateprocess across actions, or - Kill the previous
caffeinatebefore spawning a new one, or - Track the PID and clean up on session exit
Actual Behavior
A new caffeinate process is spawned on repeated actions without killing prior instances. Over a multi-hour session, this results in thousands of leaked processes that are never cleaned up, even when the session ends.
Possible Silent Impact on Other Users
This bug may be silently affecting many users who notice poor battery life while using Claude Code but don't think to check their process list. Since caffeinate processes are tiny individually, they wouldn't show up as a top CPU consumer — the damage comes from the sheer volume overwhelming the OS process scheduler and power management subsystem.
Environment
- Claude Code version: 2.1.51
- macOS: 26.0.1 (Build 25A362)
- Kernel: Darwin 25.0.0 (arm64)
- Hardware: MacBook Pro, Apple M4 Pro, 48GB RAM
- Shell: zsh
- Launch command:
claude --dangerously-skip-permissions
Workaround
Run killall caffeinate in a terminal to immediately kill all leaked processes. System resources recover instantly.
This issue has 2 comments on GitHub. Read the full discussion on GitHub ↗