# libtmux._internal.env.resolve_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#L100
- **Page:** https://libtmux.org/en/py/latest/reference/libtmux-_internal-env-resolve_socket_path/

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

Resolve the socket path tmux uses for *socket_name*.

tmux keeps its sockets in ``tmux-<euid>`` under ``$TMUX_TMPDIR``, falling
back to ``/tmp`` when that is unset or empty. ``$TMPDIR`` is deliberately
not consulted -- tmux does not consult it either. The socket directory is
resolved through symlinks, as tmux resolves it before binding, so a
symlinked ``$TMUX_TMPDIR`` yields the path tmux itself reports.

A ``$TMUX_TMPDIR`` tmux cannot resolve falls back the same way. tmux takes
the first of ``$TMUX_TMPDIR`` and ``/tmp`` that resolves, so a path that is
not there -- or a broken symlink -- is never the one it binds, and
measuring it would refuse a server tmux reaches without difficulty. A
directory it resolves but cannot create ``tmux-<euid>`` under is an error
from tmux, not a fallback.

The path is *computed*, not observed: it says where tmux would put the
socket, not that a daemon is listening there. Code holding a live
:class:`~libtmux.Server` should ask tmux instead, with the
[`#{socket_path}`](/en/tmux/latest/catalog/formats/socket_path/) format.

## Parameters

- `socket_name` (`str | None`): Socket name, as passed to tmux's ``-L``. Defaults to tmux's own
default, ``"default"``.
  Default: `None`.
- `env` (`t.Mapping[str, str] | None`): Environment to read. Defaults to :data:`os.environ`.
  Default: `None`.

## Returns

:class:`pathlib.Path`
    Path tmux resolves the socket to.

## Examples

```python
>>> from libtmux._internal.env import resolve_socket_path
>>> resolve_socket_path(env={})
PosixPath('/tmp/tmux-.../default')
```

```python
>>> resolve_socket_path("mysocket", env={"TMUX_TMPDIR": "/usr"})
PosixPath('/usr/tmux-.../mysocket')
```

``$TMPDIR`` is not a socket directory, so it changes nothing:

```python
>>> resolve_socket_path(env={"TMPDIR": "/var/folders/xy"})
PosixPath('/tmp/tmux-.../default')
```

Nor does a ``$TMUX_TMPDIR`` tmux cannot use, however long it is:

```python
>>> resolve_socket_path(env={"TMUX_TMPDIR": "/nonexistent-" + "d" * 200})
PosixPath('/tmp/tmux-.../default')
```
