Mastering tmux: the terminal multiplexer

2026-03-09

post-thumb

Contents

If you’ve ever lost what you were doing in the terminal because you accidentally closed a tab, or found yourself frantically switching between multiple windows while running a server, watching logs, and editing code at the same time, tmux is going to change your life.

tmux is a terminal multiplexer. In simple terms: it lets you create, split, and manage multiple terminal sessions within a single window. But the real superpower is that those sessions persist even when you close the terminal or lose your SSH connection. Everything keeps running in the background, waiting for you to come back.


Why use tmux?

Before jumping into the installation, it’s worth understanding the problems tmux solves:

  • Persistence: closed the terminal? Lost internet in the middle of an SSH session? Doesn’t matter. Your session stays alive. Just reconnect.
  • Multiplexing: split your screen into panes and windows. Run the server in one corner, watch the logs in another, and edit code in a third. All on the same screen.
  • Reproducibility: create saved layouts for your projects. A single command opens your entire work environment.
  • Remote work: essential for anyone working on servers via SSH. Disconnected? Reconnect and everything is exactly where you left it.

If you use the terminal frequently, tmux is one of those tools that, once you learn it, you’ll wonder how you ever lived without it.


Fundamental concepts

tmux works with three main layers:

┌─────────────────────────────────────────────┐
│  Session                                    │
│  ┌───────────────────────────────────────┐  │
│  │  Window 1                             │  │
│  │  ┌──────────────┐ ┌────────────────┐  │  │
│  │  │  Pane 1      │ │   Pane 2       │  │  │
│  │  │              │ │                │  │  │
│  │  │              │ │                │  │  │
│  │  └──────────────┘ └────────────────┘  │  │
│  └───────────────────────────────────────┘  │
│  ┌───────────────────────────────────────┐  │
│  │  Window 2                             │  │
│  └───────────────────────────────────────┘  │
└─────────────────────────────────────────────┘
  • Session: the main container. You can have multiple sessions (one per project, for example).
  • Window: works like tabs within a session. Each window takes up the full screen.
  • Pane: divisions within a window. This is where the split-screen magic happens.

Think of it this way: sessions are your projects, windows are the screens of the project, and panes are the divisions within each screen.


Installation

macOS

If you use Homebrew (and you should), the installation is straightforward:

brew install tmux

Ubuntu / Debian

sudo apt update && sudo apt install tmux -y

Fedora

sudo dnf install tmux

Windows (via WSL)

If you set up WSL following our previous guide, just open the Ubuntu terminal and run:

sudo apt update && sudo apt install tmux -y

Verify the installation

tmux -V

You should see something like tmux 3.5a.


First steps

Creating your first session

To start tmux, simply run:

tmux

Done. You’re inside a tmux session. Notice the green (or colored) bar at the bottom of the screen: that’s the tmux status bar, showing information like the session name and open windows.

But the ideal is to always create named sessions to make organization easier:

tmux new -s my-project

This creates a session called my-project. Much easier to identify when you have multiple sessions running.

The prefix: the magic key

Every interaction with tmux starts with a prefix. By default, it’s Ctrl + b. You press the prefix, release it, then press the command key.

For example, to split the screen vertically:

  1. Press Ctrl + b
  2. Release
  3. Press %

It feels weird at first, but it quickly becomes instinct.


Essential commands

Here’s the quick reference for the commands you’ll use daily. They all start with the prefix Ctrl + b:

Sessions

ShortcutAction
tmux new -s nameCreates a new named session
tmux lsLists all active sessions
tmux attach -t nameReconnects to an existing session
tmux kill-session -t nameTerminates a session
Ctrl + bdDetaches from the session (it keeps running)
Ctrl + bsLists sessions and lets you switch between them
Ctrl + b$Renames the current session

Windows (tabs)

ShortcutAction
Ctrl + bcCreates a new window
Ctrl + bnGoes to the next window
Ctrl + bpGoes to the previous window
Ctrl + b0-9Goes to a window by number
Ctrl + b,Renames the current window
Ctrl + b&Closes the current window

Panes (screen splits)

ShortcutAction
Ctrl + b%Splits vertically (side by side)
Ctrl + b"Splits horizontally (one on top of the other)
Ctrl + barrowMoves focus between panes
Ctrl + bzZoom: maximizes/restores the current pane
Ctrl + bxCloses the current pane
Ctrl + b{Moves the pane to the left
Ctrl + b}Moves the pane to the right
Ctrl + bspaceToggles between pane layouts

Other

