{"record":{"id":"30bb2f97981bdabc","repo":"chenhg5/cc-connect","slug":"w-s","errorCode":null,"errorMessage":"%w: %s","messagePattern":"%w: %s","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"agent/tmux/session.go","lineNumber":225,"sourceCode":"}\n\n// tmuxWindowExists checks whether a window or pane target (e.g. \"sess:win\") exists.\nfunc tmuxWindowExists(target string) bool {\n\treturn exec.Command(\"tmux\", \"has-session\", \"-t\", target).Run() == nil\n}\n\n// createTmuxSession creates a new detached tmux session with the given window name.\nfunc createTmuxSession(name, windowName, workDir, shell string) error {\n\targs := []string{\"new-session\", \"-d\", \"-s\", name, \"-n\", windowName}\n\tif workDir != \"\" && workDir != \".\" {\n\t\targs = append(args, \"-c\", workDir)\n\t}\n\tif shell != \"\" {\n\t\targs = append(args, shell)\n\t}\n\tout, err := exec.Command(\"tmux\", args...).CombinedOutput()\n\tif err != nil {\n\t\treturn fmt.Errorf(\"%w: %s\", err, strings.TrimSpace(string(out)))\n\t}\n\t// Enable focus events so Claude Code doesn't warn about them being off.\n\t_ = exec.Command(\"tmux\", \"set-option\", \"-t\", name, \"-g\", \"focus-events\", \"on\").Run()\n\treturn nil\n}\n\n// createTmuxWindow adds a new window to an existing session.\n// Using \"session:\" (trailing colon) tells tmux to pick the next free index,\n// avoiding index collisions when multiple windows are created concurrently.\nfunc createTmuxWindow(session, windowName, workDir string) error {\n\targs := []string{\"new-window\", \"-d\", \"-t\", session + \":\", \"-n\", windowName}\n\tif workDir != \"\" && workDir != \".\" {\n\t\targs = append(args, \"-c\", workDir)\n\t}\n\tout, err := exec.Command(\"tmux\", args...).CombinedOutput()\n\tif err != nil {\n\t\treturn fmt.Errorf(\"%w: %s\", err, strings.TrimSpace(string(out)))\n\t}","sourceCodeStart":207,"sourceCodeEnd":243,"githubUrl":"https://github.com/chenhg5/cc-connect/blob/4000b2338aa6e850c99df54f8b0ed6ed7460b401/agent/tmux/session.go#L207-L243","documentation":"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'.","triggerScenarios":"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.","commonSituations":"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.","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"],"exampleFix":"// before\nagent, err := tmuxAgent.StartSession(ctx, opts) // work_dir: \"/nonexistent\"\n// tmux: create session \"cc\": exit status 1: can't establish current working directory\n\n// after\n// fix config: work_dir = \"/home/user/project\" (must exist)\nagent, err := tmuxAgent.StartSession(ctx, opts)","handlingStrategy":"validation","validationCode":"if _, err := os.Stat(workDir); err != nil { return fmt.Errorf(\"work_dir %q unavailable: %w\", workDir, err) }\nif _, err := exec.LookPath(shellOr(\"bash\")); err != nil { return fmt.Errorf(\"shell %q not in PATH\", shell) }\nif err := exec.Command(\"tmux\", \"has-session\", \"-t\", name).Run(); err == nil { /* already exists; skip create */ }","typeGuard":null,"tryCatchPattern":"if _, err := agent.StartSession(ctx, opts); err != nil {\n    var tmuxErr *exec.ExitError\n    if errors.As(err, &tmuxErr) { slog.Error(\"tmux create failed\", \"stderr\", err.Error()) }\n    return fmt.Errorf(\"start tmux session: %w\", err)\n}","preventionTips":["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"],"tags":["go","tmux","exec","process"],"backgroundTag":"command-execution-failed","analyzedSha":"4000b2338aa6e850c99df54f8b0ed6ed7460b401","analyzedAt":"2026-09-06T11:45:09.575Z","contentChangedAt":"2026-09-06T11:45:09.575Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}