# libtmux.Server.detach_all_clients

- **Module:** libtmux.Server
- **Package:** libtmux
- **Language:** Python
- **Kind:** method
- **Source:** https://github.com/tmux-python/libtmux/blob/036c521c4b83ce6e434eb50afe2a0d08a6a05e46/src/libtmux/server.py#L1058
- **Page:** https://libtmux.org/reference/py/libtmux-server-detach_all_clients/

```
libtmux.Server.detach_all_clients(self, keep_client: str | None = None, shell_command: str | None = None) -> None
```

Detach every client on this server via ``$ tmux detach-client -a``.

tmux's ``-a`` always preserves one client; when *keep_client* is
omitted, the most-recently-active client survives.

## Parameters

- `self`
- `keep_client` (str | None) — Client to preserve (``-t`` flag). All other clients on the
server, regardless of which session they are attached to,
are detached.
- `shell_command` (str | None) — Run a shell command on the detached client(s) after detach
(``-E`` flag).

## Example

```python
>>> with control_mode() as ctl:
...     server.detach_all_clients(keep_client=ctl.client_name)
```
