fix: clean up orphaned tmux sessions at gt start time

Add CleanupOrphanedSessions() function that runs at `gt start` time to
detect and kill zombie tmux sessions (sessions where tmux is alive but
the Claude process has died).

This prevents:
- Session name conflicts when restarting agents
- Resource accumulation from orphaned sessions
- Process accumulation that can overwhelm the system

The function scans for sessions with `gt-*` and `hq-*` prefixes, checks
if Claude is running using IsClaudeRunning(), and kills zombie sessions
using KillSessionWithProcesses() for proper cleanup.

Fixes #700

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
toast
2026-01-22 21:40:35 -08:00
committed by beads/crew/emma
parent 73d577e3c3
commit ee5221889f
3 changed files with 137 additions and 0 deletions

View File

@@ -174,6 +174,15 @@ func runStart(cmd *cobra.Command, args []string) error {
t := tmux.NewTmux()
// Clean up orphaned tmux sessions before starting new agents.
// This prevents session name conflicts and resource accumulation from
// zombie sessions (tmux alive but Claude dead).
if cleaned, err := t.CleanupOrphanedSessions(); err != nil {
fmt.Printf(" %s Could not clean orphaned sessions: %v\n", style.Dim.Render("○"), err)
} else if cleaned > 0 {
fmt.Printf(" %s Cleaned up %d orphaned session(s)\n", style.Bold.Render("✓"), cleaned)
}
fmt.Printf("Starting Gas Town from %s\n\n", style.Dim.Render(townRoot))
fmt.Println("Starting all agents in parallel...")
fmt.Println()