tmux-style commands
btmux supports a subset of tmux commands, including familiar aliases and
flags. Commands target the current pane’s server or, outside btmux, the
running server for --profile. See All commands.
btmux list-panes -F '#{pane_index} #{pane_id} #{pane_current_path}'pane=$(btmux split-window -h -d -c "$PWD")btmux send-keys -t "$pane" 'npm test' Enterbtmux capture-pane -p -t "$pane" -S -200btmux kill-pane -t "$pane"| Command | Flags |
|---|---|
list-sessions (ls) |
-F |
list-windows (lsw) |
-a -t -F |
list-panes (lsp) |
-a -s -t -F |
new-session (new) |
-s -n -c -F |
new-window (neww) |
-t -n -c -d -F -e --keep-open --wait [COMMAND] |
split-window (splitw) |
-t -h -v -b -d -c -F -e --keep-open --wait [COMMAND] |
kill-pane (killp) |
-t |
kill-window (killw) |
-t |
kill-session |
-t |
select-pane (selectp) |
-t |
select-window (selectw) |
-t |
rename-window (renamew) |
-t NAME |
rename-session (rename) |
-t NAME |
send-keys (send) |
-t -l KEY... |
capture-pane (capturep) |
-t -S (-p, -J are implied) |
new-worktree |
-t -d -F BRANCH |
remove-worktree |
-t |
wait-exit |
-t --timeout |
display-popup (popup) |
-t -d -e -T -E; see Popups |
Coding agents learn these commands from the btmux skill; see agent setup.
Differences from tmux
Section titled “Differences from tmux”-ttakes a pane, window, or session ID, orSESSION[:WINDOW[.PANE]]by name or index. An empty part is the current one (:1,:.2,work:). Without-t, the target is the pane the command runs in (BTMUX_PANE_ID). Pane indexes follow the layout, as<prefix> + qshows them.new-session,new-window, andsplit-windowprint the new pane’s ID, as tmux does with-P -F '#{pane_id}'. Sessions are always detached.- List commands print JSON unless given
-F. Formats only substitute#{name}: thesession_,window_, andpane_fields of the JSON, plussession_windowsandwindow_panes. Flags print as1or0. send-keyssends each argument as a key name (Enter,C-c,M-x,Up,F5, …) if it is one, else as text, without spaces between arguments.-lsends them all as text.capture-panealways prints, with wrapped lines joined and no escapes.-S -includes all retained history and-S -Nthe last N rows of it.kill-panecloses the window with its last pane, and the session with its last window, but never the last session.
Running a command and waiting for it
Section titled “Running a command and waiting for it”Scripts and agents can run a command in its own pane and get its exit
status, unlike typing it with send-keys, which can’t tell when it finished.
btmux new-window -d -n tests --wait -- cargo test # exits with the tests' statuspane=$(btmux split-window -h -d --keep-open 'npm run build')btmux wait-exit -t "$pane" --timeout 600 # its status; 124 on timeoutbtmux capture-pane -p -t "$pane" -S - # its output, after it exitsbtmux kill-pane -t "$pane"new-windowandsplit-windowrun COMMAND, the arguments after the flags, instead of the shell. A single argument is a command line for the shell; several run directly. It starts at once, whether or not a client shows the pane, in the current directory unless-csays otherwise, with this shell’s environment plus any-e NAME=VALUE, as popups run. A command that can’t start is an error, and nothing changes.- In a sandboxed session, the command runs in the guest, in the directory asked for, with the guest’s environment rather than this shell’s.
- The pane closes when its program exits. With
--keep-openit stays, with the output and an[exited with status N]line, until you close it; typing into it does nothing. A program that died full-screen is left for the main screen, so its output from before is what shows.list-panesshowspane_deadandpane_dead_statusfor it. --waitprints the pane’s ID, then waits for the program to exit and exits with its status, aswait-exitdoes. It needs COMMAND: a shell only starts once a client shows its pane.wait-exitwaits for the target pane’s program (its command, or its shell) to exit, and exits with its status. A signal N gives 128 + N, and statuses above 255 are reduced modulo 256. It exits 1 if the pane closed before its program reported a status (kill-pane), and 124 if--timeoutseconds pass first. A pane whose shell hasn’t started, as no client showed it, is refused with exit 1.- For a kept pane,
wait-exitreturns once the output has ended and the[exited ...]line is written, socapture-paneright after it sees all of it. If something else, such as a background job, holds the terminal open, that’s at most 2 seconds after the program exits. - A pane that closed in the last 5 minutes still reports its status, so
-ttakes a closed pane’s ID; the server keeps the last 256 of them. A wait already running when its pane closes always gets the status. Waits continue acrossbtmux upgrade, and a kept pane keeps its output and status through one. A restart ends the command: its pane comes back as a shell under a new ID, so a wait across it exits 1.
btmux wait is a different command: it waits for an
agent’s state.
Worktrees
Section titled “Worktrees”new-worktree and remove-worktree follow the same rules as the
worktree key bindings.
new-worktree BRANCHadds a Git worktree for the target pane’s repository and opens a window there, in the pane’s session. It prints the new pane’s ID.remove-worktreeremoves the worktree the target pane is in and closes every pane in it. It prints the worktree’s path.
Shell completions
Section titled “Shell completions”btmux completions <shell> prints a completion script for bash, fish, zsh,
PowerShell, or Elvish. Save it in your shell’s completion directory:
# fishbtmux completions fish > ~/.config/fish/completions/btmux.fish
# zsh: add ~/.zfunc to fpath before compinit runs in ~/.zshrcmkdir -p ~/.zfunc && btmux completions zsh > ~/.zfunc/_btmux
# bashmkdir -p ~/.local/share/bash-completion/completionsbtmux completions bash > ~/.local/share/bash-completion/completions/btmux# PowerShell: load completions from your profileAdd-Content $PROFILE 'btmux completions powershell | Out-String | Invoke-Expression'Regenerate the script after updating btmux. The Home Manager module installs completions itself.