Bug: new sessions do not inherit custom env vars when reusing an existing tmux server
Summary
When claude-squad creates a new tmux session against an already-running tmux server, the new session does not inherit custom environment variables from the invoking shell.
This is especially visible when launching Codex: if the current shell has CPA_API_KEY set, but the tmux server's update-environment does not include it, the new Codex session fails with:
Missing environment variable: CPA_API_KEY
Although I noticed this through Codex, the issue is not specific to CPA_API_KEY. It affects any workflow that depends on custom environment variables from the current shell.
Steps to reproduce
- Start a tmux server.
- In the current shell or tmux pane, set a custom environment variable, for example:
export CPA_API_KEY=... - Use
claude-squadto create a new agent session that runs a program requiring that variable, such as Codex. - Check the environment inside the new session, or observe the program failing at startup.
Actual behavior
The newly created tmux session does not receive custom environment variables from the invoking shell, so programs that depend on them fail to start.
Expected behavior
New tmux sessions created by claude-squad should inherit the environment of the shell that invoked claude-squad, or at least inherit the vast majority of custom environment variables, instead of relying only on tmux's default update-environment behavior.
Root cause
tmux copies an environment into its server/global environment when the server starts. After that, creating or attaching sessions does not automatically refresh the full client environment; it only updates variables listed in update-environment.
claude-squad currently uses the default tmux server directly. As a result, if that server is already running and a custom variable is not listed in update-environment, newly created sessions will miss it.
Suggested direction
A clean fix would be to:
- use a dedicated tmux socket/server for
claude-squad, so it does not modify the user's default tmux server - sync the invoking shell's environment variable names into tmux's
update-environmentbefore creating a new session - only filter a very small set of variables that should not be forwarded, such as:
TERMTMUXTMUX_PANEPWD
Environment
- OS: Debian
- tmux: 3.5a
- Most visible with: Codex
- Actual impact: any agent/CLI launched through
claude-squadthat depends on custom environment variables from the invoking shell
Source: smtg-ai/claude-squad