# libtmux.Session.cmd

- **Module:** libtmux.Session
- **Package:** libtmux
- **Language:** Python
- **Kind:** method
- **Source:** https://github.com/tmux-python/libtmux/blob/036c521c4b83ce6e434eb50afe2a0d08a6a05e46/src/libtmux/session.py#L416
- **Page:** https://libtmux.org/reference/py/libtmux-session-cmd/

```
libtmux.Session.cmd(self, cmd: str, args: t.Any, target: str | int | None = None) -> tmux_cmd
```

Execute tmux subcommand within session context.

Automatically binds target by adding  ``-t`` for object's session ID to the
command. Pass ``target`` to keyword arguments to override.

## Parameters

- `self`
- `cmd` (str)
- `args` (t.Any)
- `target` (str | int | None) — Optional custom target override. By default, the target is the session ID.

## Returns

:meth:`server.cmd`

## Example

```python
>>> session.cmd('new-window', '-P').stdout[0]
'libtmux...:....0'
```

## Example

From raw output to an enriched `Window` object:

```python
>>> Window.from_window_id(window_id=session.cmd(
... 'new-window', '-P', '-F#{window_id}').stdout[0], server=session.server)
Window(@... ...:..., Session($1 libtmux_...))
```
