tmuxtmuxTopics

Choose documentation 1

latest

tmux manual version

Latest (3.7c) 3.7c 3.2a
English

Edit this page on GitHub

Architecture

tmux runs a server that owns sessions, window links, windows, and panes. Clients connect through a Unix-domain socket to issue commands or display a session. Programs inside panes run through pseudo-terminals managed by the server. A command client can exit while the server and pane programs continue.

Observe the server across client commands

Save this complete script as architecture.sh. It requires tmux 3.3a or newer and a POSIX shell. It starts a private server, reads it through separate clients, and verifies that its session survives with no attached clients.

architecture.sh
#!/bin/sh
set -eu
directory=$(mktemp -d "${TMPDIR:-/tmp}/libtmux-architecture.XXXXXX")
socket="$directory/tmux.sock"
cleanup() {
status=$?
trap - 0 HUP INT TERM
if [ -S "$socket" ] && ! tmux -S "$socket" kill-server; then
printf 'Cannot stop tmux; kept %s\n' "$directory" >&2
exit 1
fi
rm -rf "$directory" || status=$?
exit "$status"
}
trap cleanup 0
trap 'exit 1' HUP INT TERM
tmux -S "$socket" -f /dev/null \
new-session -d -s work -n editor 'cat' \; \
new-window -d -t '=work:' -n logs 'cat'
first_pid=$(tmux -S "$socket" display-message -p '#{pid}')
state=$(tmux -S "$socket" list-sessions \
-F '#{session_name}:#{session_windows}')
[ "$state" = work:2 ]
printf 'session state: %s\n' "$state"
second_pid=$(tmux -S "$socket" display-message -p '#{pid}')
[ "$first_pid" = "$second_pid" ]
printf 'server PID unchanged\n'
clients=$(tmux -S "$socket" list-clients -F '#{client_name}')
[ -z "$clients" ]
printf 'attached clients: 0\n'

Run the saved script:

Terminal window
$ sh architecture.sh

The output is session state: work:2, server PID unchanged, and attached clients: 0 on separate lines. The cleanup trap then stops the private server. list-clients reports attached clients, including control clients; the short-lived command clients do not remain attached.

Follow a command

A shell invocation starts a client for the selected socket. The server executes tmux commands through command queues. The example groups new-session and new-window with an escaped ;, so the shell passes the separator to tmux. Commands within the group run in order. Some commands pause a queue while they wait for their task.

A group is not a transaction. A command failure can stop later commands while earlier changes remain. Command failures shows a complete partial-work example. Control mode explains persistent clients, reply boundaries, and asynchronous events.

Read state through native commands

list-sessions, list-windows, and list-panes read the current object state. display-message evaluates a format for a selected target. -F formats choose fields; -f filters can reduce a listing to matching rows.

Separate reads can observe changes made by other clients. Saving output creates a local record of that read, rather than a reservation on the objects. Filtering and queries covers live listings, and the object hierarchy covers IDs and window links.

Source and command contracts

The CLI manual documents command syntax and observable behavior for the selected release. The C source reference exposes tmux’s native implementation. Use those sources when a script depends on version-specific flags, queue behavior, or formats.

Keep server selection explicit when a program manages more than one socket. Socket and servers explains selection and server replacement; ownership and cleanup explains which kill command matches the resource a script created.

The pinned tmux manual documents the commands and formats used here.

Esc

Type to search.

Reference previewOpen reference