{"record":{"id":"0db14145086773ea","repo":"chenhg5/cc-connect","slug":"tmux-create-session-q-w","errorCode":null,"errorMessage":"tmux: create session %q: %w","messagePattern":"tmux: create session %q: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"agent/tmux/tmux.go","lineNumber":181,"sourceCode":"\t//     isolation; each gets its own init_command/agent instance).\n\t//   - else, when workDir is a real path: a window named after the directory\n\t//     so each workspace gets its own instance.\n\t//   - else: the legacy session:pane target.\n\t// windowForSession may allocate a fresh window name when sessionID is empty;\n\t// the returned ID is persisted by the engine so resumes reuse the same window.\n\twindowName, effectiveSessionID := a.windowForSession(sessionName, pane, workDir, sessionID)\n\tsessionID = effectiveSessionID\n\ttarget := sessionName + \":\" + windowName\n\n\tsessionExists := tmuxSessionExists(sessionName)\n\twindowExists := sessionExists && tmuxWindowExists(target)\n\n\tif !sessionExists {\n\t\tif !autoCreate {\n\t\t\treturn nil, fmt.Errorf(\"tmux: session %q does not exist and auto_create is disabled\", sessionName)\n\t\t}\n\t\tif err := createTmuxSession(sessionName, windowName, workDir, shell); err != nil {\n\t\t\treturn nil, fmt.Errorf(\"tmux: create session %q: %w\", sessionName, err)\n\t\t}\n\t\tslog.Info(\"tmux: created session\", \"session\", sessionName, \"window\", windowName, \"work_dir\", workDir)\n\t} else if !windowExists && windowName != pane {\n\t\t// Session exists but this workspace window does not yet — create it.\n\t\tif err := createTmuxWindow(sessionName, windowName, workDir); err != nil {\n\t\t\treturn nil, fmt.Errorf(\"tmux: create window %q in session %q: %w\", windowName, sessionName, err)\n\t\t}\n\t\tslog.Info(\"tmux: created window\", \"session\", sessionName, \"window\", windowName, \"work_dir\", workDir)\n\t}\n\n\tnewPane := !sessionExists || (!windowExists && windowName != pane)\n\tif newPane {\n\t\t// Always cd to the workspace directory so the shell (and any init_command)\n\t\t// starts in the right place, regardless of tmux's -c flag behaviour.\n\t\tif workDir != \"\" && workDir != \".\" {\n\t\t\tif err := sendKeys(target, \"cd \"+shellQuote(workDir)); err != nil {\n\t\t\t\tslog.Warn(\"tmux: cd failed\", \"work_dir\", workDir, \"err\", err)\n\t\t\t}","sourceCodeStart":163,"sourceCodeEnd":199,"githubUrl":"https://github.com/chenhg5/cc-connect/blob/4000b2338aa6e850c99df54f8b0ed6ed7460b401/agent/tmux/tmux.go#L163-L199","documentation":"When the tmux session is missing and auto_create is enabled, StartSession calls createTmuxSession and wraps any underlying failure with 'tmux: create session %q: %w'. This is the intermediate wrap around the raw tmux exec error (errorIndex 350), preserving both the session name and tmux's own output.","triggerScenarios":"auto_create = true, session does not exist, and `tmux new-session` fails: nonexistent work_dir (-c), invalid shell, or tmux server error creating the session.","commonSituations":"work_dir pointing to a directory that does not exist yet (e.g. project not cloned); shell option naming an uninstalled binary; concurrent auto-create of the same session name by two agents.","solutions":["Read the wrapped inner error for tmux's message","Create the work_dir or fix the work_dir value in config","Fix or remove the shell option if it names a missing binary","Create the session manually with tmux new-session -d -s <name> and disable auto_create"],"exampleFix":"// before\n[agents.options]\nsession = \"cc\"\nauto_create = true\nwork_dir = \"/srv/app\" # does not exist\n\n// after\nmkdir -p /srv/app\n# or point work_dir at an existing path\nwork_dir = \"/home/user/app\"","handlingStrategy":"validation","validationCode":"if _, err := os.Stat(workDir); err != nil { return fmt.Errorf(\"auto_create work_dir missing: %w\", err) }\nif shell != \"\" { if _, err := exec.LookPath(shell); err != nil { return err } }","typeGuard":null,"tryCatchPattern":"if _, err := agent.StartSession(ctx, opts); err != nil {\n    var inner error\n    if errors.Unwrap(errors.Unwrap(err)) != nil { inner = errors.Unwrap(errors.Unwrap(err)) }\n    slog.Error(\"tmux auto-create failed\", \"session\", sessionName, \"cause\", inner)\n    return err\n}","preventionTips":["Ensure work_dir exists before enabling auto_create","Verify shell option names an installed binary","Serialize session creation to avoid duplicate-name races","Keep tmux updated to a version supporting all used flags"],"tags":["go","tmux","exec","config"],"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"}