detach-client
Short form: detach
Detach the current client or the client specified by -t from its session. The session continues running in the background.
How detach-client works
detach-client disconnects a terminal from tmux while everything in the session keeps running. It is the opposite of attach-session and the main reason people use tmux: start a long job, detach, close the terminal or SSH connection, and come back to it later.
Most of the time you just press Prefix + d. From a shell, tmux detach detaches the terminal you are typing in. -s detaches every terminal attached to a named session, and -a detaches all terminals except one, which helps when old connections pile up.
Detaching never stops programs. If you want something to end, quit it normally or use kill-pane, kill-window, or kill-session.
Synopsis
tmux detach-client [-aP] [-E shell-command] [-s target-session] [-t target-client]Options
| Flag | Description |
|---|---|
| -a | Detach all clients except the one specified by -t |
| -P | Send SIGHUP to parent process (usually the shell) |
| -t target-client | Specify which client to detach |
| -s target-session | Detach all clients from specified session |
Examples
Detach current client
tmux detachDetach using keybinding (most common)
Prefix + dDetach all other clients
tmux detach -aDetach all clients from 'mysession'
tmux detach -s mysessionDetach and also send a hangup to the shell or SSH session that started the client, which usually closes it too.
tmux detach -PDetach every terminal except the one on /dev/ttys003. Find client names with tmux list-clients.
tmux detach -a -t /dev/ttys003Default Keybinding
Prefix + d
Default prefix is Ctrl+b
Common Mistakes
- Only programs started inside tmux survive. Anything you ran directly in the terminal outside tmux ends when that terminal closes.
- On a remote server the session lives on that server. To get back, SSH in again and run tmux attach there, not on your own computer.
- Detaching does not protect against a reboot. Restarting the machine that runs tmux ends every session. Plugins such as tmux-resurrect can recreate your windows and panes afterwards.
Pro Tips
- •Detaching keeps your session alive - you can reattach later
- •Use this before closing your SSH connection to keep work running
- •Prefix + d is the most common way to detach