Terminal Multiplexers
Why You Need One
You're debugging a service. You have a log tail running in one terminal tab, the server process in another, a test runner in a third, and a shell for ad-hoc commands in a fourth. Your terminal emulator has eight tabs open. You accidentally close the window. Everything is gone — the log scrollback, the running processes, all of it.
A terminal multiplexer solves this. It runs a server process that manages your terminal sessions independently from your terminal emulator. Close the window, reopen it, reattach — everything is exactly where you left it. Running processes kept running. Scrollback is preserved. Your layout is intact.
This alone justifies using one. But multiplexers also give you sessions, windows, and panes — a spatial organization system for your terminal that is vastly superior to browser-style tabs.
If you SSH into remote servers, a multiplexer is not optional. Without one, a dropped SSH connection kills your running processes. With one, you reconnect and pick up exactly where you left off.
tmux
tmux is the standard. It's installed or available on virtually every Unix system. It's been around since 2007 and has a massive ecosystem of plugins and configurations. If you're going to learn one multiplexer, learn tmux.
Core concepts
tmux has three layers of organization:
Session - A named collection of windows (e.g., "work", "personal", "server-debug")
Window - A named tab within a session (e.g., "editor", "server", "logs")
Pane - A split within a window (e.g., left pane has code, right pane has tests)
A typical setup might look like this:
Session: "api-project"
Window 0: "code" - Full-screen editor
Window 1: "server" - Pane 1: server process | Pane 2: log tail
Window 2: "test" - Test runner
Window 3: "shell" - General-purpose shell
Session: "infra"
Window 0: "k8s" - kubectl commands
Window 1: "logs" - Log aggregation
Window 2: "ssh" - Connected to production bastion
You can switch between sessions instantly. Each session preserves its own state. You can detach from everything, go home, SSH back in, and reattach.
Essential commands
tmux uses a prefix key (default: Ctrl+b) before every command. You press the prefix, release it, then press the action key.
Starting tmux:
tmux - Start a new unnamed session
tmux new -s work - Start a new session named "work"
tmux attach -t work - Attach to an existing session
tmux attach - Attach to the last session
tmux ls - List all sessions
tmux kill-session -t work - Kill a session
Prefix key: Ctrl+b (press and release, then the next key)
Session management:
prefix d - Detach from current session
prefix s - List sessions and switch between them
prefix $ - Rename current session
Window management:
prefix c - Create a new window
prefix , - Rename current window
prefix n - Next window
prefix p - Previous window
prefix 0-9 - Switch to window by number
prefix & - Close current window
Pane management:
prefix % - Split pane vertically (left/right)
prefix " - Split pane horizontally (top/bottom)
prefix arrow - Move between panes
prefix z - Toggle pane zoom (full screen / restore)
prefix x - Close current pane
prefix space - Cycle through pane layouts
Copy mode:
prefix [ - Enter copy mode (scroll, search, select)
q - Exit copy mode
/ - Search forward in copy mode
Configuration
tmux is configured via ~/.tmux.conf. The defaults are usable but not great. Here's a practical configuration:
# Change prefix from Ctrl+b to Ctrl+a (easier to reach)
unbind C-b
set -g prefix C-a
bind C-a send-prefix
# Start window numbering at 1 (0 is far from the other numbers)
set -g base-index 1
setw -g pane-base-index 1
# Renumber windows when one is closed
set -g renumber-windows on
# Increase scrollback buffer
set -g history-limit 50000
# Faster key repetition
set -s escape-time 0
# Enable mouse support (controversial, but useful for resizing panes)
set -g mouse on
# Split panes with | and - (more intuitive than % and ")
bind | split-window -h -c "#{pane_current_path}"
bind - split-window -v -c "#{pane_current_path}"
# New windows open in the current directory
bind c new-window -c "#{pane_current_path}"
# Reload config
bind r source-file ~/.tmux.conf \; display "Config reloaded"
# Vi-style pane navigation
bind h select-pane -L
bind j select-pane -D
bind k select-pane -U
bind l select-pane -R
# Resize panes with Shift+arrow
bind -r H resize-pane -L 5
bind -r J resize-pane -D 5
bind -r K resize-pane -U 5
bind -r L resize-pane -R 5
# Better colors
set -g default-terminal "screen-256color"
set -ga terminal-overrides ",*256col*:Tc"
# Status bar
set -g status-style 'bg=colour235 fg=colour255'
set -g status-left '#[fg=colour46][#S] '
set -g status-right '%H:%M %d-%b'
After editing, reload with prefix r (if you have the bind above) or run tmux source-file ~/.tmux.conf.
Practical workflows
The project session pattern. Create one session per project you're actively working on. Each session has a predictable window layout.
# Script to create a standard project session
#!/usr/bin/env bash
set -euo pipefail
PROJECT="${1:?Usage: tmux-project <project-name>}"
PROJECT_DIR="$HOME/projects/$PROJECT"
if ! [ -d "$PROJECT_DIR" ]; then
echo "Directory $PROJECT_DIR does not exist"
exit 1
fi
tmux new-session -d -s "$PROJECT" -c "$PROJECT_DIR"
tmux rename-window -t "$PROJECT:1" "edit"
tmux new-window -t "$PROJECT" -n "server" -c "$PROJECT_DIR"
tmux new-window -t "$PROJECT" -n "test" -c "$PROJECT_DIR"
tmux new-window -t "$PROJECT" -n "shell" -c "$PROJECT_DIR"
tmux select-window -t "$PROJECT:1"
tmux attach -t "$PROJECT"
The SSH safety net. Always start a tmux session immediately after SSHing into a server. If your connection drops, your work survives.
# SSH in and attach to (or create) a session
ssh server.example.com -t "tmux attach || tmux new -s main"
The pair programming layout. Both participants attach to the same session and see the same thing in real time.
# Person A creates the session
tmux new -s pairing
# Person B attaches to the same session
tmux attach -t pairing
Zellij
Zellij is the modern alternative. It launched in 2021, is written in Rust, and has better defaults, built-in UI hints, and a more intuitive interface. If you're starting fresh and don't need to work on ancient servers, Zellij is worth considering.
Why Zellij over tmux
The discoverability is dramatically better. Zellij shows keybinding hints at the bottom of the screen. You don't need to memorize commands to be productive on day one.
Default keybindings make more sense. Pane navigation, splitting, and resizing use intuitive key combinations without requiring a prefix key.
Layouts are first-class. You can define layouts in config files and start sessions with predefined pane arrangements.
Plugins are built in. Tab bar, status bar, and other UI elements are implemented as WASM plugins, making them easy to customize or replace.
Zellij basics
# Start Zellij
zellij
# Start with a named session
zellij -s work
# Attach to a session
zellij attach work
# List sessions
zellij list-sessions
# Key modes (Zellij uses modes instead of a prefix key)
Ctrl+p - Pane mode (manage panes)
Ctrl+t - Tab mode (manage tabs)
Ctrl+n - Resize mode
Ctrl+s - Scroll mode
Ctrl+o - Session mode
Ctrl+h - Move mode
# In Pane mode (after Ctrl+p):
n - New pane
d - Split down
r - Split right
x - Close pane
arrow keys - Navigate between panes
# In Tab mode (after Ctrl+t):
n - New tab
x - Close tab
1-9 - Switch to tab
r - Rename tab
Zellij layouts
One of Zellij's strongest features. Define a layout file and start sessions with a consistent structure:
# ~/.config/zellij/layouts/dev.kdl
layout {
pane size=1 borderless=true {
plugin location="tab-bar"
}
pane split_direction="vertical" {
pane size="60%"
pane split_direction="horizontal" {
pane
pane
}
}
pane size=2 borderless=true {
plugin location="status-bar"
}
}
Start with a layout:
zellij --layout dev
Choosing Between Them
Use tmux if:
- You SSH into many different servers (tmux is everywhere)
- You want the largest ecosystem of plugins and tutorials
- Your team already uses tmux
- You need to work on minimal server environments
Use Zellij if:
- You're starting fresh with no multiplexer experience
- You primarily work on your local machine
- You value discoverability and modern defaults
- You want layout files without learning tmux scripting
Either choice is fine. The important thing is using a multiplexer at all. The productivity difference between "has a multiplexer" and "doesn't have a multiplexer" is vast. The difference between tmux and Zellij is minor.
Common Pitfalls
Not using a multiplexer at all. This is the biggest pitfall. Every engineer who works in a terminal should use one. The setup cost is 30 minutes. The payoff is permanent.
Over-customizing before learning the basics. Install tmux or Zellij, use it with default settings for a week, and then start customizing based on what bothers you. Don't spend hours configuring a tool you don't yet understand.
Forgetting to detach. If you close your terminal window without detaching first, the session keeps running (which is good), but you might accumulate orphaned sessions over time. Periodically check tmux ls or zellij list-sessions and clean up old sessions.
Nested multiplexers. If you run tmux locally and then SSH into a server that also runs tmux, you get nested sessions where the prefix key is ambiguous. The standard solution is to use a different prefix key for the inner session, or send the prefix to the inner session by pressing it twice.
Not using named sessions. tmux new -s api is much more useful than tmux new. When you have three unnamed sessions running, you won't remember which is which. Name them.
Key Takeaways
A terminal multiplexer lets you organize terminal work into sessions, windows, and panes that persist across disconnections. This is essential for anyone who works in a terminal regularly.
tmux is the established standard with universal availability. Zellij is the modern alternative with better defaults and discoverability. Pick one and use it.
Start with the basics: create sessions, split panes, switch windows, detach and reattach. This covers 90% of daily use. Add customization gradually.
For remote work, a multiplexer is a requirement, not a luxury. One dropped SSH connection without tmux can cost you hours of lost work and running processes.
Name your sessions, develop a consistent window layout per project, and script session creation for projects you work on frequently.