Hmbown/CodeWhale · error · anyhow::Error

Failed to run tmux load-buffer -w: {e}

Error message

Failed to run tmux load-buffer -w: {e}

What it means

Spawn of `tmux load-buffer -w -` failed while writing the clipboard through tmux (chosen when the TMUX env var is set). load-buffer -w sets both the tmux paste buffer and the attached client's clipboard and works with tmux's default allow-passthrough off. This spawn error means the tmux binary itself could not be executed - not that tmux refused the command (non-zero exit is a separate bail carrying stderr detail).

Source

Thrown at crates/tui/src/tui/clipboard.rs:626

#[cfg(not(test))]
fn write_text_with_tmux(text: &str) -> Result<()> {
    write_text_with_tmux_using_argv("tmux", &[], text)
}

/// Ask tmux to set both its paste buffer and the attached client's clipboard.
/// Unlike DCS passthrough, `load-buffer -w` works with tmux's default
/// `allow-passthrough off` policy and returns a non-zero status when tmux
/// cannot honor the command.
#[cfg(any(not(test), all(test, unix)))]
fn write_text_with_tmux_using_argv(program: &str, prefix_args: &[&str], text: &str) -> Result<()> {
    let mut child = Command::new(program)
        .args(prefix_args)
        .args(["load-buffer", "-w", "-"])
        .stdin(Stdio::piped())
        .stdout(Stdio::null())
        .stderr(Stdio::piped())
        .spawn()
        .map_err(|e| anyhow::anyhow!("Failed to run tmux load-buffer -w: {e}"))?;

    let write_result = child
        .stdin
        .take()
        .context("open tmux clipboard input")
        .and_then(|mut stdin| {
            stdin
                .write_all(text.as_bytes())
                .context("write tmux clipboard input")
        });
    let output = child
        .wait_with_output()
        .context("wait for tmux load-buffer -w")?;
    write_result?;
    if !output.status.success() {
        let detail = String::from_utf8_lossy(&output.stderr);
        let detail = detail.trim();
        if detail.is_empty() {

View on GitHub (pinned to 0c42157ee5)

Solutions

  1. Run `command -v tmux` in the TUI's environment; fix PATH if it does not resolve
  2. If you are not actually inside tmux, `unset TMUX` so the OSC 52 path is used
  3. Install tmux or point the environment at its real location

Example fix

# before: TMUX leaked into a container
docker run -e TMUX=/tmp/tmux-1000/default … codewhale tui
# -> Failed to run tmux load-buffer -w: No such file or directory

# after: drop the leaked variable
docker run -e TMUX= … codewhale tui   # OSC 52 path instead
Defensive patterns

Strategy: validation

Validate before calling

// Rust - verify tmux is actually reachable when TMUX is set
fn tmux_transport_usable(in_tmux: bool) -> bool {
    !in_tmux || which::which("tmux").is_ok()
}

Try / catch

if tmux_transport_usable(ctx.in_tmux) { enqueue_terminal_write(text)?; } else { bail!("tmux transport unavailable"); }

Prevention

When it happens

Trigger: in_tmux detection is true (TMUX env var set) but Command::new("tmux").spawn() fails: tmux missing from PATH in the TUI's environment, not executable, or the env var leaked into a container/namespace where tmux does not exist.

Common situations: Containers inheriting TMUX from the host; NixOS/Guix-style nonstandard PATH; TUI launched from a service with minimal PATH; tmux uninstalled while session variables persisted.

Related errors


AI-assisted analysis of Hmbown/CodeWhale@0c42157ee5 (2026-08-20). Data as JSON: /api/errors/589ec43d80bf34ee. Report an issue: GitHub.