From 5260a9ca08dc85ea0dafd54a3da92add1f106f3f Mon Sep 17 00:00:00 2001 From: Steve Yegge Date: Mon, 29 Dec 2025 15:24:31 -0800 Subject: [PATCH] fix: Close agent bead when crew workspace is removed (gt-rqcd8) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit When gt crew remove runs, it now closes the associated agent bead (gt--crew-) with reason "Crew workspace removed". This prevents orphaned agent beads in the system after crew removal. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 --- internal/cmd/crew_lifecycle.go | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/internal/cmd/crew_lifecycle.go b/internal/cmd/crew_lifecycle.go index 96f1b33f..d1c57a74 100644 --- a/internal/cmd/crew_lifecycle.go +++ b/internal/cmd/crew_lifecycle.go @@ -3,6 +3,7 @@ package cmd import ( "fmt" "os" + "os/exec" "path/filepath" "strings" "time" @@ -63,6 +64,22 @@ func runCrewRemove(cmd *cobra.Command, args []string) error { fmt.Printf("%s Removed crew workspace: %s/%s\n", style.Bold.Render("✓"), r.Name, name) + + // Close the agent bead if it exists + // Format: gt--crew- (matches session name format) + agentBeadID := fmt.Sprintf("gt-%s-crew-%s", r.Name, name) + closeCmd := exec.Command("bd", "close", agentBeadID, "--reason=Crew workspace removed") + closeCmd.Dir = r.Path // Run from rig directory for proper beads resolution + if output, err := closeCmd.CombinedOutput(); err != nil { + // Non-fatal: bead might not exist or already be closed + if !strings.Contains(string(output), "no issue found") && + !strings.Contains(string(output), "already closed") { + style.PrintWarning("could not close agent bead %s: %v", agentBeadID, err) + } + } else { + fmt.Printf("Closed agent bead: %s\n", agentBeadID) + } + return nil }