{"record":{"id":"5d6bbd293d9c6365","repo":"nikivdev/code","slug":"tmux-exited-with-status-while-attempting-to-co","errorCode":null,"errorMessage":"tmux exited with status {} while attempting to {context}","messagePattern":"tmux exited with status (.+?) while attempting to (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/terminal.rs","lineNumber":220,"sourceCode":"    }\n\n    fs::write(conf_path, rendered).with_context(|| {\n        format!(\n            \"failed to write fish tracing hooks to {}\",\n            conf_path.display()\n        )\n    })\n}\n\nfn run_tmux(args: &[&str], context: &str) -> Result<()> {\n    let status = Command::new(\"tmux\")\n        .args(args)\n        .status()\n        .with_context(|| format!(\"failed to execute tmux to {context}\"))?;\n    if status.success() {\n        Ok(())\n    } else {\n        bail!(\n            \"tmux exited with status {} while attempting to {context}\",\n            status.code().unwrap_or(-1)\n        );\n    }\n}\n\nfn sh_quote(path: &Path) -> String {\n    let value = path.to_string_lossy();\n    let escaped = value.replace('\\'', r\"'\\''\");\n    format!(\"'{escaped}'\")\n}\n\nfn home_dir() -> PathBuf {\n    env::var_os(\"HOME\")\n        .map(PathBuf::from)\n        .unwrap_or_else(|| PathBuf::from(\".\"))\n}\n","sourceCodeStart":202,"sourceCodeEnd":238,"githubUrl":"https://github.com/nikivdev/code/blob/a747e741ae92c09071d0ae946ab48488adcff1ce/src/terminal.rs#L202-L238","documentation":"This error is raised by run_tmux (src/terminal.rs:220) after spawning a tmux subprocess that terminates with a non-zero exit code. The library wraps tmux invocations for logging/hooks setup and converts any tmux failure into a bail! with the numeric exit status and the operation context (e.g. what it was attempting to do).","triggerScenarios":"run_tmux is called by enforce_tmux_logging, install_hooks, and prime_existing_panes; the error fires whenever the spawned `tmux` command (e.g. tmux set-option, tmux list-panes, tmux send-keys) exits non-zero — tmux not running (no server/session), invalid tmux options, or a tmux binary that exists but fails at runtime. The exit status is status.code().unwrap_or(-1), so -1 means tmux was killed by a signal.","commonSituations":"Running f commands outside a tmux session where the target socket/server does not exist; a tmux version that lacks the option being set; $TMUX or socket path misconfigured; tmux server crashed mid-command (exit code -1).","solutions":["Verify tmux is installed and a server is running (`tmux ls`); start a session before running the command.","Run the failing tmux command manually with the same args to see tmux's own stderr for the real cause.","Check your tmux version supports the options this tool sets (`tmux -V`).","If status is -1, tmux was killed by a signal — check dmesg/ulimits."],"exampleFix":"// before: blind call\nf hook install\n// after: pre-check tmux availability\nif !Command::new(\"tmux\").args([\"ls\"]).status().map(|s| s.success()).unwrap_or(false) {\n    eprintln!(\"start tmux first\");\n    return;\n}","handlingStrategy":"try-catch","validationCode":"// check tmux availability before invoking the tool\nuse std::process::Command;\nlet tmux_ok = Command::new(\"tmux\").arg(\"ls\").status().map(|s| s.success()).unwrap_or(false);\nif !tmux_ok { eprintln!(\"tmux is not available/running\"); }","typeGuard":null,"tryCatchPattern":"match result {\n    Err(e) if e.to_string().contains(\"tmux exited with status\") => {\n        eprintln!(\"tmux operation failed: {e:#}; check `tmux ls` and tmux version\");\n    }\n    Err(e) => return Err(e),\n    Ok(v) => v,\n}","preventionTips":["Always run inside or alongside an active tmux server (`tmux ls` first).","Pin a reasonably recent tmux version in your environment.","Wrap the call in a context that logs the exit code for triage.","Treat exit code -1 (signal) as an environment crash, not a tooling bug."],"tags":["tmux","subprocess","exit-code"],"backgroundTag":"subprocess-nonzero-exit","analyzedSha":"a747e741ae92c09071d0ae946ab48488adcff1ce","analyzedAt":"2026-09-01T22:43:55.719Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}