Sessions, Detach, Reattach
The feature that survives SSH drops and laptop reboots
Detach with Ctrl-B d, reattach withtmux attach, name sessions withtmux new -s name. Sessions outlive every terminal they run in.
A session is the outermost tmux container โ a named bag of windows that keeps running even when you walk away. Detach with Ctrl-Bd: tmux closes its window, the session keeps running in the background, every shell inside stays alive. Come back hours or days later, type tmux attach (or tmux a for short), and you're back exactly where you left off.
| Where | Command |
|---|---|
| Inside tmux | Ctrl-Bd โ detach |
| Outside tmux | tmux โ attach to default unnamed session, or create one |
| Outside tmux | tmux new -s work โ start a new session named work |
| Outside tmux | tmux attach โ attach to last-used session |
| Outside tmux | tmux attach -t work โ attach to session named work |
| Outside tmux | tmux ls โ list all sessions |
| Outside tmux | tmux kill-session -t work โ kill named session |
| Inside tmux | Ctrl-Bs โ interactive session chooser |
| Inside tmux | Ctrl-B: new-session โ create from inside |
The Three-Layer Hierarchy
Sessions, windows, and panes nest:
| Layer | Examples in a typical setup | Lives until |
|---|---|---|
| Session | work, side-project, server | You explicitly kill it |
| Window | editor, server, logs (per session) | You close it (Ctrl-B&) or session ends |
| Pane | Editor + test runner side-by-side (per window) | Its shell exits or you kill it (Ctrl-Bx) |
The classic mistake is to use just one session for everything. Once you have more than five or six windows in one session, switching becomes a chore. Split into named sessions per project โ work, personal, experiments โ and use Ctrl-Bs or tmux switch-client to hop between them. Each session has its own window list, its own scrollback, its own state.
Watch
See also: Windows, What Is tmux?