🖥️ tmux
tmux is a terminal multiplexer — it lets you run multiple terminal sessions inside a single window, split the screen into panes, and detach/reattach to sessions so work keeps running in the background.
Core Concepts
Session — a collection of windows. You can detach from a session and reattach later; everything keeps running.
Window — like a tab inside a session. Each window fills the full terminal.
Pane — a split within a window. Multiple panes can be visible side-by-side or stacked.
All tmux commands are prefixed with a key combination called the prefix key. The default is Ctrl+B.
Sessions
Command |
Description |
|---|---|
|
Start a new session |
|
Start a named session |
|
List all sessions |
|
Re-attach to the most recent session |
|
Re-attach to a named session |
|
Detach from the current session |
|
Rename the current session |
|
Show an interactive session list to switch between sessions |
Inside session: |
Rename session from the command line |
Windows
Command |
Description |
|---|---|
|
Create a new window |
|
Create a new window (from the command line inside a session) |
|
Switch to the next window |
|
Switch to the previous window |
|
Rename the current window |
|
Close the current window |
Panes
Command |
Description |
|---|---|
|
Split pane vertically (side by side) |
|
Split pane horizontally (top and bottom) |
|
Move focus to the pane in that direction |
|
Resize the current pane in that direction |
|
Close the current pane |
Configuration
tmux reads its configuration from ~/.tmux.conf at startup.
Note
Good resource for customization: Learn tmux Part 5 — How to Customize tmux and Make it Your Own
Enable mouse support:
set -g mouse on
With mouse support enabled you can click to focus a pane or window, and drag pane borders to resize them.
Scripting
tmux is scriptable, which makes it useful for launching reproducible development environments. The example below sets up a three-pane layout — a common pattern for running a broker alongside two clients.
#!/bin/bash
SESSION="my-session"
# Kill any existing session to start clean
tmux kill-session -t $SESSION 2>/dev/null
# Create a new detached session (200 cols × 50 rows)
tmux new-session -d -s $SESSION -x 200 -y 50
# Split right: creates pane 2
tmux split-window -t $SESSION -h -l 100
# Split pane 2 vertically: creates pane 3 below
tmux split-window -t $SESSION:1.2 -v -l 25
# Send commands to each pane
tmux send-keys -t $SESSION:1.1 "echo 'hello from pane 1'" Enter
tmux send-keys -t $SESSION:1.2 "echo 'hello from pane 2'" Enter
tmux send-keys -t $SESSION:1.3 "echo 'hello from pane 3'" Enter
# Attach to the session
tmux attach-session -t $SESSION
Key scripting commands:
tmux new-session -d -s <name> -x <cols> -y <rows>— create a detached session with a given sizetmux split-window -t <target> -h -l <cols>— split horizontally, new pane on the righttmux split-window -t <target> -v -l <rows>— split vertically, new pane belowtmux send-keys -t <target> "<command>" Enter— send a command to a panetmux attach-session -t <name>— attach to a sessiontmux set-hook -t <name> session-closed 'run-shell "<cmd>"'— run a shell command when the session closes
The <target> format is <session>:<window>.<pane> (e.g. my-session:1.2 means window 1, pane 2 of session my-session).