# libtmux_mcp.tools.env_tools.set_environment

- **Module:** libtmux_mcp.tools.env_tools
- **Package:** libtmux-mcp
- **Language:** Python
- **Kind:** function
- **Source:** https://github.com/tmux-python/libtmux-mcp/blob/4daddc0dfca96c43bf521d818bf91564e1434760/src/libtmux_mcp/tools/env_tools.py#L61
- **Page:** https://libtmux.org/en/py/stable/mcp/reference/libtmux_mcp-tools-env_tools-set_environment/

```
libtmux_mcp.tools.env_tools.set_environment(
    name: str,
    value: str,
    session_name: str | None = None,
    session_id: str | None = None,
    socket_name: str | None = None,
) -> EnvironmentSetResult
```

Set a tmux environment variable.

Use to set variables that will be inherited by new panes and windows.
Changes do not affect already-running processes.

Some variables control later shell execution. Bash sources the file named
by ``BASH_ENV``, POSIX shells may source the file named by ``ENV``, and
Bash evaluates ``PROMPT_COMMAND`` before displaying a prompt.

> **warning:** Values set here propagate into **every** shell tmux later spawns
> in the targeted scope — including panes the user opens manually,
> not just panes the agent drives. A caller that writes ``PATH``,
> ``LD_PRELOAD``, or ``AWS_*`` variables can influence future
> commands the human user types directly. Treat this as
> elevated-risk within ``execute``. The audit log
> redacts the ``value`` argument, but the side effects persist on
> disk/memory until tmux is restarted. Prefer ``env VAR=value
> command`` via :func:`~libtmux_mcp.tools.pane_tools.send_keys`
> when you only need the override for a single command. See
> :doc:`/topics/trust`.

## Parameters

- `name` (`str`): Environment variable name.
- `value` (`str`): Environment variable value.
- `session_name` (`str | None`): Session name to set environment for.
- `session_id` (`str | None`): Session ID to set environment for.
- `socket_name` (`str | None`): tmux socket name.

## Returns

EnvironmentSetResult
    Confirmation with variable name, value, and status.
