From 0703835ce945f8f681244a67484a8e9881e16f2c Mon Sep 17 00:00:00 2001 From: Steve Yegge Date: Wed, 17 Dec 2025 22:44:42 -0800 Subject: [PATCH] Fix gt mayor attach to mirror Python behavior MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Auto-start Mayor session if not running (matches town mayor attach) - Send `gt prime` after Claude starts to initialize context - Use `exec claude` so /exit closes tmux session (no shell to return to) - Add "may" alias for mayor command 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 --- internal/cmd/mayor.go | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/internal/cmd/mayor.go b/internal/cmd/mayor.go index 26539d15..8babcdfd 100644 --- a/internal/cmd/mayor.go +++ b/internal/cmd/mayor.go @@ -17,8 +17,9 @@ import ( const MayorSessionName = "gt-mayor" var mayorCmd = &cobra.Command{ - Use: "mayor", - Short: "Manage the Mayor session", + Use: "mayor", + Aliases: []string{"may"}, + Short: "Manage the Mayor session", Long: `Manage the Mayor tmux session. The Mayor is the global coordinator for Gas Town, running as a persistent @@ -122,7 +123,8 @@ func startMayorSession(t *tmux.Tmux) error { t.SetEnvironment(MayorSessionName, "GT_ROLE", "mayor") // Launch Claude with full permissions (Mayor is trusted) - if err := t.SendKeys(MayorSessionName, "claude --dangerously-skip-permissions"); err != nil { + // Use exec to replace shell - when Claude exits, session closes + if err := t.SendKeys(MayorSessionName, "exec claude --dangerously-skip-permissions"); err != nil { return fmt.Errorf("sending command: %w", err) } @@ -170,18 +172,19 @@ func runMayorAttach(cmd *cobra.Command, args []string) error { return fmt.Errorf("checking session: %w", err) } if !running { - // Auto-start if not running + // Auto-start if not running (matches Python behavior) fmt.Println("Mayor session not running, starting...") if err := startMayorSession(t); err != nil { return err } } else { // Session exists - check if Claude is still running + // (With exec this rarely triggers, but handles edge cases) paneCmd, err := t.GetPaneCommand(MayorSessionName) if err == nil && isMayorShellCommand(paneCmd) { - // Claude has exited, restart it + // Claude has exited, restart it with exec fmt.Println("Claude exited, restarting...") - if err := t.SendKeys(MayorSessionName, "claude --dangerously-skip-permissions"); err != nil { + if err := t.SendKeys(MayorSessionName, "exec claude --dangerously-skip-permissions"); err != nil { return fmt.Errorf("restarting claude: %w", err) } // Prime after restart