Repository navigation
Description
What variant of Codex are you using?
CLI (0.160.0, managed app-server daemon), Windows 11. The same gap exists on macOS and Linux.
What feature would you like to see?
Let the CLI/TUI set thread-scoped MCP server environment when it starts or resumes a thread, the same way any other app-server client already can.
Use case. We run several Codex sessions side by side in a terminal multiplexer, wmux, one per pane, alongside Claude Code sessions. Agents talk to each other through the multiplexer's MCP server (mcp_servers.wmux, agent-to-agent messages). That server must know which pane the calling session lives in, so it can tell sender from recipient. The multiplexer identifies a pane through per-pane variables (WMUX_PTY_ID, WMUX_WORKSPACE_ID), like TMUX_PANE for tmux.
With the managed daemon, a typed codex cannot pass that identity to its thread's MCP servers:
- The MCP server is spawned by the daemon. Its environment comes from the daemon process, filtered by
create_env_for_mcp_server(rmcp-client/src/utils.rs), so the pane variables are missing, or belong to whichever client started the daemon. - The app-server protocol already supports the right thing: a
thread/start/thread/resume/thread/forkrequest may carryconfigoverrides, includingmcp_servers.<name>.env. That config is scoped to the thread. wmux relies on this on macOS and Linux. It proxies the TUI connection (codex --remote unix://…) and addsmcp_servers.wmux.envto each thread request, which works well. - The TUI itself cannot send it:
config_request_overrides_from_config(tui/src/app_server_session.rs) forwards onlyallow_login_shell,default_permissions,features,network,permissions,personality,sandbox_workspace_write,shell_environment_policyandsuppress_unstable_features_warning. Socodex -c 'mcp_servers.wmux.env.WMUX_PTY_ID="…"'is dropped before it reaches the daemon.
So users must either run codex --no-daemon, losing the daemon, or put a proxy between the TUI and the daemon. On Windows that proxy is not practical for a Node-based tool, because the daemon socket is AF_UNIX.
Proposal (smallest first):
- Forward
mcp_servers.<name>.env(or all ofmcp_servers) from the TUI's session flags inconfig_request_overrides_from_config. This is the same thread-scoped override the protocol already accepts from other clients. A multiplexer can then launchcodex -c mcp_servers.wmux.env.WMUX_PTY_ID=…per pane. - Optionally, as sugar on top:
env_varsentries withsource = "client"(next to the existinglocal/remote). The CLI would resolve them from its own environment when it starts or resumes a thread and send them as that thread's MCP env. Then a plaincodextyped in a pane works with no wrapper.
Both keep your model: the values belong to the thread, set by the client that started or resumed it, and are never inferred from whichever client is attached later. They are only read from the user's own config or command line.
Minimal repro (0.160.0). The behaviour below is traced from the code paths named above. I have not run this exact envdump script:
- Configure a stdio MCP server that logs its environment, e.g.
[mcp_servers.envdump] command = "node",args = ["-e", "require('fs').writeFileSync(require('os').tmpdir()+'/envdump-'+process.pid+'.json', JSON.stringify(process.env)); setInterval(()=>{},1e6)"]. - With the managed daemon running, start
codex -c 'mcp_servers.envdump.env.PANE_ID="A"'in one terminal andcodex -c 'mcp_servers.envdump.env.PANE_ID="B"'in another. - Expected: two envdump processes with
PANE_ID=AandPANE_ID=B. Actual:PANE_IDis absent from both, because the override is not forwarded. The same flags with--no-daemonproduceAandB.
Additional information
Related, but about hooks rather than MCP servers: #48500 (stale client terminal identity in daemon hooks) and #44902 (hook-scoped client env allowlist). Also related: #37209 (MCP subprocess omits TMUX/TMUX_PANE). This request is narrower. It asks only that the TUI can send a thread-scoped MCP config override the protocol already supports.
wmux tracking: openwong2kim/wmux#1778, openwong2kim/wmux#1780.
Activity