From d4359d4d56718687816d783bc92e8e03cf749ba3 Mon Sep 17 00:00:00 2001 From: Natalie Date: Wed, 20 May 2026 02:34:42 -0700 Subject: [PATCH] =?UTF-8?q?fix(@scripts):=20=F0=9F=90=9B=20improve=20detac?= =?UTF-8?q?hed=20session=20handling=20with=20systemd=20scope?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-Authored-By: Lilith Autocommit --- bin/rclaude | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/bin/rclaude b/bin/rclaude index 5bc6277..06608c4 100755 --- a/bin/rclaude +++ b/bin/rclaude @@ -1603,9 +1603,17 @@ inner=$(build_inner "$dir") # background and print the session name. Symmetric with the local-host # detached branch above; used by supervisor processes (e.g. clare web) # that bring up a remote Claude pane without attaching the calling tty. +# +# We wrap `tmux new-session -d` in `systemd-run --user --scope --collect` +# so the tmux server is parented to its own systemd scope, not the ssh +# login session's scope. Without this, systemd-logind reaps the tmux +# server when the ssh session ends — even with `loginctl enable-linger`, +# transient ssh-spawn scopes get cleaned up after disconnect. The +# `--collect` flag lets systemd garbage-collect the scope after exit. # Mosh is interactive-only — always go through ssh for detached spawn. if [ -n "${RCLAUDE_DETACHED:-}" ]; then - ssh $_SSH_LIVE_OPTS "$host" "tmux new-session -d -s '${session}' \"${inner}\"" + _remote_cmd="systemd-run --user --scope --collect --quiet tmux new-session -d -s '${session}' \"${inner}\" 2>/dev/null || tmux new-session -d -s '${session}' \"${inner}\"" + ssh $_SSH_LIVE_OPTS "$host" "$_remote_cmd" printf '%s\n' "$session" exit 0 fi