From 5823c9fb361498177955978825f10481b197b83e Mon Sep 17 00:00:00 2001 From: gastown/crew/joe Date: Sat, 17 Jan 2026 01:34:27 -0800 Subject: [PATCH] fix(down): prevent tmux server exit when all sessions killed When gt down --all killed all Gas Town sessions, if those were the only tmux sessions, the server would exit due to tmux's default exit-empty setting. Users perceived this as gt down --all killed my tmux server. Fix: Set exit-empty off before killing sessions, ensuring the server stays running for subsequent gt up commands. The --nuke flag still explicitly kills the server when requested. Fixes: gt-kh8w47 Co-Authored-By: Claude Opus 4.5 --- internal/cmd/down.go | 6 ++++++ internal/tmux/tmux.go | 17 +++++++++++++++++ 2 files changed, 23 insertions(+) diff --git a/internal/cmd/down.go b/internal/cmd/down.go index d119a89c..50a2ce08 100644 --- a/internal/cmd/down.go +++ b/internal/cmd/down.go @@ -95,6 +95,12 @@ func runDown(cmd *cobra.Command, args []string) error { return fmt.Errorf("cannot proceed: %w", err) } defer func() { _ = lock.Unlock() }() + + // Prevent tmux server from exiting when all sessions are killed. + // By default, tmux exits when there are no sessions (exit-empty on). + // This ensures the server stays running for subsequent `gt up`. + // Ignore errors - if there's no server, nothing to configure. + _ = t.SetExitEmpty(false) } allOK := true diff --git a/internal/tmux/tmux.go b/internal/tmux/tmux.go index 12c1f8c4..435e6126 100644 --- a/internal/tmux/tmux.go +++ b/internal/tmux/tmux.go @@ -224,6 +224,23 @@ func (t *Tmux) KillServer() error { return err } +// SetExitEmpty controls the tmux exit-empty server option. +// When on (default), the server exits when there are no sessions. +// When off, the server stays running even with no sessions. +// This is useful during shutdown to prevent the server from exiting +// when all Gas Town sessions are killed but the user has no other sessions. +func (t *Tmux) SetExitEmpty(on bool) error { + value := "on" + if !on { + value = "off" + } + _, err := t.run("set-option", "-g", "exit-empty", value) + if errors.Is(err, ErrNoServer) { + return nil // No server to configure + } + return err +} + // IsAvailable checks if tmux is installed and can be invoked. func (t *Tmux) IsAvailable() bool { cmd := exec.Command("tmux", "-V")