"My SSH connection dropped and killed the build." "I have twenty terminal tabs open and can't tell them apart." "Switching between my editor, dev server, and test runner is getting old."
If any of these sound familiar, tmux is the answer. It lets you manage multiple virtual terminals inside a single window, and your sessions survive SSH disconnects. Once you start using it, you won't go back.
What is tmux?
tmux (terminal multiplexer) is a tool that lets you run and manage multiple terminal sessions inside one window. It's open source under the BSD license and widely used on Linux and macOS.
You may have heard of GNU Screen — tmux is its modern successor with more features and far more flexible configuration. In today's developer community, tmux is the standard choice.
The biggest benefit of tmux is session persistence. When your SSH connection drops, processes keep running on the tmux server. Reconnect, reattach to your session, and everything is exactly where you left it. Long builds and deployments are safe even on flaky connections.
tmux organizes your workspace in three layers:
- Session: a named group of work. Typically one session per project
- Window: like a tab within a session. One session can hold many windows
- Pane: a subdivision of a window. Multiple shells side by side in one view
Session: "dev"
├── Window 0: "editor"
│ ├── Pane 0: vim
│ └── Pane 1: file browser
├── Window 1: "server"
│ └── Pane 0: npm run dev
└── Window 2: "test"
├── Pane 0: test runner
└── Pane 1: log tail
Installation
tmux does not run natively on Windows. Install it inside WSL using the Linux instructions.
# WSL (Ubuntu)
sudo apt install tmux
Verify the installation:
tmux -V
# tmux 3.6a
Core concepts: Sessions, windows, and panes
Every tmux operation starts with the prefix key. The default prefix is Ctrl+b. When you see prefix below, it means press Ctrl+b first, then the next key.
Session operations
Sessions are the top-level unit. Create one per project or task.
# Create a named session
tmux new -s work
# List sessions
tmux ls
# Attach to a session (reconnect)
tmux attach -t work
# Short form
tmux a -t work
# Kill a session
tmux kill-session -t work
Inside a session:
prefix d— Detach (leave the session; processes keep running in the background)prefix s— List and switch sessionsprefix $— Rename the current session
Window operations
Windows are like browser tabs. They appear in the status bar at the bottom.
prefix c— Create a new windowprefix n— Next windowprefix p— Previous windowprefix 0-9— Jump to window by numberprefix w— Tree view of all windows for selectionprefix ,— Rename the current windowprefix &— Close the current window (with confirmation)
Pane operations
Panes split a window so you can see multiple shells at once — perfect for running an editor next to a terminal.
prefix %— Split left/rightprefix "— Split top/bottomprefix Arrow— Move between panesprefix Ctrl+Arrow— Resize panes (press repeatedly)prefix z— Toggle zoom (fullscreen the current pane)prefix x— Close the current pane (with confirmation)prefix Space— Cycle through layouts
Copy mode
To scroll back through output or select text inside tmux, enter copy mode.
prefix [— Enter copy modeq— Exit copy modeprefix ]— Paste buffer contents
With vi mode enabled (see .tmux.conf below):
prefix [to enter copy modeSpaceto start selection- Arrow keys or
hjklto extend the selection Enterto copy (yanks to buffer)prefix ]to paste
Key bindings cheat sheet
A quick reference for common operations. All keys are pressed after prefix.
Sessions:
| Key | Action |
|---|---|
d | Detach |
s | List / switch sessions |
$ | Rename session |
( | Previous session |
) | Next session |
Windows:
| Key | Action |
|---|---|
c | Create |
n / p | Next / previous window |
0-9 | Jump by number |
w | Tree view / select |
, | Rename |
& | Close |
l | Last used window |
Panes:
| Key | Action |
|---|---|
% | Split left/right |
" | Split top/bottom |
Arrow | Move |
Ctrl+Arrow | Resize |
z | Zoom (toggle) |
x | Close |
Space | Cycle layouts |
{ / } | Swap position |
! | Break pane into new window |
Other:
| Key | Action |
|---|---|
[ | Copy mode |
] | Paste |
: | Command prompt |
? | List all key bindings |
t | Clock |
Customizing with .tmux.conf
The tmux config file lives at ~/.tmux.conf. The default key bindings are frankly hard to remember, so customizing tmux to match your muscle memory is the key to using it long-term.
Here's a practical config. Pick the parts that make sense for your workflow.
# -------------------------------------------
# Change prefix to Ctrl+a
# -------------------------------------------
# Same as GNU Screen and easier to reach than Ctrl+b
unbind C-b
set -g prefix C-a
bind C-a send-prefix
# -------------------------------------------
# Intuitive pane splitting
# -------------------------------------------
# | for horizontal, - for vertical. New panes inherit the current directory
bind | split-window -h -c "#{pane_current_path}"
bind - split-window -v -c "#{pane_current_path}"
unbind '"'
unbind %
# -------------------------------------------
# Vim-style pane navigation
# -------------------------------------------
bind h select-pane -L
bind j select-pane -D
bind k select-pane -U
bind l select-pane -R
# -------------------------------------------
# Enable mouse support
# -------------------------------------------
set -g mouse on
# -------------------------------------------
# Start window and pane numbers at 1
# -------------------------------------------
set -g base-index 1
setw -g pane-base-index 1
# -------------------------------------------
# Renumber windows when one is closed
# -------------------------------------------
set -g renumber-windows on
# -------------------------------------------
# 256-color support
# -------------------------------------------
set -g default-terminal "screen-256color"
set -sa terminal-overrides ",xterm-256color:RGB"
# -------------------------------------------
# Vi key bindings in copy mode
# -------------------------------------------
setw -g mode-keys vi
# -------------------------------------------
# Increase scrollback history
# -------------------------------------------
set -g history-limit 10000
# -------------------------------------------
# Status bar customization
# -------------------------------------------
set -g status-style 'bg=colour235 fg=colour136'
set -g status-left '#[fg=green]#S '
set -g status-right '%Y-%m-%d %H:%M'
set -g status-left-length 20
After editing the file, reload it from within tmux:
# From the shell
tmux source-file ~/.tmux.conf
# From the tmux command prompt
# Press prefix : and type
source-file ~/.tmux.conf
Real-world workflows
Knowing the basics is one thing — putting them to work is another. Here are four patterns that make tmux indispensable in practice.
SSH safety net
This is where tmux shines brightest. Your processes survive SSH disconnects, so long builds and deployments run safely even on unreliable connections.
# SSH into your server
ssh user@server.example.com
# Start a tmux session
tmux new -s deploy
# Run a long deployment
./deploy.sh
# Optionally detach if the connection is flaky
# prefix d
# --- connection drops / come back later ---
# Reconnect
ssh user@server.example.com
# Reattach — everything is still there
tmux a -t deploy
One-command dev environment
Setting up the same window layout by hand every day is a waste of time. Script it.
#!/bin/bash
# dev-tmux.sh — spin up a dev tmux session in one command
SESSION="dev"
PROJECT_DIR="$HOME/projects/myapp"
# If the session already exists, just attach
tmux has-session -t $SESSION 2>/dev/null && {
tmux attach -t $SESSION
exit 0
}
# Create session in detached mode
tmux new-session -d -s $SESSION -c $PROJECT_DIR
# Pane 0: editor
tmux send-keys 'vim .' C-m
# Split right: dev server
tmux split-window -h -c $PROJECT_DIR
tmux send-keys 'npm run dev' C-m
# Split bottom-right: test watcher
tmux split-window -v -c $PROJECT_DIR
tmux send-keys 'npm run test -- --watch' C-m
# Focus back on the editor pane
tmux select-pane -t 0
# Attach
tmux attach -t $SESSION
# Make it executable and run
chmod +x dev-tmux.sh
./dev-tmux.sh
Simultaneous multi-server operations
With synchronize-panes, every keystroke is sent to all panes at once. Run the same command across multiple servers in parallel.
# Create panes for each server
tmux new -s servers
tmux split-window -h
tmux split-window -v
tmux select-pane -t 0
# SSH into each server from its pane
# Pane 0: ssh web1.example.com
# Pane 1: ssh web2.example.com
# Pane 2: ssh web3.example.com
# Enable synchronized input
# Press prefix : and type
setw synchronize-panes on
# Now every keystroke goes to all panes simultaneously
# e.g. sudo apt update && sudo apt upgrade -y
# Turn it off when done
setw synchronize-panes off
Pair programming
Multiple terminals can attach to the same tmux session simultaneously. This lets teammates share a screen and collaborate in real time on the same server.
# Developer A creates the session
tmux new -s pair
# Developer B attaches to the same session
tmux attach -t pair
# Both see and can type in real time
When terminals with different sizes attach to the same session, tmux shrinks to the smallest. Use the same terminal size, or run tmux attach -d -t pair to detach any existing connections first.
Wrapping Up
tmux answers a straightforward need: using your terminal more efficiently.
Key takeaways:
- Three layers (Session → Window → Pane) give you a mental model that makes every command intuitive
- Session persistence is your safety net for remote work
.tmux.conflets you remap prefix keys, pane navigation, and appearance to suit your habits- Scripted sessions automate dev environment setup so you never waste time on it again
Start with the prefix key and basic pane splitting. As you get comfortable, grow your .tmux.conf one setting at a time.
If you want to take your terminal productivity further, try adding fuzzy search with fzf. The tmux + fzf combination is a game changer. For a broader view of CLI tools, check out the CLI Toolkit overview.