Technical Beauty ■ Episode
“In 2 hours, I found only one or two nits that had very minor security consequences. It is high quality code.”
Theo de Raadt, on reviewing tmux for OpenBSD inclusion
Theo de Raadt does not compliment code. He dissects it, finds every flaw, and tells you about them with the warmth of a coroner reading an autopsy report. When de Raadt reviews a codebase for two hours and the worst he can say is “one or two nits,” that codebase has achieved something remarkable. It has survived the most exacting code review in the open source world and emerged with its dignity intact.
The Man
Nicholas Marriott was a long-time GNU Screen user. He was not a casual user, either. He was the kind of person who had memorised Screen's keybindings, built his workflow around its quirks, and spent years accommodating its eccentricities the way one accommodates a flatmate who insists on playing the trombone at 6 AM. Eventually, in 2007, he stopped accommodating.
The problem with GNU Screen was not that it did not work. It worked. It had worked since 1987, which is to say it carried 37 years of accumulated decisions, some brilliant, some questionable, all load-bearing. The documentation was poor. The configuration was strange. The interface was unintuitive in ways that required genuine archaeology to understand. Marriott did what any self-respecting OpenBSD developer would do: he wrote a replacement from scratch.
The Architecture
The design decision that separates tmux from its predecessor is architectural, not cosmetic. tmux uses a proper client-server model. A single server process manages all sessions, windows, and panes. Clients connect to the server via a Unix domain socket. When you detach, the client exits but the server continues. When you reattach, a new client connects to the same server. Your processes never notice you left.
This is not merely a nicer implementation of the same idea. GNU Screen uses a monolithic process model. The terminal and the session manager are the same process, communicating through a FIFO and a thoroughly entertaining collection of signal handlers. When it works, it works well enough. When it breaks, debugging requires the kind of patience normally reserved for restoring medieval manuscripts.
tmux's client-server split means that multiple clients can attach to the same session simultaneously. Pair programming becomes trivial: two developers, two terminals, one session. No screen-sharing software. No latency from video encoding. No “can you see my screen?” Just two cursors in the same panes, editing the same files, watching the same test output. The protocol handles the rest.
The Configuration
GNU Screen's configuration file, .screenrc, is a dialect
of English that Screen alone speaks. The syntax evolved over decades
without any apparent design authority, accumulating commands the way
a shed accumulates tools: everything is in there somewhere, but good
luck finding the adjustable spanner.
tmux uses a single configuration file, .tmux.conf, with
a consistent command syntax. Every command you can type in tmux's
command prompt is the same command you can place in the configuration
file. There is no separate configuration language. There is no
distinction between interactive commands and config-file directives.
The interface is the configuration, and the configuration is the
interface. This sounds obvious. It was, apparently, a revelation.
# Split panes
bind | split-window -h
bind - split-window -v
# Navigate panes with vim keys
bind h select-pane -L
bind j select-pane -D
bind k select-pane -U
bind l select-pane -R
# Status bar
set -g status-style 'bg=default,fg=white'
The keybindings are consistent and rebindable. The prefix key defaults
to Ctrl-b, but every binding can be changed in a single
line. Screen's keybinding system, by comparison, requires the user
to understand the difference between bindkey,
bind, and escape, three commands that do
overlapping things in subtly different contexts. It is the kind of
design that makes perfect sense if you were there when each command
was introduced, and no sense at all if you were not.
The Quality
tmux was written for OpenBSD, and this matters. OpenBSD is a project where code quality is not a goal but a prerequisite. The codebase undergoes constant auditing. Functions are scrutinised for buffer overflows, integer overflows, format string vulnerabilities, and the general category of “things that would be fine on any other operating system but are unacceptable here.”
When Marriott submitted tmux for inclusion in OpenBSD, Theo de Raadt reviewed it personally. Two hours. One or two minor nits. For context, de Raadt is the man who once removed an entire subsystem from the OpenBSD kernel because he found a theoretical vulnerability that had never been exploited in practice. His threshold for “acceptable” is somewhere north of what most projects consider “paranoid.” tmux cleared it. It was included in OpenBSD 4.6, released in October 2009, and has been in the base system ever since.
The Practical Beauty
What tmux actually solves is the problem of context. A developer working on a server does not have one task. They have six. A compilation running in one pane, logs tailing in another, an editor in a third, a database console in a fourth. Without a terminal multiplexer, losing your SSH connection means losing all of that state. Rebuilding it costs minutes. Multiplied by a dozen disconnections per day, that is hours per week spent reconstructing context that a proper architecture would have preserved.
tmux preserves it. Detach, close your laptop, fly to another
continent, open a different laptop, reattach. Every pane is where
you left it. Every process is still running. The compilation
finished while you were on the plane. The logs kept tailing. Your
vim session still has the cursor on line 247, column
12, in exactly the file you were editing. The server does not care
that the client went away. It has no opinion on your travel
arrangements.
The Licence
tmux is ISC licensed, the most permissive of the BSD licences. GNU Screen is, naturally, GPL. The licensing choice is not incidental. ISC is two paragraphs. GPL version 3 is 5,644 words. The licence mirrors the software: one is concise, clear, and easy to comply with. The other requires a lawyer.
The Lesson
GNU Screen was written in 1987, and it shows. Not because it is bad software. It is not. It solved a genuine problem, and it solved it well enough to survive for nearly four decades. But 37 years of decisions accumulate. Features are added but never removed. Interfaces are extended but never simplified. Configuration syntax grows new dialects. The codebase becomes its own archaeology.
tmux was written in 2007 with 20 years of hindsight about what a terminal multiplexer actually needs. Marriott did not attempt to improve Screen. He did not fork it. He sat down with a blank file and asked a better question: what would this look like if we designed it today, knowing everything we know?
The answer was a clean client-server architecture, a single consistent configuration language, proper keybinding management, and code clean enough to pass Theo de Raadt's two-hour inspection with one or two nits. It was included in OpenBSD's base system and has since become the default terminal multiplexer on virtually every Unix-like operating system.
Sometimes the most beautiful code is not an improvement of what exists. It is permission to start again.