# libtmux.Server.detach_client

- **Module:** libtmux
- **Package:** libtmux
- **Language:** Python
- **Kind:** method
- **Source:** https://github.com/tmux-python/libtmux/blob/38e368c11117fb4aeb2f082d552cd4f210eae06a/src/libtmux/server.py#L1006
- **Page:** https://libtmux.org/en/py/stable/reference/libtmux-server-detach_client/

tmux command: [`detach-client`](/en/tmux/latest/manual/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`](/en/tmux/latest/manual/detach-client/).

Maps to [`$ tmux detach-client [-t <target_client>]`](/en/tmux/latest/manual/detach-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`.

## Examples

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

## Parameters

- `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).

## In other ports

### Detach one client

- Go: [`tmux.Server.DetachClient`](/en/go/latest/reference/tmux-server-detachclient/) (method)
- C#: [`LibTmux.Server.DetachClientAsync`](/en/csharp/latest/reference/libtmux-server-detachclientasync/) (method)
- Swift: [`Server.detach(_:)`](/en/swift/latest/reference/server-detach(_-)/) (method)
