From 4b87a7795fa702bf650969b8e380973f2a4ed85c Mon Sep 17 00:00:00 2001 From: Levi Neely Date: Wed, 18 Feb 2026 16:31:21 +0100 Subject: [PATCH] Assist: reuse existing terminal for tmux attach - Check for existing tmux clients before launching new terminal - Use 'tmux switch-client' to reuse existing terminal window - Fall back to new terminal only when no client is attached --- cmd/Assist/main.go | 26 ++++++++++++++++++++------ 1 file changed, 20 insertions(+), 6 deletions(-) diff --git a/cmd/Assist/main.go b/cmd/Assist/main.go index 8f56c79..18e191c 100644 --- a/cmd/Assist/main.go +++ b/cmd/Assist/main.go @@ -663,12 +663,26 @@ func attachSession(id string) error { return fmt.Errorf("session does not support attach") } - go func() { - cmd := exec.Command(terminalCommand, "-e", "tmux", "attach", "-t", target) - if err := cmd.Start(); err != nil { - fmt.Fprintf(os.Stderr, "Failed to launch terminal: %v\n", err) - } - }() + // Check if there's already a tmux client running + clientsCmd := exec.Command("tmux", "list-clients") + clientsOutput, err := clientsCmd.Output() + if err == nil && len(clientsOutput) > 0 { + // There's an existing tmux client, switch to the target session/window + go func() { + cmd := exec.Command("tmux", "switch-client", "-t", target) + if err := cmd.Run(); err != nil { + fmt.Fprintf(os.Stderr, "Failed to switch tmux client: %v\n", err) + } + }() + } else { + // No existing client, launch new terminal + go func() { + cmd := exec.Command(terminalCommand, "-e", "tmux", "attach", "-t", target) + if err := cmd.Start(); err != nil { + fmt.Fprintf(os.Stderr, "Failed to launch terminal: %v\n", err) + } + }() + } return nil }