nikivdev/code · error
tmux exited with status {} while attempting to {context}
Error message
tmux exited with status {} while attempting to {context} What it means
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).
Source
Thrown at src/terminal.rs:220
}
fs::write(conf_path, rendered).with_context(|| {
format!(
"failed to write fish tracing hooks to {}",
conf_path.display()
)
})
}
fn run_tmux(args: &[&str], context: &str) -> Result<()> {
let status = Command::new("tmux")
.args(args)
.status()
.with_context(|| format!("failed to execute tmux to {context}"))?;
if status.success() {
Ok(())
} else {
bail!(
"tmux exited with status {} while attempting to {context}",
status.code().unwrap_or(-1)
);
}
}
fn sh_quote(path: &Path) -> String {
let value = path.to_string_lossy();
let escaped = value.replace('\'', r"'\''");
format!("'{escaped}'")
}
fn home_dir() -> PathBuf {
env::var_os("HOME")
.map(PathBuf::from)
.unwrap_or_else(|| PathBuf::from("."))
}
View on GitHub (pinned to a747e741ae)
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.
Example fix
// before: blind call
f hook install
// after: pre-check tmux availability
if !Command::new("tmux").args(["ls"]).status().map(|s| s.success()).unwrap_or(false) {
eprintln!("start tmux first");
return;
} Defensive patterns
Strategy: try-catch
Validate before calling
// check tmux availability before invoking the tool
use std::process::Command;
let tmux_ok = Command::new("tmux").arg("ls").status().map(|s| s.success()).unwrap_or(false);
if !tmux_ok { eprintln!("tmux is not available/running"); } Try / catch
match result {
Err(e) if e.to_string().contains("tmux exited with status") => {
eprintln!("tmux operation failed: {e:#}; check `tmux ls` and tmux version");
}
Err(e) => return Err(e),
Ok(v) => v,
} Prevention
- 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.
When it happens
Trigger: 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.
Common situations: 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).
Related errors
- Lin.app is not running
- Agent exited with status: {}
- gen exited with status: {}
- {} exited with {}
- Claude review failed
AI-assisted analysis of nikivdev/code@a747e741ae (2026-09-01).
Data as JSON: /api/errors/5d6bbd293d9c6365.
Report an issue: GitHub.