codex - 💡(How to fix) Fix Expose current thread ID to local stdio MCP servers [2 comments, 2 participants]

Official PRs (…)
ON THIS PAGE

Recommended Tools

×6

Utilities matched from this issue’s tags and category — try them while you read without losing context.

GitHub issue graph ai analysis

Paste a GitHub issue URL. We fetch that issue, discover linked issues from bodies/comments/timeline, collect linked pull requests, and produce a structured English report.

The report is written in English Markdown for sharing and archival.

Helpful · Quick feedback

Loading…
GitHub stats
openai/codex#19937Fetched 2026-04-29 06:25:08
View on GitHub
Comments
2
Participants
2
Timeline
8
Reactions
0
Timeline (top)
labeled ×4commented ×2unlabeled ×2

Error Message

MCP server stderr (clumsies): Error: clumsies MCP server requires a host CLI session id.

Root Cause

MCP servers that record audit logs, per-thread state, rule attestations, or tool-call provenance need to associate MCP tool calls with the active Codex thread. Without a stable Codex-provided thread/session id at MCP startup or tool-call time, these servers must either:

  • invent their own session ids, which cannot be correlated with Codex hooks or shell executions;
  • rely on workspace-global marker files, which break with concurrent sessions;
  • ask the model to pass session ids manually, which is brittle and protocol-polluting;
  • or fail MCP startup, which leaves Codex showing Tools: (none).

This is especially visible for MCP servers that also integrate with Codex hooks: hooks can see the current session/thread identity, while the MCP server cannot, so hook events and MCP tool events cannot be reliably joined.

Code Example

[mcp_servers.my_server]
   command = "my-server"
   args = ["mcp", "serve"]
   env_vars = [{ name = "CODEX_THREAD_ID", source = "thread" }]

---

env | grep CODEX_THREAD_ID
# CODEX_THREAD_ID=019dba93-8214-7d50-a089-9690b4ce6b9e

---

[mcp_servers.clumsies]
command = "clumsies"
args = ["mcp", "serve"]
env_vars = ["CODEX_THREAD_ID"]

---

/mcp

• clumsies
Status: enabled
Command: clumsies mcp serve
Env: CODEX_THREAD_ID=*****
Tools: (none)

---

MCP server stderr (clumsies): Error: clumsies MCP server requires a host CLI session id.

---

{
  "transport": {
    "type": "stdio",
    "command": "clumsies",
    "args": ["mcp", "serve"],
    "env": null,
    "env_vars": ["CODEX_THREAD_ID"]
  }
}

---

codex mcp get clumsies \
  -c 'mcp_servers.clumsies.env_vars=[{name="CODEX_THREAD_ID",source="thread_id"}]' \
  --json

---

unsupported env_vars source `thread_id`; expected `local` or `remote`
RAW_BUFFERClick to expand / collapse

What feature would you like to see?

Expose the current Codex thread/session identity to local stdio MCP servers.

Today CODEX_THREAD_ID is available to shell/tool executions, but it does not appear to be available to stdio MCP server startup. This makes it hard for MCP servers to correlate their tool calls with the active Codex thread.

Concretely, please support one of these:

  1. Inject CODEX_THREAD_ID into local stdio MCP server processes, the same way it is injected into shell tool executions.

  2. Add a supported dynamic MCP env source, for example:

    [mcp_servers.my_server]
    command = "my-server"
    args = ["mcp", "serve"]
    env_vars = [{ name = "CODEX_THREAD_ID", source = "thread" }]
  3. Expose equivalent thread/session metadata to MCP servers through another stable mechanism.

Current behavior

Codex CLI 0.125.0 exposes CODEX_THREAD_ID in shell tool executions. For example, inside a shell tool:

env | grep CODEX_THREAD_ID
# CODEX_THREAD_ID=019dba93-8214-7d50-a089-9690b4ce6b9e

However, a local stdio MCP server configured with:

[mcp_servers.clumsies]
command = "clumsies"
args = ["mcp", "serve"]
env_vars = ["CODEX_THREAD_ID"]

does not receive CODEX_THREAD_ID during MCP startup. The MCP server exits when it requires this env var, and Codex reports the server as enabled but with no tools:

/mcp

