# libtmux._internal.env.pane_id_from_env

- **Module:** libtmux._internal.env
- **Package:** libtmux
- **Language:** Python
- **Kind:** function
- **Source:** https://github.com/tmux-python/libtmux/blob/38e368c11117fb4aeb2f082d552cd4f210eae06a/src/libtmux/_internal/env.py#L125
- **Page:** https://libtmux.org/en/py/stable/reference/libtmux-_internal-env-pane_id_from_env/

```
libtmux._internal.env.pane_id_from_env(
    env: t.Mapping[str, str] | None = None,
) -> str
```

Return the pane id recorded in ``$TMUX_PANE``.

The ``%`` sigil is load-bearing: libtmux passes this id straight to tmux as
a ``-t`` target, and tmux's ``cmd_find`` routes a target to its pane slot
*by sigil*. A sigil-less value would be matched against session names
instead, silently resolving to the wrong object.

## Examples

```python
>>> from libtmux._internal.env import pane_id_from_env
>>> pane_id_from_env({"TMUX_PANE": "%3"})
'%3'
```

```python
>>> pane_id_from_env({})
Traceback (most recent call last):
...
libtmux.exc.NotInsideTmux: Not inside a tmux pane: $TMUX_PANE is unset or empty
```

```python
>>> pane_id_from_env({"TMUX_PANE": "3"})
Traceback (most recent call last):
...
libtmux.exc.NotInsideTmux: Not inside a tmux pane: $TMUX_PANE is not a pane id...
```

## Parameters

- `env` (`t.Mapping[str, str] | None`): Environment to read. Defaults to :data:`os.environ`.

## Returns

str
    The pane id, e.g. ``"%3"``.

## Raises

- [`NotInsideTmux`](/en/py/stable/reference/libtmux-exc-notinsidetmux/): When ``$TMUX_PANE`` is unset, empty, or is not a ``%``-prefixed id.
