Guides · September 2026
tmux cheatsheet: sessions, windows, panes
92 commands and the fixes for the messages tmux prints — every one checked against the man page, with a filter box and a copy button each.
One server, sessions, windows, panes — and a prefix.
tmux is a terminal multiplexer: one program that holds many terminals and shows you some of them. The shape is a tree. A single server process runs per user; it manages sessions; each session has windows (tabs, in effect); each window is split into panes, and every pane is a real terminal with its own shell. Your terminal emulator is only a client looking at one session. Close it, lose the SSH connection, walk away: the server and everything in it keep running, and tmux attach puts you back where you were.
You talk to tmux with a prefix key — C-b by default, Ctrl and b together, released — followed by one command key, or with commands typed at a shell (tmux …) or at tmux’s own prompt (C-b :). The key bindings and the commands are the same operations; the cheatsheet lists both wherever both exist.
$ tmux new -A -s work # start it, or attach if it exists
C-b d # detach; the session keeps running
$ tmux ls # what is running under your user
tmux sessions: new, attach, detach, list, rename, kill.
A session is a set of windows kept alive by one tmux server. Detaching leaves it running; attaching picks it up from any terminal — as long as the server process is still there.
Start tmux — a new session with one window
Attaches you to the new session at once. Its name is a number; give it a real one with
-s.tmux
Start a named session
newis the alias ofnew-session. The name is what every later-ttarget andtmux lsline uses.tmux new -s work
Start a session in the background, running a command
-dcreates it detached, so this works from scripts and cron; the command runs in the first window.tmux new -d -s build 'make -j8'
Attach to the most recent session
tmux aalso works — tmux accepts the shortest unambiguous form of any command.tmux attach
Attach to a session by name
tmux attach -t work
Attach, or create it if it doesn’t exist
-Amakes new-session behave like attach-session when the name already exists. The one-liner for a login script.tmux new -A -s work
Attach and kick every other client off
-ddetaches the other clients. The fix for a session that renders tiny because a terminal somewhere else is still attached.tmux attach -d -t work
Detach from the session
C-b dThe session keeps running on the server; you can close the terminal, drop the SSH connection, go home.
tmux detach
List sessions
Alias of
list-sessions. With no server running it says so — see troubleshooting.tmux ls
Check whether a session exists (for scripts)
Exit status 0 if it exists, 1 if not. Quiet enough for a shell
if; redirect stderr to lose the message.tmux has -t work
Rename the current session
C-b $renameis the alias ofrename-session;-tpicks the session to rename.tmux rename -t 0 work
Switch to another session while attached
C-b sC-b (C-b )C-b LC-b sopens a chooser;(and)step to the previous and next session;Lgoes back to the last one.tmux switch-client -t work
Kill one session
Closes its windows and detaches its clients. Other sessions are untouched.
tmux kill-session -t work
Kill every session except one
-ainverts the target: everything butworkgoes.tmux kill-session -a -t work
Kill all sessions
Kills the server, and with it every session and client. The one-line answer to “kill all tmux sessions”. There is no undo.
tmux kill-server
Exit tmux for good
C-dTyping
exitin the last shell closes its window; when the last window of the last session closes, the server exits on its own.exit
tmux windows.
A window fills the screen and belongs to a session; the status line lists them by index. Think tabs.
New window
C-b c-nnames it. Without a name the status line shows the running program.tmux neww -n logs
New window in a directory, running a command
tmux neww -c ~/proj -n dev 'npm run dev'
Next or previous window
C-b nC-b pC-b ltmux prevgoes the other way;C-b l(tmux last) goes back to the window you came from.M-nandM-pafter the prefix jump to the next window with activity or a bell.tmux next
Jump to a window by number
C-b 0 … C-b 9Past nine,
C-b 'prompts for an index.tmux selectw -t 2
Rename the window
C-b ,tmux renamew logs
Choose a session, window, or pane from a tree
C-b wEverything on the server in one list; Enter jumps to it.
tmux choose-tree
Move the window to another index
C-b .Errors if the index is taken;
-kreplaces whatever is there.tmux movew -t 0
Renumber windows to close the gaps
Respects
base-index. To have it happen every time a window closes, setrenumber-windows on(below).tmux movew -r
Kill the window
C-b &The key binding asks for confirmation; the command doesn’t.
killw -akills every window but this one.tmux killw -t logs
tmux panes: split, navigate, resize, zoom, swap, break and join.
A pane is a slice of a window, and each one is its own terminal. Splits, sizes, and layouts are per window.
Split left and right
C-b %-his what tmux calls a horizontal split: the new pane appears beside the current one.tmux splitw -h
Split top and bottom
C-b "-vis the default when neither flag is given.tmux splitw -v
Split with a size, or on the other side
-ltakes lines or columns, or a percentage of the space.-bputs the new pane to the left of, or above, the current one;-c ~/projstarts it in a directory, and a trailing'tail -f app.log'runs a command instead of a shell.tmux splitw -h -l 30%
Make splits open in the current pane’s directory
For .tmux.conf. By default a new pane starts where the session started, not where you are.
bind '"' splitw -v -c "#{pane_current_path}" bind % splitw -h -c "#{pane_current_path}"Move between panes
C-b ← ↑ → ↓-L -R -U -Dpick a direction;-t 2picks a pane by number.tmux selectp -L
Cycle panes, or go back to the last one
C-b oC-b ;tmux lastp
Show pane numbers, then jump to one
C-b q, then a digitThe numbers stay up for
display-panes-timemilliseconds; pressing one runsselect-paneon it.tmux displayp
Resize a pane
C-b C-← … (one cell)C-b M-← … (five)-U -D -L -Rwith a count;-x 50%or-y 20set an absolute size in cells or percent.tmux resizep -L 10
Zoom a pane to fill the window (toggle)
C-b ztmux resizep -Z
Swap with the previous or next pane
C-b {C-b }-Dswaps downward. Mark a pane first withC-b mand it becomes the source.tmux swapp -U
Cycle through the preset layouts
C-b SpacePresets: even-horizontal, even-vertical, main-horizontal, main-vertical, tiled — also on
C-b M-1toM-5.tmux selectl tiled
Break a pane out into its own window
C-b !tmux breakp
Join a pane from another window
Moves window 2’s active pane into the current window, below the current pane;
-hputs it beside. The reverse ofbreak-pane.tmux joinp -s :2
Mark a pane, then join it wherever you are
C-b mWith
-somitted,join-pane,swap-paneandmove-paneuse the marked pane.C-b Mclears the mark.tmux joinp
Kill the pane
C-b x-akills every other pane in the window instead.tmux killp
Type into every pane at once
A window option;
offto stop. The same command on four servers, once.tmux setw synchronize-panes on
Keep a pane after its command exits, then restart it
The pane shows “Pane is dead” instead of vanishing.
respawn-panereruns its original command;-kkills anything still there.tmux setw remain-on-exit on tmux respawnp -k
tmux copy mode and scrollback.
History lives in copy mode: enter it, move, select, copy. Text goes to tmux’s own paste buffers unless you tell it otherwise.
Enter copy mode (scroll back)
C-b [C-b PageUpenters it already scrolled up one page.tmux copy-mode
Leave copy mode
qEscape (emacs)-Xsends a copy-mode command to the pane, which is how the key tables are built.tmux send-keys -X cancel
Page up and down
PageUpPageDownvi adds C-b, C-fHalf pages:
C-uandC-din vi mode,M-UpandM-Downin emacs mode.tmux send-keys -X page-up
Top or bottom of the history
gG (vi)M-<M-> (emacs)tmux send-keys -X history-top
Search backwards or forwards
?/ (vi)C-rC-s (emacs)nrepeats the search,Nreverses it. The way to find the error that scrolled past.tmux send-keys -X search-backward error
Start a selection
Space (vi)C-Space (emacs)v(vi) orR(emacs) toggles a rectangle;V(vi) selects whole lines.tmux send-keys -X begin-selection
Copy the selection and leave copy mode
Enter (vi)M-w (emacs)The text lands in a tmux paste buffer, not the system clipboard — see
set-clipboardbelow.tmux send-keys -X copy-selection-and-cancel
Paste the last buffer
C-b ]tmux pasteb
List buffers, or pick one to paste
C-b #C-b ==opens a chooser so you can paste any buffer, not only the newest.tmux lsb
Dump the whole scrollback to a file
-pprints to stdout,-S -starts at the beginning of history,-Jjoins wrapped lines.-t work:0.1targets another pane.tmux capture-pane -p -J -S - > pane.txt
Scroll with the mouse wheel
Off by default. With it on, the wheel enters copy mode and scrolls, a drag selects, and letting go copies.
set -g mouse on
Keep more scrollback
Lines per pane. Applies only to windows created afterwards — existing windows keep the limit they were born with.
set -g history-limit 50000
Copy into the system clipboard
Uses the xterm clipboard escape, so the terminal has to support it and say so in terminfo (the
Msentry). Over SSH it is the one route that needs nothing installed on the far side. Otherwise pipe:bind -T copy-mode-vi y send-keys -X copy-pipe-and-cancel 'xclip -selection clipboard'.set -g set-clipboard on
The tmux prefix and key bindings.
Every tmux keystroke starts with the prefix — C-b by default — released before the command key. Everything is rebindable.
The prefix key
C-bPress Ctrl-b, let go, then the command key.
C-b C-bsends a literal Ctrl-b to the program in the pane — or to an inner tmux.set -g prefix C-b
List every key binding
C-b ?-Nshows only keys with notes, the readable version. Plainlskprints bind-key lines you can paste into a config.tmux lsk -N
The command prompt
C-b :Any command on this page works there without the leading
tmux.:kill-server
Bind a key
Keys go in the prefix table unless you say otherwise, so this is
C-b r.-N 'reload'attaches a note forlsk -N.bind r source-file ~/.tmux.conf
Bind a key that needs no prefix
-nbinds in the root table: the key acts on its own. Pick keys the programs in your panes don’t use.bind -n M-Left selectp -L
Bind a key that repeats
-rlets you press the prefix once andHseveral times withinrepeat-timemilliseconds (500 by default).bind -r H resizep -L 5
Unbind a key
unbind -aremoves every binding — only in a config that rebinds what you need.unbind C-b
.tmux.conf essentials.
tmux reads ~/.tmux.conf or ~/.config/tmux/tmux.conf once, when the server starts. Lines are the same commands, minus the leading tmux.
Where the config lives
Either path;
/etc/tmux.confapplies to everyone. Read once, when the server starts.~/.tmux.conf ~/.config/tmux/tmux.conf
Reload the config without restarting
C-b : source ~/.tmux.confOptions apply at once. Per-window settings such as
history-limitonly reach windows created afterwards.tmux source ~/.tmux.conf
Turn the mouse on
Click to select panes and windows, drag borders to resize, wheel to scroll.
set -g mouse on
Remap the prefix to C-a (screen style)
The three lines from the man page’s own example. C-a is readline’s beginning-of-line; press it twice to send it through.
set -g prefix C-a unbind C-b bind C-a send-prefix
vi keys in copy mode
The default is emacs unless
$VISUALor$EDITORcontainsvi.set -g status-keys vidoes the same at the command prompt.setw -g mode-keys vi
Number windows and panes from 1
So
C-b 1is the leftmost window — 0 is a long reach.set -g base-index 1 setw -g pane-base-index 1
Renumber windows when one closes
set -g renumber-windows on
Kill the Escape delay (for vim)
tmux waits
escape-timemilliseconds after Escape (500 by default) to see whether a meta sequence follows; vim users feel every one of them.set -s escape-time 10
True colour and the right TERM
default-terminalmust bescreen,tmux, or a derivative.RGBtells tmux the outer terminal — matched by its TERM — speaks 24-bit colour;-asappends to the array option.set -g default-terminal "tmux-256color" set -as terminal-features ",xterm-256color:RGB"
Keep the window size sensible with several clients
Size follows the client that last did something, instead of the smallest attached one.
set -g window-size latest
Scripting tmux: send-keys, run-shell, and building a workspace.
Every command takes a target. A script can drive a session it never attaches to, from cron, from a hook, from another machine over SSH.
Type into a session from outside
Arguments are key names (
Enter,C-c,Escape) or literal text, sosend-keys -t work:0.1 C-cinterrupts a pane. Targets aresession:window.pane; drop parts from the right to mean “the current one”. Nobody needs to be attached.tmux send-keys -t work 'npm test' Enter
Read what a pane is showing
The programmatic
tail: what is on screen right now, as text. Add-S -for the whole history.tmux capture-pane -p -t work
Print a value from tmux
#{…}is a format; the FORMATS section of the man page lists hundreds —session_name,pane_pid,window_active…tmux display -p '#{pane_current_path}'Run a shell command from tmux
-bruns it in the background,-d 5waits five seconds first. From a key binding, the output opens in view mode.tmux run-shell 'notify-send "build done"'
Log a pane to a file
-otoggles: run it again to stop. Output only, unless you ask for input with-I.tmux pipe-pane -o 'cat >> ~/pane.log'
Bring up a whole workspace from a script
Every line is a command with a target; the last hands the finished session to your terminal. Guard it with
tmux has -t dev 2>/dev/null || …to make it safe to rerun.tmux new -d -s dev -n editor -c ~/proj 'vim' tmux splitw -t dev:editor -h -c ~/proj tmux neww -t dev -n logs -c ~/proj 'tail -f log/dev.log' tmux selectw -t dev:editor tmux attach -t dev
A separate server for something you don’t want touched
-Lnames a socket in/tmp/tmux-UID/;-Sgives a full path. Every later command needs the same-L, andkill-serveron one leaves the other alone.tmux -L agents new -d -s claude
tmux troubleshooting: the messages and their fixes.
What tmux prints, what each line means, and the command that answers it.
“no server running on /tmp/tmux-1000/default”
Nothing to list or attach to: there is no tmux server for your user.
attachsays “no sessions” for the same reason. After a reboot this is normal — the server was a process, and it is gone.new -Acreates or attaches, whichever applies.tmux new -A -s main
“error connecting to /tmp/tmux-1000/default (No such file or directory)”
The same thing before the socket directory even exists — first run on a machine, or after
/tmpwas cleaned. Start a session and the directory appears.tmux new -s main
Sessions gone after a reboot
tmux keeps sessions in a process, not on disk; a reboot ends the process and everything in it. The third-party tmux-resurrect and tmux-continuum plugins save and restore layouts and the commands that were running (not their state); a login script or systemd user unit can recreate your standard session with this line.
tmux new -d -s main
“sessions should be nested with care, unset $TMUX to force”
You ran
tmuxinside a tmux pane. Usually you meanttmux attachfrom a plain shell, orswitch-clientfrom inside. For a real tmux-in-tmux, give the inner one its own socket with-L, and rememberC-b C-bsends the prefix through to it.tmux -L inner new -s x
“open terminal failed: not a terminal”
tmux needs a tty and didn’t get one:
ssh host tmuxwithout-t, a cron job, a CI step, a pipeline. Force a tty withssh -t, or start detached withnew -d, which needs no terminal at all.ssh -t host tmux attach
“missing or unsuitable terminal: xterm-kitty”
The host has no terminfo entry for your terminal’s
$TERM(older releases print it asopen terminal failed: missing or unsuitable terminal). Set aTERMthe host knows for that one command, or install your terminal’s terminfo on the host.TERM=xterm-256color tmux attach
“duplicate session: work”
new -s workwhenworkalready exists. Attach instead — or usenew -A -s work, which does whichever is right.tmux attach -t work
“can't find session: work”
A typo, a different socket (
-L), or a different user — sessions belong to the user whose server holds them, andsudo tmuxis a different user.tmux ls
The session shows in a small box with dots around it
Another client is attached from a smaller terminal and the window is sized to fit it.
-ddetaches the others;set -g window-size lateststops it recurring.tmux attach -d -t work
Colours look wrong inside tmux
Plus the
terminal-featuresRGB line above.tmux display -p '#{client_termfeatures}'shows what tmux decided about your terminal.set -g default-terminal "tmux-256color"
Copy doesn’t reach the clipboard over SSH
Needs a terminal that accepts the xterm clipboard escape. Otherwise pipe copies to a clipboard tool with
copy-pipe-and-cancel, or use the terminal’s own selection — many terminals bypass tmux’s mouse capture while Shift is held.set -g set-clipboard on
A pane says “Pane is dead”
Its command exited and
remain-on-exitkept the pane. Respawn it, orkillp.tmux respawnp -k
Ctrl-b doesn’t do anything
Something remapped the prefix — a dotfile, a plugin, a colleague. Ask tmux what it is now;
tmux lsk -Nlists the live bindings.tmux show -g prefix
Persistence in tmux is a discipline.
Look at what the persistence actually rests on. A session survives your terminal closing because the server is a separate process — but only the terminals started inside it. The build you ran in a plain shell before you remembered to type tmux dies with the window. The agent you launched over SSH without attaching first is gone when the connection is. And the server itself is a process on one machine: a reboot, an OOM kill, a kill-server in the wrong terminal, and every session is gone — which is what the troubleshooting section above is mostly about. So tmux persistence is a habit you keep, per machine, every time: start inside it, name it, remember which box it lives on, and reach that box over SSH when you want it back.
For one machine you sit at, that habit is enough, and nothing on this page suggests otherwise. It stops being enough when the sessions are agents that run for hours, across several machines, and you are not at any of them. That is the case where the other design earns its place: sessions that are persistent by construction rather than by discipline. In spawnd, a small daemon on each host you own owns every session — a worker process holds each PTY — so a session survives the closed tab, the dropped connection, the laptop lid, and a restart of the daemon itself, scrollback intact. There is no “did I start this inside tmux?”, because there is no wrong way to start one. The daemon dials out, so nothing listens on the host and no VPN is needed; any browser is the console, and on a phone it installs to the home screen as a web app — the same live terminal, mid-scrollback. tmux still runs fine inside a tile if you like it as a layout tool; it just stops being load-bearing.
Claude Code, remote walks the SSH-and-tmux route as numbered steps, including where the classic is still the right answer; background agents is the job persistence was built for.
Real PTYs owned by host workers. Hosts dial out — zero open ports. Your browser talks to each daemon peer-to-peer, end-to-end encrypted. Open source, MIT / Apache-2.0. Read the threat model.
Start
Persistence without the prefix.
curl -fsSL https://spawnd.dev/install.sh | shQuestions
- How do I kill all tmux sessions?
- tmux kill-server — it stops the server and every session and client on it. To keep one, tmux kill-session -a -t name kills all the others. Neither asks for confirmation.
- Why did my tmux sessions disappear after a reboot?
- Because a tmux session is a process, not a file. The server dies with the machine and takes every session with it; what survives is only what a plugin like tmux-resurrect saved beforehand, and that is the layout and the commands, not their state. Anything that must outlive a reboot has to be started again by something — a login script, a systemd unit, or a daemon built for it.
- What is the difference between detaching and exiting?
- Detach (C-b d) drops your terminal off the session and leaves everything running; you come back with tmux attach. Exit closes the shell in the pane; when the last pane of the last window goes, the session and, if it was the last session, the server go too.