diff --git a/internal/cmd/costs.go b/internal/cmd/costs.go index 7179b177..5e72c684 100644 --- a/internal/cmd/costs.go +++ b/internal/cmd/costs.go @@ -525,6 +525,10 @@ func runCostsRecord(cmd *cobra.Command, args []string) error { // Derive session name from GT_* environment variables session = deriveSessionName() } + if session == "" { + // Try to detect current tmux session (works when running inside tmux) + session = detectCurrentTmuxSession() + } if session == "" { return fmt.Errorf("--session flag required (or set GT_SESSION env var, or GT_RIG/GT_ROLE)") } @@ -649,6 +653,28 @@ func deriveSessionName() string { return "" } +// detectCurrentTmuxSession returns the current tmux session name if running inside tmux. +// Uses `tmux display-message -p '#S'` which prints the session name. +func detectCurrentTmuxSession() string { + // Check if we're inside tmux + if os.Getenv("TMUX") == "" { + return "" + } + + cmd := exec.Command("tmux", "display-message", "-p", "#S") + output, err := cmd.Output() + if err != nil { + return "" + } + + session := strings.TrimSpace(string(output)) + // Only return if it looks like a Gas Town session + if strings.HasPrefix(session, constants.SessionPrefix) { + return session + } + return "" +} + // buildAgentPath builds the agent path from role, rig, and worker. // Examples: "mayor", "gastown/witness", "gastown/polecats/toast" func buildAgentPath(role, rig, worker string) string {