# libtmux.Window.from_env

- **Module:** libtmux.Window
- **Package:** libtmux
- **Language:** Python
- **Kind:** method
- **Source:** https://github.com/tmux-python/libtmux/blob/036c521c4b83ce6e434eb50afe2a0d08a6a05e46/src/libtmux/window.py#L242
- **Page:** https://libtmux.org/reference/py/libtmux-window-from_env/

```
libtmux.Window.from_env(cls, env: t.Mapping[str, str] | None = None) -> Window
```

Return the window containing the pane this process runs inside of.

Resolves through :meth:`Pane.from_env`, so the answer is the window
that *contains* the caller -- not the session's currently active
window, which may be a different one entirely.

## Parameters

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

## Returns

:class:`Window`

## Raises

- `NotInsideTmux` — When ``$TMUX`` or ``$TMUX_PANE`` is unset or malformed.
- `TmuxObjectDoesNotExist` — When the pane named by ``$TMUX_PANE`` is gone.
- `LibTmuxException` — When the server named by ``$TMUX`` is unreachable.
- `ValueError` — When the resolved pane carries no ``window_id``. Surfaces a clear
error under ``python -O``, where an ``assert`` would be stripped.

## Example

```python
>>> socket_path = server.cmd(  # doctest: +HIDE
...     "display-message", "-p", "-t", pane.pane_id, "#{socket_path}"
... ).stdout[0]
>>> env = {  # doctest: +HIDE
...     "TMUX": f"{socket_path},1,0",
...     "TMUX_PANE": pane.pane_id,
... }
```

## Example

```python
>>> Window.from_env(env)
Window(@1 1:..., Session($1 ...))
```

## Example

The caller's window is reported even while another window is active:

```python
>>> _ = session.new_window(window_name="foreground", attach=True)
>>> Window.from_env(env).window_id == window.window_id
True
```
