tmux is a free program that keeps terminal programs running in the background. You start a session (a named workspace) in tmux, then you can leave it and come back later. Everything inside keeps running, even when you close the window or your connection to a server drops. That is why people run AI assistants on a server inside tmux.
tmux runs on Linux and on macOS. On a server, install it with the package tool of the server. The tmux project lists, for example:
| System | Install command |
|---|---|
| Debian or Ubuntu | apt install tmux |
| Fedora | dnf install tmux |
| macOS with Homebrew | brew install tmux |
On many servers you must add sudo before apt or dnf (it runs the command as the administrator).
1. Start a named session
tmux new -s workwork is a name that you choose. A green status line appears at the bottom of the window. You are now inside tmux. Start your assistant here, for example with claude, codex or gemini.
2. Leave the session running (detach)
Press Ctrl + B, let go, then press D.
tmux shows [detached (from session work)] and you are back in the normal terminal. Your session and the assistant in it keep running. You can now close the window or disconnect.
All tmux keys work this way: first Ctrl + B (the prefix key), then one more key.
3. List your sessions
tmux lsYou see each session name, the number of windows and when you made it.
4. Go back into a session (attach)
tmux attach -t workYou see the session exactly as you left it. tmux attach with no name goes back to the most recent session.
5. End a session
tmux kill-session -t workThis closes the session and every program in it. Stop your assistant properly first. You can also type exit in the last window of a session to end it.
Extra keys: windows, panes and scrolling
| Keys | What they do |
|---|---|
| Ctrl + B, then C | Opens a new window in the session |
| Ctrl + B, then N | Goes to the next window |
| Ctrl + B, then % | Splits the window into a left and a right pane |
| Ctrl + B, then " | Splits the window into a top and a bottom pane |
| Ctrl + B, then O | Goes to the next pane |
| Ctrl + B, then [ | Scrolls back: use the arrow keys, then press Q to stop |
| Ctrl + B, then ? | Shows all keys (press Q to close) |
A pane is one part of a split window. Use one pane for the assistant and one for your own commands. Scroll back to read what the assistant did while you were away.
To run an assistant on a server with tmux, follow Run an assistant on a server.
Sources
- github.com/tmux/tmux/wiki/Getting-Started
- github.com/tmux/tmux/wiki/Installing
- man.openbsd.org/tmux