ShortcutAction
Ctrl + b[Enters scroll/copy mode (exit with q)
Ctrl + btShows a clock (yes, it’s useless, but fun)
Ctrl + b?Lists all available shortcuts

Workflow in practice

Let’s set up a real scenario. Say you’re working on a web project and you want:

  • A pane for the code editor
  • A pane for the dev server
  • A pane for git commands

Step by step

# Create a session for the project
tmux new -s webapp

# Now you're in the first pane; use it to edit code
# Split vertically (creates pane to the right)
# Ctrl + b, %

# In the right pane, run the server
npm run dev

# Split the right pane horizontally
# Ctrl + b, "

# In the bottom-right pane, use it for git
git status

The visual result looks like this:

┌──────────────────────┬──────────────────┐
│                      │  npm run dev     │
│   editor / code      │  (server)        │
│                      ├──────────────────┤
│                      │  git status      │
│                      │  (git)           │
└──────────────────────┴──────────────────┘

To navigate between panes, use Ctrl + b followed by the arrow keys. To temporarily maximize a pane (zoom), use Ctrl + bz. Press again to restore.


Detach and reconnect: the superpower

This is the feature that makes tmux worth it. Imagine you’re running a long build or monitoring logs:

# Detach from the session (everything keeps running)
# Ctrl + b, d

# Leave, close the terminal, go to sleep...

# The next day, list the sessions
tmux ls

# Reconnect
tmux attach -t webapp

Everything is exactly as you left it. Server running, logs flowing, code open. This is especially useful when you work on remote servers via SSH.


Configuring tmux your way

The configuration file lives at ~/.tmux.conf. If it doesn’t exist, just create it. Here are some settings that will significantly improve your experience:

# Change the prefix from Ctrl+b to Ctrl+a (more comfortable)
unbind C-b
set -g prefix C-a
bind C-a send-prefix

# Enable mouse (scroll, click on panes, resize)
set -g mouse on

# Split panes with | and - (more intuitive than % and ")
bind | split-window -h
bind - split-window -v
unbind '"'
unbind %

# Start counting windows and panes from 1 (instead of 0)
set -g base-index 1
setw -g pane-base-index 1

# Renumber windows when one is closed
set -g renumber-windows on

# Increase scroll history
set -g history-limit 10000

# Reduce escape delay (important for Vim/Neovim)
set -sg escape-time 10

# Reload config with prefix + r
bind r source-file ~/.tmux.conf \; display "Config reloaded!"

After creating or editing the file, reload the configuration:

tmux source-file ~/.tmux.conf

Or, if you added the shortcut above, just press Ctrl + ar.


Making it pretty with themes

Default tmux is functional, but not exactly pretty. Catppuccin and Dracula are two popular themes that transform its appearance.

An even more practical option is TPM (Tmux Plugin Manager), which makes installing plugins and themes easy:

git clone https://github.com/tmux-plugins/tpm ~/.tmux/plugins/tpm

Add the following to the end of your ~/.tmux.conf:

# Plugin list
set -g @plugin 'tmux-plugins/tpm'
set -g @plugin 'tmux-plugins/tmux-sensible'
set -g @plugin 'catppuccin/tmux'

# Initialize TPM (keep this line at the end of the file)
run '~/.tmux/plugins/tpm/tpm'

Inside tmux, press Ctrl + aI (capital letter I) to install the plugins.


tmux + AI tools

If you use Claude Code or Codex CLI, tmux is the perfect companion. A productive layout:

┌──────────────────────┬──────────────────┐
│                      │                  │
│   Claude Code /      │  server /        │
│   Codex CLI          │  build           │
│                      │                  │
│                      ├──────────────────┤
│                      │                  │
│                      │  git / tests     │
│                      │                  │
└──────────────────────┴──────────────────┘

The AI agent works in the left pane while you monitor the server and run tests in the right panes. No need to switch between tabs.


Script to automate your environment

Tired of building the layout manually every time? Create a script. Save it as ~/dev-tmux.sh:

#!/bin/bash

SESSION="dev"

# If the session already exists, just reconnect
tmux has-session -t $SESSION 2>/dev/null
if [ $? -eq 0 ]; then
  tmux attach -t $SESSION
  exit 0
fi

# Create the session with the first window
tmux new-session -d -s $SESSION -n "code"

# Split: right pane for the server
tmux split-window -h -t $SESSION:1

# Split the right pane: git below
tmux split-window -v -t $SESSION:1.2

# Focus on the main pane (left)
tmux select-pane -t $SESSION:1.1

# Attach to the session
tmux attach -t $SESSION

Make it executable and run:

chmod +x ~/dev-tmux.sh
~/dev-tmux.sh

Every time you run this script, it will create (or reconnect to) a session with your layout ready to go.


Quick reference

CommandWhat it does
tmux new -s nameCreates a named session
tmux lsLists sessions
tmux attach -t nameReconnects to a session
tmux kill-session -t nameTerminates a session
Ctrl+b dDetaches from the session
Ctrl+b cNew window
Ctrl+b %Splits vertically
Ctrl+b "Splits horizontally
Ctrl+b arrowNavigates between panes
Ctrl+b zZooms into the pane
Ctrl+b [Scroll mode
Ctrl+b ?Help

Alternatives to tmux

It’s worth mentioning that there are other tools that solve similar problems:

  • Zellij: a modern alternative written in Rust. It has a gentler learning curve and more intuitive shortcuts. If tmux feels too complex at first, Zellij is an excellent entry point.
  • GNU Screen: the grandfather of multiplexers. Simpler, fewer features, but present on almost every Linux server by default.

Next steps

Now that you have tmux in your arsenal:

  1. Start simple: use named sessions and learn to detach/reconnect
  2. Split the screen: practice the pane commands in your daily workflow
  3. Configure: create your ~/.tmux.conf with the options that make sense for you
  4. Automate: build scripts for your most frequent projects
  5. Explore plugins: TPM opens a world of possibilities

tmux is one of those tools that rewards the investment. It may feel verbose at first, but after a week of use, you won’t want to go back.

Liked it? Send me a shout on twitter @lauralesteves