๐Ÿ–ฅ๏ธ

How Does tmux Work?

Session Persistence & Splitting with a Terminal Multiplexer

tmux (terminal multiplexer) is a tool that manages multiple sessions in a single terminal window, splits panes, and maintains work even when SSH connections drop. The key is its server-client architecture. The tmux server manages sessions in the background, and the terminal we see connects to the server as a client. So even when you close the terminal (detach), the server session stays alive and you can reconnect (attach) later. The hierarchy is Server > Session > Window > Pane.

Architecture Diagram

๐Ÿ–ฅ๏ธ
tmux Server
Background process
Session: dev
Window 0: vim
Pane 0 Pane 1
Window 1: server
rails s
attach
detach
๐Ÿ’ป
Terminal (Client)
iTerm / Terminal.app
$ tmux attach -t dev
# Connect to session
Hierarchy: Server > Session > Window > Pane
Server Session (dev) Window (vim) Pane
Key Commands (prefix: Ctrl+b)
d detach
c new window
% split vertical
" split horizontal
n/p next/prev window
arrow move pane
SSH Disconnection Scenario
SSH Connect tmux new -s work Working... Network disconnected! SSH Reconnect tmux attach -t work Work intact!
Key Points
  • Server-Client Architecture: Terminal is the client, tmux server runs in the background
  • Session Persistence: Server+session stays alive after detach โ€” safe from SSH disconnection
  • Multiple Connections: Multiple clients can attach to the same session (pair programming)
  • Screen Splitting: Split a Window into Panes for multitasking

How It Works

1

tmux server process starts in background on first tmux command

2

Server creates new Session, with a default Window inside the session

3

Terminal (client) connects to server and displays session

4

Ctrl+b d to detach โ†’ only client terminates, server+session persists

5

tmux attach to reconnect to existing session (even after SSH reconnection)

6

Ctrl+b %/" to split panes, Ctrl+b c to create new window

Pros

  • Session persists despite SSH disconnection
  • Multitasking via screen splitting
  • Collaboration via session sharing
  • Automatable via scripts (tmuxinator)
  • Lightweight and fast

Cons

  • Key binding learning curve
  • Getting used to prefix key (Ctrl+b)
  • Limited mouse support (configuration needed)
  • Difficult to manage complex layouts

Use Cases

Preventing SSH disconnection (remote server work) Terminal screen splitting (simultaneous task monitoring) Pair programming (shared session) Long-running task persistence (build, deploy) Server process management (terminate after detach)