{"record":{"id":"32069d02783aead6","repo":"chenhg5/cc-connect","slug":"tmux-session-q-does-not-exist-and-auto-create-is","errorCode":null,"errorMessage":"tmux: session %q does not exist and auto_create is disabled","messagePattern":"tmux: session %q does not exist and auto_create is disabled","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"agent/tmux/tmux.go","lineNumber":178,"sourceCode":"\n\t// Decide which tmux window this session drives:\n\t//   - window_per_session: a dedicated window per cc-connect session (true\n\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 != \".\" {","sourceCodeStart":160,"sourceCodeEnd":196,"githubUrl":"https://github.com/chenhg5/cc-connect/blob/4000b2338aa6e850c99df54f8b0ed6ed7460b401/agent/tmux/tmux.go#L160-L196","documentation":"StartSession checks tmuxSessionExists before touching tmux and refuses to start when the configured session is absent and the 'auto_create' option is not enabled. The agent attaches to pre-existing tmux sessions by default, so it will not silently create infrastructure the user did not ask for.","triggerScenarios":"StartSession (typically triggered by the first user message routed to the tmux agent) where options.session names a tmux session that does not exist and options.auto_create is false/unset.","commonSituations":"tmux session killed after a reboot or logout (no tmux server running); typo in the session name in config; user forgot to add auto_create = true for an agent meant to own its session.","solutions":["Create the session manually: tmux new-session -d -s <name>","Set auto_create = true in the agent's options so cc-connect creates it","Verify the session name matches: tmux ls","If sessions vanish on reboot, run tmux under a persistent mechanism (systemd user unit with tmux server)"],"exampleFix":"// before (config.toml)\n[agents.options]\nsession = \"cc-work\"\n\n// after\n[agents.options]\nsession = \"cc-work\"\nauto_create = true","handlingStrategy":"validation","validationCode":"exists := exec.Command(\"tmux\", \"has-session\", \"-t\", sessionName).Run() == nil\nif !exists && !autoCreate { /* pre-create or enable auto_create */ }","typeGuard":null,"tryCatchPattern":"if _, err := agent.StartSession(ctx, opts); err != nil && strings.Contains(err.Error(), \"auto_create is disabled\") {\n    return fmt.Errorf(\"run 'tmux new-session -d -s %s' or set auto_create=true\", sessionName)\n}","preventionTips":["Enable auto_create for agents that own their session","Persist tmux sessions across reboots (tmux server under systemd user unit)","Match options.session to output of `tmux ls`","Document required tmux setup in deployment notes"],"tags":["go","tmux","config","lifecycle"],"backgroundTag":"resource-not-found","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"}