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

The three commands that cover most days.
92 of 92

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

    new is the alias of new-session. The name is what every later -t target and tmux ls line uses.

    tmux new -s work
  • Start a session in the background, running a command

    -d creates 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 a also 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

    -A makes 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

    -d detaches 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 d

    The 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 $

    rename is the alias of rename-session; -t picks the session to rename.

    tmux rename -t 0 work
  • Switch to another session while attached

    C-b sC-b (C-b )C-b L

    C-b s opens a chooser; ( and ) step to the previous and next session; L goes 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

    -a inverts the target: everything but work goes.

    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-d

    Typing exit in 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

    -n names 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 l

    tmux prev goes the other way; C-b l (tmux last) goes back to the window you came from. M-n and M-p after 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 9

    Past 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 w

    Everything 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; -k replaces 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, set renumber-windows on (below).

    tmux movew -r
  • Kill the window

    C-b &

    The key binding asks for confirmation; the command doesn’t. killw -a kills 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 %

    -h is what tmux calls a horizontal split: the new pane appears beside the current one.

    tmux splitw -h
  • Split top and bottom

    C-b "

    -v is the default when neither flag is given.

    tmux splitw -v
  • Split with a size, or on the other side

    -l takes lines or columns, or a percentage of the space. -b puts the new pane to the left of, or above, the current one; -c ~/proj starts 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 -D pick a direction; -t 2 picks 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 digit

    The numbers stay up for display-panes-time milliseconds; pressing one runs select-pane on it.

    tmux displayp
  • Resize a pane

    C-b C-← … (one cell)C-b M-← … (five)

    -U -D -L -R with a count; -x 50% or -y 20 set an absolute size in cells or percent.

    tmux resizep -L 10
  • Zoom a pane to fill the window (toggle)

    C-b z
    tmux resizep -Z
  • Swap with the previous or next pane

    C-b {C-b }

    -D swaps downward. Mark a pane first with C-b m and it becomes the source.

    tmux swapp -U
  • Cycle through the preset layouts

    C-b Space

    Presets: even-horizontal, even-vertical, main-horizontal, main-vertical, tiled — also on C-b M-1 to M-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; -h puts it beside. The reverse of break-pane.

    tmux joinp -s :2
  • Mark a pane, then join it wherever you are

    C-b m

    With -s omitted, join-pane, swap-pane and move-pane use the marked pane. C-b M clears the mark.

    tmux joinp
  • Kill the pane

    C-b x

    -a kills every other pane in the window instead.

    tmux killp
  • Type into every pane at once

    A window option; off to 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-pane reruns its original command; -k kills 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 PageUp enters it already scrolled up one page.

    tmux copy-mode
  • Leave copy mode

    qEscape (emacs)

    -X sends 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-f

    Half pages: C-u and C-d in vi mode, M-Up and M-Down in 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)

    n repeats the search, N reverses 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) or R (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-clipboard below.

    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

    -p prints to stdout, -S - starts at the beginning of history, -J joins wrapped lines. -t work:0.1 targets 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 Ms entry). 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-b

    Press Ctrl-b, let go, then the command key. C-b C-b sends 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 ?

    -N shows only keys with notes, the readable version. Plain lsk prints 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 for lsk -N.

    bind r source-file ~/.tmux.conf
  • Bind a key that needs no prefix

    -n binds 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

    -r lets you press the prefix once and H several times within repeat-time milliseconds (500 by default).

    bind -r H resizep -L 5
  • Unbind a key

    unbind -a removes 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.conf applies to everyone. Read once, when the server starts.

    ~/.tmux.conf
    ~/.config/tmux/tmux.conf
  • Reload the config without restarting

    C-b : source ~/.tmux.conf

    Options apply at once. Per-window settings such as history-limit only 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 $VISUAL or $EDITOR contains vi. set -g status-keys vi does the same at the command prompt.

    setw -g mode-keys vi
  • Number windows and panes from 1

    So C-b 1 is 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-time milliseconds 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-terminal must be screen, tmux, or a derivative. RGB tells tmux the outer terminal — matched by its TERM — speaks 24-bit colour; -as appends 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, so send-keys -t work:0.1 C-c interrupts a pane. Targets are session: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

    -b runs it in the background, -d 5 waits 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

    -o toggles: 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

    -L names a socket in /tmp/tmux-UID/; -S gives a full path. Every later command needs the same -L, and kill-server on 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. attach says “no sessions” for the same reason. After a reboot this is normal — the server was a process, and it is gone. new -A creates 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 /tmp was 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 tmux inside a tmux pane. Usually you meant tmux attach from a plain shell, or switch-client from inside. For a real tmux-in-tmux, give the inner one its own socket with -L, and remember C-b C-b sends 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 tmux without -t, a cron job, a CI step, a pipeline. Force a tty with ssh -t, or start detached with new -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 as open terminal failed: missing or unsuitable terminal). Set a TERM the 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 work when work already exists. Attach instead — or use new -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, and sudo tmux is 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. -d detaches the others; set -g window-size latest stops it recurring.

    tmux attach -d -t work
  • Colours look wrong inside tmux

    Plus the terminal-features RGB 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-exit kept the pane. Respawn it, or killp.

    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 -N lists 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 | sh
Sign up free
Install the daemon

Questions

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.