{"record":{"id":"589ec43d80bf34ee","repo":"Hmbown/CodeWhale","slug":"failed-to-run-tmux-load-buffer-w-e","errorCode":null,"errorMessage":"Failed to run tmux load-buffer -w: {e}","messagePattern":"Failed to run tmux load-buffer -w: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/tui/src/tui/clipboard.rs","lineNumber":781,"sourceCode":"#[cfg(not(test))]\nfn write_text_with_tmux(text: &str) -> Result<()> {\n    write_text_with_tmux_using_argv(\"tmux\", &[], text)\n}\n\n/// Ask tmux to set both its paste buffer and the attached client's clipboard.\n/// Unlike DCS passthrough, `load-buffer -w` works with tmux's default\n/// `allow-passthrough off` policy and returns a non-zero status when tmux\n/// cannot honor the command.\n#[cfg(any(not(test), all(test, unix)))]\nfn write_text_with_tmux_using_argv(program: &str, prefix_args: &[&str], text: &str) -> Result<()> {\n    let mut child = Command::new(program)\n        .args(prefix_args)\n        .args([\"load-buffer\", \"-w\", \"-\"])\n        .stdin(Stdio::piped())\n        .stdout(Stdio::null())\n        .stderr(Stdio::piped())\n        .spawn()\n        .map_err(|e| anyhow::anyhow!(\"Failed to run tmux load-buffer -w: {e}\"))?;\n\n    let write_result = child\n        .stdin\n        .take()\n        .context(\"open tmux clipboard input\")\n        .and_then(|mut stdin| {\n            stdin\n                .write_all(text.as_bytes())\n                .context(\"write tmux clipboard input\")\n        });\n    let output = child\n        .wait_with_output()\n        .context(\"wait for tmux load-buffer -w\")?;\n    write_result?;\n    if !output.status.success() {\n        let detail = String::from_utf8_lossy(&output.stderr);\n        let detail = detail.trim();\n        if detail.is_empty() {","sourceCodeStart":763,"sourceCodeEnd":799,"githubUrl":"https://github.com/Hmbown/CodeWhale/blob/433685b2024e7bc4c99e1e2e326bcad39b4d9d65/crates/tui/src/tui/clipboard.rs#L763-L799","documentation":"This error is raised when the TUI fails to spawn the `tmux load-buffer -w -` child process, which is how clipboard writes are pushed into tmux's paste buffer (and, via -w, the attached terminal's clipboard). The `e` in the message is the OS-level spawn error from `Command::spawn`, so the message reflects why the process could not be started at all — not why it exited later (spawn failures and nonzero exits are distinct branches in `write_text_with_tmux_using_argv`). It is thrown eagerly at spawn time so callers can fall back to OSC 52 or other clipboard transports.","triggerScenarios":"Calling `write_text_with_tmux` (or the test-visible `write_text_with_tmux_using_argv`) while `tmux` cannot be spawned: the binary is not on PATH (ENOENT), the user lacks execute permission (EACCES), or resource limits (fork/ENOMEM, EAGAIN too many processes) prevent `Command::new(\"tmux\").args([\"load-buffer\",\"-w\",\"-\"]).spawn()` from succeeding.","commonSituations":"Running the TUI inside a tmux session where the tmux binary was removed or the PATH differs from the login shell (e.g. minimal systemd user PATH, Nix/venv shells missing /usr/bin); containers or chroots without tmux installed while $TMUX is set so the code still takes the tmux path; restricted environments with process-count limits (RLIMIT_NPROC) blocking fork.","solutions":["Install tmux or ensure it is on PATH for the process running the TUI: run `command -v tmux` in the same shell, and fix PATH so the binary resolves.","If tmux is installed but not executable for this user, fix permissions (`chmod +x $(command -v tmux)`) or reinstall the package.","Check resource limits (`ulimit -u`) and reduce process usage if fork fails with EAGAIN.","If tmux genuinely cannot be used, exit the tmux session so the code falls back to the OSC 52 clipboard path instead."],"exampleFix":"// before: tmux missing from the process's PATH\n$ echo $TMUX set, but `command -v tmux` -> not found\n// after\nexport PATH=\"$PATH:/usr/bin\"  # or install tmux: apt install tmux / nix-env -iA nixpkgs.tmux","handlingStrategy":"fallback","validationCode":"fn tmux_available() -> bool {\n    std::process::Command::new(\"tmux\")\n        .arg(\"-V\")\n        .stdout(std::process::Stdio::null())\n        .stderr(std::process::Stdio::null())\n        .status()\n        .map(|s| s.success())\n        .unwrap_or(false)\n}\n// call before requesting a tmux clipboard write:\nlet use_tmux = std::env::var_os(\"TMUX\").is_some() && tmux_available();","typeGuard":null,"tryCatchPattern":"match write_text_with_tmux(text) {\n    Ok(()) => {}\n    Err(e) if e.to_string().contains(\"Failed to run tmux load-buffer -w\") => {\n        // spawn-level failure: fall back to OSC 52\n        write_text_with_osc52(text)?;\n    }\n    Err(e) => return Err(e),\n}","preventionTips":["Check `std::env::var_os(\"TMUX\")` and `tmux -V` availability before choosing the tmux transport.","Keep tmux on PATH in minimal/container environments where the TUI runs.","Fall back to OSC 52 clipboard output when the tmux binary cannot be spawned."],"tags":["tmux","clipboard","process-spawn","command-not-found"],"backgroundTag":"command-not-found","analyzedSha":"433685b2024e7bc4c99e1e2e326bcad39b4d9d65","analyzedAt":"2026-09-15T12:24:24.634Z","contentChangedAt":"2026-09-15T12:24:24.634Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}