Skip to main content
Browse referenceAll guides
Back to Commands
Session ManagementPrefix + d

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

bash
tmux detach-client [-aP] [-E shell-command] [-s target-session] [-t target-client]

Options

FlagDescription
-aDetach all clients except the one specified by -t
-PSend SIGHUP to parent process (usually the shell)
-t target-clientSpecify which client to detach
-s target-sessionDetach all clients from specified session

Examples

Detach current client

bash
tmux detach

Detach using keybinding (most common)

bash
Prefix + d

Detach all other clients

bash
tmux detach -a

Detach all clients from 'mysession'

bash
tmux detach -s mysession

Detach and also send a hangup to the shell or SSH session that started the client, which usually closes it too.

bash
tmux detach -P

Detach every terminal except the one on /dev/ttys003. Find client names with tmux list-clients.

bash
tmux detach -a -t /dev/ttys003

Default 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