chenhg5/cc-connect · error
tmux: create window %q in session %q: %w
Error message
tmux: create window %q in session %q: %w
What it means
When the tmux session exists but the workspace window does not (and windowName != pane), StartSession calls createTmuxWindow and wraps failures as 'tmux: create window %q in session %q: %w'. It is the session-level wrap around the raw `tmux new-window` exec error (errorIndex 351).
Source
Thrown at agent/tmux/tmux.go:187
windowName, effectiveSessionID := a.windowForSession(sessionName, pane, workDir, sessionID)
sessionID = effectiveSessionID
target := sessionName + ":" + windowName
sessionExists := tmuxSessionExists(sessionName)
windowExists := sessionExists && tmuxWindowExists(target)
if !sessionExists {
if !autoCreate {
return nil, fmt.Errorf("tmux: session %q does not exist and auto_create is disabled", sessionName)
}
if err := createTmuxSession(sessionName, windowName, workDir, shell); err != nil {
return nil, fmt.Errorf("tmux: create session %q: %w", sessionName, err)
}
slog.Info("tmux: created session", "session", sessionName, "window", windowName, "work_dir", workDir)
} else if !windowExists && windowName != pane {
// Session exists but this workspace window does not yet — create it.
if err := createTmuxWindow(sessionName, windowName, workDir); err != nil {
return nil, fmt.Errorf("tmux: create window %q in session %q: %w", windowName, sessionName, err)
}
slog.Info("tmux: created window", "session", sessionName, "window", windowName, "work_dir", workDir)
}
newPane := !sessionExists || (!windowExists && windowName != pane)
if newPane {
// Always cd to the workspace directory so the shell (and any init_command)
// starts in the right place, regardless of tmux's -c flag behaviour.
if workDir != "" && workDir != "." {
if err := sendKeys(target, "cd "+shellQuote(workDir)); err != nil {
slog.Warn("tmux: cd failed", "work_dir", workDir, "err", err)
}
}
if initCmd != "" {
if err := sendKeys(target, initCmd); err != nil {
slog.Warn("tmux: init_command failed", "cmd", initCmd, "err", err)
} else {
slog.Info("tmux: init_command sent", "cmd", initCmd, "target", target)View on GitHub (pinned to 4000b2338a)
Solutions
- Check the inner tmux output for the concrete cause
- Ensure work_dir for the workspace exists
- Confirm the session still exists (tmux has-session -t <name>) and retry
- Create the window manually: tmux new-window -d -t <session>: -n <name> -c <dir>
Example fix
// before # work_dir deleted -> new-window fails // tmux: create window "feature-x" in session "cc": exit status 1: can't set working directory // after mkdir -p /home/user/feature-x # retry StartSession
Defensive patterns
Strategy: retry
Validate before calling
if !exec.Command("tmux","has-session","-t",sessionName).Run() == nil { /* recreate session first */ }
if _, err := os.Stat(workDir); err != nil { return err } Try / catch
sess, err := agent.StartSession(ctx, opts)
if err != nil && strings.Contains(err.Error(), "create window") {
time.Sleep(200 * time.Millisecond)
sess, err = agent.StartSession(ctx, opts) // re-checks existence
} Prevention
- Retry StartSession once on window-create failures (handles races)
- Keep per-workspace work_dir valid and existing
- Avoid killing tmux sessions externally while agents run
- Use simple window names without target-syntax characters
When it happens
Trigger: StartSession against an existing tmux session with window_per_session style layout, where `tmux new-window -d` fails: bad -c workDir, malformed target, or the session dying between the has-session check and the call.
Common situations: Multiple workspaces sharing one tmux session with an invalid work_dir for a new workspace; session killed by another client in a race; window-name/target syntax issues from unusual characters.
Related errors
- %w: %s
- tmux: session %q does not exist and auto_create is disabled
- tmux: create session %q: %w
- antigravitySession: start: %w
- codex app-server start: %w
AI-assisted analysis of chenhg5/cc-connect@4000b2338a (2026-09-06).
Data as JSON: /api/errors/2379c871fdbd1efc.
Report an issue: GitHub.