[BUG] CLI process orphans at 100% CPU after window/terminal close (2.1.111, 2.1.121)
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?
After closing the terminal or Claude.app window without /exit, the claude CLI process is orphaned (PPID=1) and stays at ~100% CPU indefinitely. Last transcript entry is a normal assistant reply with all tool_use paired with tool_result — session ended cleanly but the event loop never exits. Found 3 such zombies on my system over 8 days; worst case ran 184 CPU-hours.
Summary
After closing the host terminal or Claude.app window, the claude CLI process is sometimes orphaned (PPID=1) and stays at ~100% CPU indefinitely. The session ended cleanly (last transcript entry is a normal assistant reply, all tool_use paired with tool_result), but the event loop never exits.
Versions affected
- 2.1.111
- 2.1.121
- macOS (Apple Silicon, latest)
Evidence
Found 3 zombie processes over 8 days. Worst case lived 8 days at ~100% CPU (184 CPU-hours) after a session that ended normally on 2026-04-27 19:37 — no interruption, no unfinished tool calls in the transcript.
Sample ps output:
- PID 14051, PPID=1, 99.2% CPU, 16h elapsed, claude-code 2.1.121
- PID 47432, PPID=1, 99.6% CPU, 8d 15h elapsed, claude-code 2.1.111
All zombies share: PPID=1 (parent died), high CPU, no further activity in the JSONL transcript.
Reproduction
Not 100% deterministic, but suspected trigger: closing the host (terminal window or Claude.app) without /exit. Possibly related to stdin/stdout handling on parent death — the process doesn't seem to receive or honor SIGHUP.
Impact
- Drains CPU/battery silently
- Multiplies over time if user doesn't notice (3 zombies × ~100% CPU = 3 cores wasted)
Workaround
LaunchAgent runs hourly and kills MacOS/claude processes with PPID=1 AND %CPU>50. Active sessions are safe (they have non-1 PPID).
Suggested fix
- Trap SIGHUP / SIGPIPE in the CLI's main event loop and exit cleanly
- Or: detect closed stdin and exit
What Should Happen?
When the parent process (terminal or Claude.app window) closes, the claude CLI process should receive SIGHUP and exit cleanly within seconds.
Error Messages/Logs
Steps to Reproduce
- Open a Claude Code session in Claude.app or a terminal
- Have a normal exchange (or several)
- Close the host window/terminal directly (X button, Cmd+Q) without typing /exit
- Run: ps -axo pid,ppid,%cpu,command | grep MacOS/claude
- Observe: claude process still running with PPID=1 and high CPU
Not 100% deterministic — happened ~3 times over 8 days of regular use.
Claude Model
Opus
Is this a regression?
Yes, this worked in a previous version
Last Working Version
Claude Code: 2.1.111 and 2.1.121 (both affected)
Claude Code Version
1.5354.0
Platform
Anthropic API
Operating System
macOS
Terminal/Shell
Terminal.app (macOS)
Additional Information
logs:
ps -axo pid,ppid,%cpu,etime,command | grep MacOS/claude
14051 1 99.2 16:17:11 ...claude-code/2.1.121/.../MacOS/claude
47432 1 99.6 8-15:00 ...claude-code/2.1.111/.../MacOS/claude
This issue has 1 comment on GitHub. Read the full discussion on GitHub ↗