# libtmux.Server.detach_client

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

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

Detach a specific client via ``$ tmux detach-client``.

Maps to ``$ tmux detach-client [-t <target_client>]``. tmux
resolves ``-t`` over the global client list (see
``cmd-find.c``); the named client may be attached to any
session, so this method lives on :class:`Server` rather than
:class:`Session`.

## Parameters

- `self`
- `target_client` (str | None) — Client name (``-t`` flag). When omitted, tmux falls back to
the most-recently-active client.
- `shell_command` (str | None) — Run a shell command on the detached client after detach
(``-E`` flag).

## Example

```python
>>> with control_mode() as ctl:
...     server.detach_client(target_client=ctl.client_name)
```
