# libtmux._internal.env.resolve_ambient_socket_path

- **Module:** libtmux._internal.env
- **Package:** libtmux
- **Language:** Python
- **Kind:** function
- **Source:** https://github.com/tmux-python/libtmux/blob/efdbb5637666b166358772ecc737b3807beab21e/src/libtmux/_internal/env.py#L291
- **Page:** https://libtmux.org/en/py/latest/reference/libtmux-_internal-env-resolve_ambient_socket_path/

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

Resolve the socket a *bare* tmux invocation talks to, in tmux's own order.

A tmux client given no ``-L`` or ``-S`` prefers ``$TMUX`` -- the socket of
the pane it is running inside -- and only falls back to computing a path
under ``$TMUX_TMPDIR`` when there is no pane. Measured against tmux 3.7b: a
bare client with ``$TMUX`` set connects even when ``$TMUX_TMPDIR`` names a
directory far too deep to bind, because it never looks there.

That order only holds for the bare client. Passing ``-L`` sends tmux to
``$TMUX_TMPDIR`` regardless of ``$TMUX``, so a named socket resolves through
:func:`resolve_socket_path` instead.

## Parameters

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

## Returns

:class:`pathlib.Path`
    Socket path a bare tmux client would use.

## Examples

```python
>>> from libtmux._internal.env import resolve_ambient_socket_path
```

Inside a pane, ``$TMUX`` names the socket outright:

```python
>>> resolve_ambient_socket_path({"TMUX": "/tmp/tmux-1000/default,8421,0"})
PosixPath('/tmp/tmux-1000/default')
```

``$TMUX_TMPDIR`` is not consulted when there is a pane to inherit from:

```python
>>> resolve_ambient_socket_path(
...     {"TMUX": "/tmp/sock,8421,0", "TMUX_TMPDIR": "/nowhere"}
... )
PosixPath('/tmp/sock')
```

Outside tmux it falls back to the computed path:

```python
>>> resolve_ambient_socket_path({})
PosixPath('/tmp/tmux-.../default')
```
