Background-session PTY host waits 5 s for a client after SIGTERM, adding 5 s to every shutdown
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?
Each background session runs under a PTY host process (claude --bg-pty-host …, shown in ps as claude bg-pty-host). On SIGTERM or SIGINT the host passes the signal on to its session, and on SIGHUP it sends the session SIGTERM; the host itself does not exit. Once the session has exited, if no client is attached, the host waits for a client to connect, with a 5000 ms timeout, before it exits. During a system shutdown or a systemctl --user stop nothing connects, so the stop waits the full 5 s after the sessions have exited. The hosts wait in parallel, so that is 5 s per shutdown, not per session.
Here the background daemon (claude daemon run) and its hosts run in the cgroup of the client that started the daemon. Under Ghostty, which gives each terminal surface its own app-ghostty-surface-transient-<pid>.scope, that is the scope of that terminal: right now the daemon and its four hosts are all in app-ghostty-surface-transient-4624.scope. That terminal's scope is what a shutdown waits on.
In 2.1.289 nothing on the host's exit path knows that the host itself was signalled, and the wait for a client is called without a timeout argument, so it always uses its 5000 ms default.
What Should Happen?
A host that is exiting because it was sent SIGTERM, SIGINT or SIGHUP exits as soon as its session has exited, without waiting for a client to reattach.
Error Messages/Logs
From a reboot on 2026-10-03 running 2.1.289. ~/.claude/daemon.log:
[2026-10-03T22:01:07.920Z] [supervisor] ─── daemon start ─── version=2.1.289 pid=5302 origin=transient
[2026-10-03T23:03:08.824Z] [supervisor] shutting down (cause=signal, uptime=3721s, leases=0, live_workers=1)
The last line any session debug log (~/.claude/debug/) wrote is at 23:03:10.205Z. Journal (UTC):
23:03:08.823634 systemd[1201]: Stopping app-ghostty-surface-transient-4530.scope...
23:03:15.260884 systemd[1201]: Stopped app-ghostty-surface-transient-4530.scope.
The scope stopped 5.06 s after the session's last log line.
Steps to Reproduce
- Run a host on its own in a transient user unit, wrapping a process that stays up (
80 24are the PTY's columns and rows):
````
C=$(command -v claude); S=$XDG_RUNTIME_DIR/pty-probe.sock
systemd-run --user --collect --unit=pty-probe "$C" --bg-pty-host "$S" 80 24 -- sleep infinity
sleep 2
time systemctl --user stop pty-probe
- The stop takes 5.03 s (5.029 s and 5.026 s in two runs).
Controls on the same machine: systemd-run --user --collect --unit=pty-probe sleep infinity stops in 0.007 s. Running socat -u UNIX-CONNECT:"$S" - & between sleep 2 and the stop, so that a client is connected, makes the stop take 0.024 s.
Claude Model
_No response_
Is this a regression?
I don't know
Last Working Version
_No response_
Claude Code Version
2.1.289 (Claude Code)
Platform
Anthropic API
Operating System
Other Linux
Terminal/Shell
Other
Additional Information
Arch Linux, kernel 7.2.8-zen, systemd 262, Ghostty 1.3.1, native install. #99369 is a separate shutdown delay in the same setup: the agent view starting a new daemon during shutdown.