[BUG]
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?
Bug: Claude Code processes become orphaned when terminal is closed
What Should Happen?
Bug: Claude Code processes become orphaned when terminal is closed
Environment:
- OS: Ubuntu 24.04.1 (SlimbookOS)
- Terminal: gnome-terminal, VS Code integrated terminal
- Claude Code: latest version
Description:
Claude Code processes do not terminate when the parent terminal is closed. Instead, they become orphaned and get adopted by systemd --user (PID 1 equivalent for user session).
Observed behavior:
- Closed terminal windows containing active Claude sessions
- Claude processes continued running with TTY showing ? (no terminal)
- Processes consumed significant CPU (up to 77%) despite having no terminal attached
- One process ran for 23+ hours after its terminal was closed
Expected behavior:
Claude Code should receive SIGHUP when the terminal closes and terminate gracefully, or at minimum, stop active work when it detects the terminal is gone.
Process evidence:
PID PPID STAT TTY CMD
583993 563118 Sl ? claude (ran 23 hours without terminal)
921216 563118 Sl ? claude (consuming 77% CPU without terminal)
Parent PID 563118 was systemd --user, indicating the processes were orphaned and reparented.
Impact:
- High CPU usage from zombie sessions
- Excessive heat/fan noise on laptops
- Users unaware that closing terminal doesn't stop Claude
Suggested fix:
Claude Code should monitor for terminal disconnect (SIGHUP) or periodically check if stdin/stdout are still valid, and gracefully exit when detached.
Error Messages/Logs
Steps to Reproduce
na
Claude Model
None
Is this a regression?
Yes, this worked in a previous version
Last Working Version
_No response_
Claude Code Version
2.1.12
Platform
Anthropic API
Operating System
Ubuntu/Debian Linux
Terminal/Shell
VS Code integrated terminal
Additional Information
_No response_
This issue has 3 comments on GitHub. Read the full discussion on GitHub ↗