chenhg5/cc-connect · error
%w: %s
Error message
%w: %s
What it means
createTmuxSession runs `tmux new-session` via exec.Command and, when tmux exits non-zero, wraps the combined stdout/stderr output into the returned error. This surfaces any tmux-level failure (bad session name, working dir missing, shell not found, server not running) together with tmux's own diagnostic text. The caller (StartSession) further wraps it as 'tmux: create session %q: %w'.
Source
Thrown at agent/tmux/session.go:225
}
// tmuxWindowExists checks whether a window or pane target (e.g. "sess:win") exists.
func tmuxWindowExists(target string) bool {
return exec.Command("tmux", "has-session", "-t", target).Run() == nil
}
// createTmuxSession creates a new detached tmux session with the given window name.
func createTmuxSession(name, windowName, workDir, shell string) error {
args := []string{"new-session", "-d", "-s", name, "-n", windowName}
if workDir != "" && workDir != "." {
args = append(args, "-c", workDir)
}
if shell != "" {
args = append(args, shell)
}
out, err := exec.Command("tmux", args...).CombinedOutput()
if err != nil {
return fmt.Errorf("%w: %s", err, strings.TrimSpace(string(out)))
}
// Enable focus events so Claude Code doesn't warn about them being off.
_ = exec.Command("tmux", "set-option", "-t", name, "-g", "focus-events", "on").Run()
return nil
}
// createTmuxWindow adds a new window to an existing session.
// Using "session:" (trailing colon) tells tmux to pick the next free index,
// avoiding index collisions when multiple windows are created concurrently.
func createTmuxWindow(session, windowName, workDir string) error {
args := []string{"new-window", "-d", "-t", session + ":", "-n", windowName}
if workDir != "" && workDir != "." {
args = append(args, "-c", workDir)
}
out, err := exec.Command("tmux", args...).CombinedOutput()
if err != nil {
return fmt.Errorf("%w: %s", err, strings.TrimSpace(string(out)))
}View on GitHub (pinned to 4000b2338a)
Solutions
- Check the tmux error text appended after '%w: %s' — it names the exact tmux failure
- Verify the work_dir passed in the config exists and is writable
- Verify the configured shell binary exists in PATH
- Run `tmux new-session -t <name>` manually to reproduce and see tmux's message
- Update tmux if the error mentions an unknown option/flag
Example fix
// before agent, err := tmuxAgent.StartSession(ctx, opts) // work_dir: "/nonexistent" // tmux: create session "cc": exit status 1: can't establish current working directory // after // fix config: work_dir = "/home/user/project" (must exist) agent, err := tmuxAgent.StartSession(ctx, opts)
Defensive patterns
Strategy: validation
Validate before calling
if _, err := os.Stat(workDir); err != nil { return fmt.Errorf("work_dir %q unavailable: %w", workDir, err) }
if _, err := exec.LookPath(shellOr("bash")); err != nil { return fmt.Errorf("shell %q not in PATH", shell) }
if err := exec.Command("tmux", "has-session", "-t", name).Run(); err == nil { /* already exists; skip create */ } Try / catch
if _, err := agent.StartSession(ctx, opts); err != nil {
var tmuxErr *exec.ExitError
if errors.As(err, &tmuxErr) { slog.Error("tmux create failed", "stderr", err.Error()) }
return fmt.Errorf("start tmux session: %w", err)
} Prevention
- Validate work_dir exists before configuring the agent
- Pin tmux version and verify flags with `tmux -V`
- Avoid concurrent auto-create of the same session name
- Log tmux's combined output for diagnosis
When it happens
Trigger: Calling StartSession with auto_create enabled when the tmux session does not exist and `tmux new-session` fails: e.g. workDir does not exist (-c path invalid), the configured shell is not an executable, duplicate session name due to a race, or tmux server errors.
Common situations: Typo in the agent's work_dir config so `-c` points to a nonexistent directory; shell option set to a binary not installed; tmux version too old for a flag used; two sessions auto-creating the same tmux session name concurrently.
Related errors
- antigravitySession: start: %w
- copilot probe: start: %w
- qoderSession: start: %w
- tmux: create session %q: %w
- tmux: create window %q in session %q: %w
AI-assisted analysis of chenhg5/cc-connect@4000b2338a (2026-09-06).
Data as JSON: /api/errors/30bb2f97981bdabc.
Report an issue: GitHub.