• clumsies
  • Status: enabled
  • Command: clumsies mcp serve
  • Env: CODEX_THREAD_ID=*****
  • Tools: (none)

Codex logs show the MCP process did not receive the env var:

MCP server stderr (clumsies): Error: clumsies MCP server requires a host CLI session id.

codex mcp get clumsies --json shows the config was parsed as:

{
  "transport": {
    "type": "stdio",
    "command": "clumsies",
    "args": ["mcp", "serve"],
    "env": null,
    "env_vars": ["CODEX_THREAD_ID"]
  }
}

This suggests env_vars inherits from the MCP launcher process environment, not from the active Codex thread context.

Additional local checks

I tested whether env_vars supports a thread-context source:

codex mcp get clumsies \
  -c 'mcp_servers.clumsies.env_vars=[{name="CODEX_THREAD_ID",source="thread_id"}]' \
  --json

Codex rejects it:

unsupported env_vars source `thread_id`; expected `local` or `remote`

source = "local" parses, but appears to mean the MCP launcher local process environment. source = "remote" parses too, but the binary contains a message indicating it requires remote MCP stdio.

Why this matters

MCP servers that record audit logs, per-thread state, rule attestations, or tool-call provenance need to associate MCP tool calls with the active Codex thread. Without a stable Codex-provided thread/session id at MCP startup or tool-call time, these servers must either:

  • invent their own session ids, which cannot be correlated with Codex hooks or shell executions;
  • rely on workspace-global marker files, which break with concurrent sessions;
  • ask the model to pass session ids manually, which is brittle and protocol-polluting;
  • or fail MCP startup, which leaves Codex showing Tools: (none).

This is especially visible for MCP servers that also integrate with Codex hooks: hooks can see the current session/thread identity, while the MCP server cannot, so hook events and MCP tool events cannot be reliably joined.

Expected behavior

There should be a supported way for local stdio MCP servers to receive the same active Codex thread/session identity that shell tool executions receive.

Environment

  • Codex CLI: codex-cli 0.125.0
  • Platform: macOS arm64
  • MCP transport: local stdio

Related issues

  • #8923 requested programmatic session id exposure.
  • #14097 asks for stable per-agent metadata on tool/subprocess invocation.
  • #4180 shows MCP server subprocess environments can differ from normal shell environments.
  • #4222 mentions CODEX_WORKSPACE_ROOT being injected at tool-call time, which looks similar to the observed CODEX_THREAD_ID behavior.

extent analysis

TL;DR

To fix the issue, Codex should inject the CODEX_THREAD_ID into local stdio MCP server processes or provide a supported dynamic MCP env source to expose the thread/session identity.

Guidance

  • The issue is likely caused by the env_vars configuration inheriting from the MCP launcher process environment instead of the active Codex thread context.
  • To verify, check the Codex logs and the MCP server configuration to confirm that the CODEX_THREAD_ID is not being passed to the MCP server.
  • A potential workaround is to use a different approach to correlate tool calls with the active Codex thread, such as using a workspace-global marker file or passing the session ID manually.
  • The source = "thread" configuration option is not currently supported, but it could be a potential solution if implemented.

Example

No code snippet is provided as the issue is more related to configuration and environment variables.

Notes

The issue is specific to local stdio MCP servers and the Codex CLI version 0.125.0. The solution may vary depending on the specific use case and requirements.

Recommendation

Apply a workaround, such as using a different approach to correlate tool calls with the active Codex thread, until a supported solution is implemented. This is because the current configuration options do not provide a straightforward way to inject the CODEX_THREAD_ID into local stdio MCP server processes.

Vote matrix · Quick signals

Works
Did the solution work? Tap to confirm.
Easy Fix
Was it a quick fix?
Time Saver
Did it save you time?
Blocking
Was it severely blocking?
Common Issue
Are others likely hitting this too?
Flaky / Intermittent
Is it intermittent?
Verified / Reproducible
Can you reproduce it reliably?
Loading…

FAQ

Expected behavior

There should be a supported way for local stdio MCP servers to receive the same active Codex thread/session identity that shell tool executions receive.

Still need to ship something?

×6

Another batch ranked right after the header list — different links, same matching logic.

Back to top recommendations

TRENDING

codex - 💡(How to fix) Fix Expose current thread ID to local stdio MCP servers [2 comments, 2 participants]