[FEATURE] Handle SIGHUP for graceful exit on terminal close / system restart
Preflight Checklist
- [x] I have searched existing requests and this feature hasn't been requested yet
- [x] This is a single feature request (not multiple features)
Problem Statement
Description:
When macOS restarts (via Apple menu > Restart, or auto-update reboot), Claude Code does not exit gracefully. Specifically, it never prints the session ID
to the terminal, so after reboot you have no easy reference to resume where you left off.
When Claude exits normally (via /stop, Ctrl-C, or SIGTERM), it prints the session GUID to the terminal. This makes resuming trivial: the ID is right there
in your scrollback, ready to copy into claude --resume <id>. After a reboot-triggered death, that ID is never printed, and you have to dig through
~/.claude/projects/ to find it.
Root cause:
During system shutdown, macOS sends a Quit Apple Event to the terminal emulator (iTerm2, Terminal.app). The terminal closes its PTY file descriptor, and
the kernel sends SIGHUP to child processes. Claude Code does not trap SIGHUP, so it dies without running its graceful exit path — which means no session
ID is printed.
Expected behavior:
Claude Code should handle SIGHUP the same way it handles SIGTERM: run the graceful exit handler and print the session ID to the terminal before exiting.
Even if the terminal is closing, writing to stdout before the PTY fully tears down has a good chance of landing in scrollback (terminal emulators buffer
output before closing).
Proposed Solution
Trap SIGHUP and route it through the existing graceful shutdown path:
process.on('SIGHUP', gracefulShutdown);
This is standard practice for interactive CLI tools (tmux, vim, and screen all handle SIGHUP).
Affected scenarios:
- macOS Apple menu > Restart / Shut Down
- macOS auto-update reboots
- Closing the terminal window/tab while Claude is running
- SSH disconnection (also sends SIGHUP)
Alternative Solutions
_No response_
Priority
Low - Nice to have
Feature Category
Other
Use Case Example
_No response_
Additional Context
_No response_