A local stdio MCP server that lets Claude Code agents and subagents ask OpenAI Codex for an independent opinion (typically a read-only review of their changes) and follow up on the same Codex thread later.
codex_ask: start a Codex thread in a project directory and get the answer plus athread_id.codex_followup: continue that thread ("I fixed 1 and 3, re-check").- Per call:
model,effort,fast,sandbox,timeout_sec. - Runs in an isolated
CODEX_HOME(~/.codex-reviews), so these threads never show up in the Codex desktop app. - Safe for many parallel callers: one process and temp dir per call, no shared state, plus a cross-process lock per thread.
- Windows first (tested on Windows 10 with the Codex desktop app and codex-cli 0.163). macOS/Linux should work but are untested.
- Node.js >= 20.3
- The Codex CLI. On Windows it ships with the Codex desktop app; a separately installed
codexworks too (see How Codex is found). - A ChatGPT account that can use Codex.
git clone https://github.com/NtTestAlert/cc-codex-mcp.git
cd cc-codex-mcp
npm install
npm run buildThe isolated home has its own login. auth.json is never copied or linked from ~/.codex, because token
refreshes rewrite that file.
Windows (PowerShell):
powershell -ExecutionPolicy Bypass -File scripts\login.ps1
# or by hand:
$env:CODEX_HOME="$HOME\.codex-reviews"; & "$env:LOCALAPPDATA\Codex\versions\current\resources\codex.exe" loginAdd -DeviceAuth (or --device-auth) if no browser can open. On macOS/Linux:
CODEX_HOME="$HOME/.codex-reviews" codex login.
Until you log in, every tool call returns an error containing this command.
Claude Code's CLI and the Claude desktop app (Code tab) share the same user-scope MCP config (~/.claude.json), so
one registration covers both. Use an absolute path to a real node.exe: version-manager shims (Volta, nvm-windows)
can pick a different Node per project, and Volta's shim also mangles </> in arguments.
claude mcp add-json --scope user cc-codex-mcp '{"type":"stdio","command":"C:/path/to/node.exe","args":["C:/path/to/cc-codex-mcp/dist/index.js"],"timeout":3700000}'
claude mcp get cc-codex-mcpclaude mcp get should show Status: ✔ Connected. New Claude Code sessions (CLI or desktop) pick it up; sessions
that were already open need a restart. Tools appear as mcp__cc-codex-mcp__codex_ask and
mcp__cc-codex-mcp__codex_followup.
Other MCP clients (Claude Desktop chat, Cursor, etc.) use the usual stdio entry: command = absolute node,
args = [".../dist/index.js"].
Claude Code has two limits on MCP tool calls (checked in Claude Code 2.1.277 / desktop 2.1.299):
- a hard wall-clock limit: the per-server
"timeout"(ms) if set, otherwiseMCP_TOOL_TIMEOUT, otherwise about 28 h; - an idle limit,
CLAUDE_CODE_MCP_TOOL_IDLE_TIMEOUT(default 30 min for stdio), which progress notifications reset.
The per-server "timeout": 3700000 above covers the maximum timeout_sec (3600). It works in both the CLI and the
desktop app, regardless of environment-variable precedence (under the desktop app, a variable already in the host's
environment wins over settings.json env). The server sends a progress notification every ~15 s while Codex runs,
which keeps the idle limit from firing. You don't need to set MCP_TOOL_TIMEOUT; setting it would lower the 28 h
default for every server.
See CLAUDE.snippet.md: drop it into a project's CLAUDE.md. Implementer subagents then get a
read-only review when they finish, fix real issues, re-check on the same thread, stop after 3 rounds, and never use
fast mode unless told to.
node dist/index.js --doctorThis prints the resolved Codex executable, the isolated home and login state, and the MCP sync report: each server,
its transport, and whether default_tools_approval_mode is set. It also creates the isolated home if needed and runs one real config
sync, so it may update the isolated config.toml (never ~/.codex).
| input | default | |
|---|---|---|
prompt |
required | sent on stdin, so no quoting issues |
cwd |
required | project directory (-C) |
sandbox |
read-only |
or workspace-write |
model |
config default | -m |
effort |
config default | low|medium|high|xhigh|max|ultra → -c model_reasoning_effort="…"; checked against the model's supported levels |
fast |
false |
-c service_tier="fast" -c features.fast_mode=true; uses about 2.5x the subscription limits |
skip_git_check |
false |
--skip-git-repo-check |
timeout_sec |
900 | 10…3600; on timeout the whole process tree is killed (taskkill /T /F) |
Runs codex exec --json --color never -C <cwd> -s <sandbox> [...] -o <temp file> -.
Inputs: thread_id (a UUID, validated, and it must exist in the isolated home), prompt, plus optional model,
effort, fast, timeout_sec. Runs codex exec resume --json --skip-git-repo-check -c sandbox_mode="<original>" [...] -o <temp file> <thread_id> -, with the process working directory set to the thread's original cwd. If that directory no longer exists, it runs
from your home directory and says so in warnings.
{
"thread_id": "0199a1b2-c3d4-7e5f-8a9b-0c1d2e3f4a5b",
"answer": "…",
"duration_sec": 7.5,
"warnings": [],
"activity": { "commands": 2, "mcp_tool_calls": ["openaiDeveloperDocs.search_openai_docs (completed)"], "subagent_events": 0 },
"error": "…only when something failed…",
"answer_file": "…only when the answer was truncated…"
}answeris the-ofile (falling back to the lastagent_message), ANSI-stripped and capped at 50,000 characters. When it's longer, the full text stays inanswer_file.warningscollects MCP server startup failures, failed or rejected MCP tool calls, declined commands, unsupported service tier / fast-mode messages, config problems, and config-sync errors.- On
turn.failed,errorevents in a turn that didn't complete, a non-zero exit, a timeout or cancellation,errorholds the message plus the last 40 stderr lines. Any partial answer and thethread_idare still returned. activityis only present when Codex ran commands, called MCP tools, or spawned subagents.
| variable | default | |
|---|---|---|
CODEX_BRIDGE_HOME |
~/.codex-reviews |
isolated CODEX_HOME; refused if it resolves to the main home |
CODEX_BRIDGE_SOURCE_HOME |
~/.codex |
main Codex home (source of truth for config and sandbox state) |
CODEX_BRIDGE_CODEX_PATH |
auto | explicit Codex executable (.exe, .js, or an npm .cmd/.ps1 shim to unwrap) |
CODEX_BRIDGE_COPY_CONFIG |
unset | 1 = copy ~/.codex/config.toml once if the isolated home has none |
CODEX_BRIDGE_MCP_EXCLUDE |
unset | comma-separated MCP server names not to sync |
CODEX_BRIDGE_SYNC_DESKTOP_ONLY |
unset | 1 = also sync desktop-only servers such as node_repl |
CODEX_BRIDGE_CODEX_PATH.codexonPATH. An npmcodex.cmdshim is unwrapped to the nativecodex.exeinside the npm package, or tobin/codex.jsrun with the current Node. A shell is never used.- The desktop app:
%LOCALAPPDATA%\Codex\versions\current\resources\codex.exe(currentis a junction to the newest version), else the highestversions\<x.y.z.w>folder. On macOS,/Applications/Codex.app/Contents/Resources/codex.
The desktop app's ~/.codex is the source of truth. The bridge only reads it and only writes the isolated home.
Config sync (config.toml): at startup, then when ~/.codex/config.toml changes (fs.watch, debounced 1 s),
plus a cheap mtime/size check before each run in case the watcher missed an event. The sync copies:
- the
[mcp_servers.*]tables (per server name the source wins; servers only in the isolated config are kept; servers removed from the source are removed again); - top-level
modelandmodel_reasoning_effort; - the
[windows]table. Withoutwindows.sandbox, Codex on Windows blocks every shell command in read-only mode, evengit diff.
All other isolated-config keys are kept. Writes are atomic and only happen when the synced subset actually changed.
The file is parsed with a real TOML parser (smol-toml), so comments in the isolated config are not preserved.
Desktop-only servers are skipped by default (node_repl needs the desktop app's named pipe and hard-codes
CODEX_HOME=~/.codex).
Elevated Windows sandbox state. The elevated sandbox runs commands as two machine-wide local accounts
(CodexSandboxOffline / CodexSandboxOnline). Each CODEX_HOME keeps its own DPAPI-encrypted copy of their
passwords (.sandbox-secrets/sandbox_users.json) and a .sandbox/setup_marker.json. If two homes each provision,
every provisioning rotates the passwords and makes the other home re-run the elevated setup, endlessly. So the
desktop app's home owns this state, and the bridge copies those two files into the isolated home at startup and
whenever the desktop app rewrites them (fs.watch). Nothing happens per call. The isolated home never provisions
while the desktop app has a provisioned sandbox, and ~/.codex is never written.
Normal Codex behaviour is unaffected: a quick, non-elevated codex-windows-sandbox-setup.exe "setup refresh" still
runs before sandboxed commands, as it does in the desktop app.
Not shared: auth.json (separate login), MCP OAuth tokens (see below), sessions/threads, history, memories.
node dist/index.js --doctor lists every synced server and whether it sets default_tools_approval_mode = "approve".
The bridge never changes that setting. In testing, read-only MCP tools ran fine under exec without it. If a server's
tool calls get rejected for approval, warnings says so; add default_tools_approval_mode = "approve" to that server
in ~/.codex/config.toml and the sync carries it over.
With Codex 0.163 on Windows, OAuth tokens for remote MCP servers are stored per CODEX_HOME:
CODEX_HOME\secrets\mcp_oauth.age, with its key in Windows Credential Manager under an account derived from the
CODEX_HOME path. The isolated home does not see the desktop app's tokens. To log a server in for the isolated home:
$env:CODEX_HOME="$HOME\.codex-reviews"; & "$env:LOCALAPPDATA\Codex\versions\current\resources\codex.exe" mcp login <server>Remote plugins enabled on your ChatGPT account are installed into every home, including the isolated one, so their
OAuth MCP servers need this login too. Until a server is logged in, each run carries a harmless AuthRequired
warning for it. Servers that authenticate with headers or bearer_token_env_var in config.toml need nothing extra.
exec:--json,-o,-C,-s read-only|workspace-write|danger-full-access,-m,-c key=value(TOML value),--skip-git-repo-check, and-/ no prompt = read stdin all exist. The first JSON event is{"type":"thread.started","thread_id":…}. Thread ids are UUIDv7.exec resume: accepts-c,-m,--json,-o,--skip-git-repo-checkand-for stdin. It has no-Cand no-s, and it runs in the process cwd, not the thread's original cwd. So the bridge spawns it in the original cwd (read from the rollout file) and keeps the sandbox with-c sandbox_mode="…".- Fast mode:
-c service_tier="fast"is accepted and recorded asservice_tier: "priority". An unsupported tier produces anerroritem ("…not advertised as supported for model…"), which lands inwarnings. - Reasoning effort key:
model_reasoning_effort. Supported levels come from Codex's own model list (<CODEX_HOME>/models_cache.json); at the time of writing the models offeredlow, medium, high, xhigh, maxand most alsoultra, and none offeredminimal. Before starting Codex, the bridge checkseffortagainst the effective model: themodelinput, else the thread's model for follow-ups, else the configured default. An unsupported level is rejected with the supported list. Unknown models are passed through unchecked. Verified live:low,xhigh,maxandultraare each recorded as the turn'sreasoning_effort. - Subagents (
multi_agent, stable) work underexec: the child thread hasthread_source: "subagent"and the parent'sparent_thread_id.
- Occasionally a run sits for several minutes waiting on the model API (seen: 225 s and ~438 s for a one-word reply, both with and without fast mode; the next identical runs took ~7 s). The default 900 s timeout covers it.
- Settings this Codex version doesn't recognise produce a warning on every run until they're removed from
~/.codex/config.toml. - On Windows, if
codex.exeitself crashes while a grandchild still holds its pipes, that grandchild can outlive it (Node can't put children in a Job Object). Timeouts, cancellation and shutdown kill the whole tree. - The thread lock is a lockfile with a 30 s heartbeat. A crashed holder is reclaimed after its PID is gone, or after 2 minutes without a heartbeat.
- macOS/Linux paths are implemented but untested.
npm test # build + node:test (unit tests use temp dirs and a fake codex)
node dist/index.js --doctorLayout: src/index.ts (MCP tools), runner.ts (spawn, JSONL parsing, timeout and tree kill), codexPath.ts,
lock.ts, configSync.ts, sandboxMirror.ts, home.ts, sessions.ts, util.ts.