Ramblings of an aging IT geek
← Ramblings of an aging IT geek
tooling

the day i stopped losing my work to a dropped ssh connection

How tmux became the layer that survives flaky VPN drops and laptop sleeps, a small but opinionated config, and the handful of habits that make detach-and-reattach second nature.

A keyboard in front of a terminal split into several tmux panes

For years my workflow had a single point of failure: the SSH connection. The VPN would hiccup, the laptop would sleep on the train, and whatever was running in that shell, a long build, a tail of a log during an incident, a half-typed migration, went with it. The fix is embarrassingly old and I should have adopted it a decade sooner. Run everything inside tmux on the remote host, and the connection becomes disposable. Drop it, reconnect, reattach, carry on as if nothing happened.

The mental model is the bit that took me longest to internalise. The tmux server lives on the remote machine and outlives your client. Your terminal is just a window onto a session that is already there. Close the lid, the session keeps running. That is the whole trick, and once it clicks you stop treating a dropped connection as a loss and start treating it as a detach.

A small config, not a framework

I resisted the urge to install one of the big tmux config bundles. They are fine, but they hide the thing I am trying to learn. This is most of my ~/.tmux.conf:

# Ctrl-a is closer than Ctrl-b and matches old screen muscle memory
unbind C-b
set -g prefix C-a
bind C-a send-prefix

# Sane splits that remember the current directory
bind | split-window -h -c "#{pane_current_path}"
bind - split-window -v -c "#{pane_current_path}"

set -g mouse on
set -g history-limit 50000
set -g base-index 1
setw -g pane-base-index 1

# Reload without leaving tmux
bind r source-file ~/.tmux.conf \; display "reloaded"

The mouse line is the one tmux purists will tut at. I do not care. Being able to click a pane to focus it or drag a border to resize lowered the barrier enough that I actually started using splits rather than tab-juggling.

A terminal showing a tmux status bar with several named windows

The habits that made it stick

Two habits did more than any config line. The first is naming sessions. tmux new -s incident or -s deploy means that when I reattach with tmux a -t deploy I land exactly where I expect, instead of squinting at a list of anonymous numbers. The second is reattaching by default. I aliased my SSH-into-the-jumpbox command to drop straight into tmux new -A -s main, which attaches to main if it exists and creates it if it does not. So even a fresh login lands me back in the same persistent session. I never start from a blank shell unless I deliberately ask for one.

The bit I underrated was how much calmer incident work became. When something is on fire you do not want to also be worrying that closing the lid loses your scrollback and your half-run query. Inside tmux it does not. Detach, walk to a screen with a bigger monitor, reattach, the panes are exactly as you left them. That alone has paid for the afternoon I spent reading the man page.

It is not glamorous and it is not new. It is just one of those tools that, once it is load-bearing in your day, you cannot remember how you worked without it.