Shaf Lab

Terminal multiplexers

Programs that run many terminal sessions in one window and keep them alive after you disconnect, such as tmux.

A terminal multiplexer runs many terminal sessions inside one window and keeps them running in a background server, independent of the window you are looking at. You split the screen into panes, group panes into windows or tabs, detach, and later reattach from the same or another machine. GNU Screen popularized the idea in the 1980s; tmux became the common default; Zellij adds a friendlier interface, layouts, and plugins. Terminal emulators such as WezTerm and Kitty build some multiplexing in, and WezTerm can also persist sessions through its own multiplexer server.

Multiplexers became central to agentic coding because command-line agents are just long-running terminal programs. Running each agent in its own pane or window means it keeps working when your SSH connection drops or your laptop sleeps, and you can watch several at once. A common setup is one session per project on an always-on machine, one window per agent, and one Git worktree per window.

Plain multiplexers do not understand what runs inside them. They cannot tell you which agent is blocked on a prompt or summarize what changed. A newer group of agent-aware tools, such as herdr, keeps the multiplexer model and adds agent status, an API agents can drive, and multi-machine views. Others, such as Rex from Superlogical and cmux, rethink the terminal itself around persistent sessions and activity status, with native and mobile clients.

If you run agents on a remote machine, learn the basics of one multiplexer even if you later move to an agent-aware tool: creating and naming sessions, detaching and reattaching, splitting panes, and scrolling back through output. Those habits carry over, and they are the fallback when fancier tools break.

Detachable terminal sessions

Terminal sessions that keep running in a background server after you close the window, so you can reattach later.

A detachable session separates the programs from the screen showing them. A background server owns the terminals; your window is just a client. Detach, close the laptop, or lose the network, and the programs keep running. Reattach from the same machine or over SSH from another one and you see the same panes and scrollback.

Detaching protects running processes from disconnects, not from reboots. After a restart, the server and its programs are gone unless the tool saves a layout and can relaunch or resume what was running. Agent-aware tools increasingly restore layouts and resume supported agent conversations, but in-flight commands still have to start over.

Multiplexer scripting

Driving a terminal multiplexer from code: creating panes, sending keystrokes, and reading output.

Most multiplexers can be controlled from the command line as well as the keyboard. With tmux, for example, a script can create sessions and windows, send keystrokes to a pane, capture a pane's visible output, and wait on events. That makes it possible to launch a fleet of agents from one command, feed them prompts, and collect their results.

Agents can use the same interface to start helper agents, run servers in neighboring panes, and check on each other. Sending raw keystrokes and scraping screens is fragile, though: timing, prompts, and screen layouts change. Tools designed for agents expose a structured API or socket with explicit commands such as start, send, read, and wait until blocked, which is far more reliable than typing into a pane and hoping.

Shared terminal sessions

One live terminal session attached by several people or devices at once, for pairing, support, or watching agents.

A shared terminal session lets more than one client attach to the same running session, so two people can watch and type in the same panes, or one person can follow from both a laptop and a phone. Multiplexers have supported this for a long time on a shared machine; newer tools add sharing over the web or native apps with per-user access.

Sharing a terminal shares everything it can reach: files, credentials, and production access. Use read-only viewers where possible, grant access per session rather than per machine, and end shares when the work is done. For agents, sharing is a convenient way for a teammate to watch or take over a run without a separate handoff.