Skip to content

Commit ea5d72a

Browse files
steveyeggeclaude
andcommitted
feat(crew): add --debug flag to crew at command
Add --debug flag for troubleshooting crew attach issues. Shows: - Current working directory - Detected rig and crew name - Computed session ID - Whether inside tmux - Which session we are attaching to Also adds Attaching to session message before attach. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
1 parent cdea53e commit ea5d72a

2 files changed

Lines changed: 31 additions & 3 deletions

File tree

internal/cmd/crew.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ var (
2121
crewAll bool
2222
crewListAll bool
2323
crewDryRun bool
24+
crewDebug bool
2425
)
2526

2627
var crewCmd = &cobra.Command{
@@ -333,6 +334,7 @@ func init() {
333334
crewAtCmd.Flags().BoolVarP(&crewDetached, "detached", "d", false, "Start session without attaching")
334335
crewAtCmd.Flags().StringVar(&crewAccount, "account", "", "Claude Code account handle to use (overrides default)")
335336
crewAtCmd.Flags().StringVar(&crewAgentOverride, "agent", "", "Agent alias to run crew worker with (overrides rig/town default)")
337+
crewAtCmd.Flags().BoolVar(&crewDebug, "debug", false, "Show debug output for troubleshooting")
336338

337339
crewRemoveCmd.Flags().StringVar(&crewRig, "rig", "", "Rig to use")
338340
crewRemoveCmd.Flags().BoolVar(&crewForce, "force", false, "Force remove (skip safety checks)")

internal/cmd/crew_at.go

Lines changed: 29 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package cmd
22

33
import (
44
"fmt"
5+
"os"
56

67
"github.com/spf13/cobra"
78
"github.com/steveyegge/gastown/internal/beads"
@@ -18,6 +19,13 @@ import (
1819
func runCrewAt(cmd *cobra.Command, args []string) error {
1920
var name string
2021

22+
// Debug mode: --debug flag or GT_DEBUG env var
23+
debug := crewDebug || os.Getenv("GT_DEBUG") != ""
24+
if debug {
25+
cwd, _ := os.Getwd()
26+
fmt.Printf("[DEBUG] runCrewAt: args=%v, crewRig=%q, cwd=%q\n", args, crewRig, cwd)
27+
}
28+
2129
// Determine crew name: from arg, or auto-detect from cwd
2230
if len(args) > 0 {
2331
name = args[0]
@@ -53,6 +61,10 @@ func runCrewAt(cmd *cobra.Command, args []string) error {
5361
fmt.Printf("Detected crew workspace: %s/%s\n", detected.rigName, name)
5462
}
5563

64+
if debug {
65+
fmt.Printf("[DEBUG] after detection: name=%q, crewRig=%q\n", name, crewRig)
66+
}
67+
5668
crewMgr, r, err := getCrewManager(crewRig)
5769
if err != nil {
5870
return err
@@ -96,10 +108,16 @@ func runCrewAt(cmd *cobra.Command, args []string) error {
96108
// Check if session exists
97109
t := tmux.NewTmux()
98110
sessionID := crewSessionName(r.Name, name)
111+
if debug {
112+
fmt.Printf("[DEBUG] sessionID=%q (r.Name=%q, name=%q)\n", sessionID, r.Name, name)
113+
}
99114
hasSession, err := t.HasSession(sessionID)
100115
if err != nil {
101116
return fmt.Errorf("checking session: %w", err)
102117
}
118+
if debug {
119+
fmt.Printf("[DEBUG] hasSession=%v\n", hasSession)
120+
}
103121

104122
// Before creating a new session, check if there's already a runtime session
105123
// running in this crew's directory (might have been started manually or via
@@ -258,8 +276,12 @@ func runCrewAt(cmd *cobra.Command, args []string) error {
258276
}
259277

260278
// If inside tmux (but different session), don't switch - just inform user
261-
if tmux.IsInsideTmux() {
262-
fmt.Printf("Started %s/%s. Use C-b s to switch.\n", r.Name, name)
279+
insideTmux := tmux.IsInsideTmux()
280+
if debug {
281+
fmt.Printf("[DEBUG] tmux.IsInsideTmux()=%v\n", insideTmux)
282+
}
283+
if insideTmux {
284+
fmt.Printf("Session %s ready. Use C-b s to switch.\n", sessionID)
263285
return nil
264286
}
265287

@@ -269,6 +291,10 @@ func runCrewAt(cmd *cobra.Command, args []string) error {
269291
return nil
270292
}
271293

272-
// Attach to session
294+
// Attach to session - show which session we're attaching to
295+
fmt.Printf("Attaching to %s...\n", sessionID)
296+
if debug {
297+
fmt.Printf("[DEBUG] calling attachToTmuxSession(%q)\n", sessionID)
298+
}
273299
return attachToTmuxSession(sessionID)
274300
}

0 commit comments

Comments
 (0)