codex-subagent-for-claude
This server lets Claude Code delegate work to a background Codex subagent, then collect results, steer, or interrupt — plus run read-only code reviews.
Dispatch tasks with
codex_spawn: hand Codex a job (prompt, cwd, model, effort, sandbox, worktree, thread_id) and get a task id back immediately; multiple tasks run in parallel in one long-lived Codex process.Fire-and-forget or wait: set
detach=truefor background work, orwait_sto block a short while for fast tasks.Continue threads: pass
thread_id(andpersist) to follow up on an earlier task with full context.Review code with
codex_review: uncommitted changes, diff against a base branch, a specific commit, or custom instructions — read-only, defect-focused, with file:line results.Collect results:
codex_waitblocks for one/all running tasks (mode=all|any, timeout doesn't kill tasks); finished results are also injected back into the session automatically.Monitor progress with
codex_status: list all session tasks, or get details/output (truncated at 6000 chars unlessfull=true).Mid-flight control:
codex_steerredirects a running task after its current step;codex_interruptstops it while keeping completed output and file changes.Run in isolation:
worktree=trueexecutes in a separate git branch (codex-sub/<id>); each Claude window gets its own Codex process.
Integrates with OpenAI's Codex app-server to run tasks as background subagents, supporting async dispatch, parallel execution, mid-flight steering, interruption, code review, and thread continuation.
codex-subagent-for-claude
English | 简体中文
Use Codex as a subagent inside Claude Code: Claude delegates a task, Codex works on it in the background, and the result comes back into Claude's conversation on its own.
Two Python files, no third-party dependencies. Currently verified on Windows 11 only.
Features
Async dispatch:
codex_spawnreturns immediately and Claude carries on. Multiple tasks run in parallel inside one long-lived Codex process, no cold start per taskResults delivered automatically: when Codex finishes, the result shows up in the conversation on Claude's next action, no polling. Claude collects any outstanding results before ending its turn
Mid-flight control:
codex_steersends a follow-up instruction and Codex changes course after its current step;codex_interruptstops a task and keeps what's done; passthread_idto continue a conversationCode review:
codex_reviewruns Codex's built-in review mode — does not modify files, defect-focused, with file and line numbersPer-window isolation: each Claude Code window gets its own Codex process
Independent model settings: subagents default to
gpt-6.1-sol/ reasoning efforthigh/ standard service tier, unaffected by the Codex desktop chat settings; change the defaults via environment variables or override per task (GPT-6.1 Sol / GPT-6 Astra / GPT-6 Sol / GPT-6 Luna)
Related MCP server: Code Worker MCP
How it works
Claude Code ──MCP──> server.py ──JSON-RPC──> codex app-server (long-lived child process)
Claude Code ──hook──> hook.py: injects finished results back into the session that dispatched themRequirements
Windows 11, Python 3.10+ (
pythonon PATH), Claude CodeA logged-in Codex. By default the
codex.exebundled with the Codex desktop app is used (under%LOCALAPPDATA%\OpenAI\Codex\bin\, updated with the app); the app itself does not need to be running. The npm package@openai/codexalso works, or pointCODEX_SUB_BINat any binary. Both share the login and config in~/.codex
Install
Clone anywhere; <install-dir> below stands for that path. You can also just hand these steps to Claude or Codex.
Register the MCP server:
claude mcp add codex-sub -s user -- python "<install-dir>\server.py"Merge the hooks into
~/.claude/settings.json(escape backslashes as\\in JSON):
{
"hooks": {
"UserPromptSubmit": [{"hooks": [{"type": "command", "command": "python \"<install-dir>\\hook.py\" UserPromptSubmit", "timeout": 10}]}],
"PostToolUse": [{"hooks": [{"type": "command", "command": "python \"<install-dir>\\hook.py\" PostToolUse", "timeout": 10}]}],
"Stop": [{"hooks": [{"type": "command", "command": "python \"<install-dir>\\hook.py\" Stop", "timeout": 10}]}]
}
}Optional: add
"mcp__codex-sub"topermissions.allow, otherwise every call asks for confirmation.
Restart your Claude Code session. To try it without touching global config: claude --plugin-dir "<install-dir>".
Usage
Just talk to Claude; it knows when to delegate:
Hand the auth module refactor to Codex. Meanwhile fix the API tests yourself, then merge when it's done.
Have Codex review what I just changed.
Run two Codex tasks in parallel: one fixes
add, one fixesmul, each in its own worktree.
Tool | Purpose |
| Dispatch a task. |
| Code review: uncommitted changes / against a base branch / a commit / custom instructions |
| Wait for results; a timeout only returns the current state, the task keeps running |
| List tasks, or show one task's details and full output |
| Send a follow-up instruction to a running task |
| Interrupt, keeping what has been produced |
Tasks are ephemeral by default and don't appear in Codex history; subagents can use the skills and plugins in
~/.codexFor fire-and-forget work pass
detach=true; Claude won't wait for it when ending its turn
Permissions
Subagents run without a sandbox (sandbox=danger-full-access) and without approvals (approvalPolicy=never) by default: they can edit any file and run any command without stopping to ask, and the occasional question that would need a human answer is skipped so the task never hangs waiting for one. The reason: Codex's Windows sandbox runs commands under a restricted account that cannot see tools installed in the user profile (Python, pnpm, uv, …), so a sandboxed subagent can't even run tests.
codex_review uses the same default: review mode itself does not modify files, but it needs to run git and similar commands. There is no per-task sandbox option: read-only enables the same restricted sandbox, inside which no command can start, so Codex cannot even read files. The default can be changed with CODEX_SUB_SANDBOX.
Configuration
Environment variable | Default |
| auto-detected |
|
|
|
|
|
|
Notes
Relies on some experimental
codex app-serverAPIs; Codex updates may change the protocol. Verified with Codex 0.157 / 0.158Each Claude session keeps one app-server process alive (~150 MB); it exits with the session
Tests: python tests/handshake.py (no Codex needed, seconds) and python tests/smoke.py (calls Codex for real, about 3 minutes).
Uninstall: claude mcp remove codex-sub -s user, then remove the three hooks from settings.json.
License
MIT
Available Tools
6 toolscodex_interruptAIdempotent
中断一个正在运行的任务:Codex 收到后立即停止,已完成的部分输出和文件改动保留,任务状态变为 interrupted,结果可用 codex_status 查看。对已结束的任务调用无副作用,直接返回其结果。被中断的 thread 之后仍可用 codex_spawn(thread_id=...) 续问。只想改方向不想停,用 codex_steer。
Inputs: id (required).
codex_reviewARead-only
用 Codex 内置的代码审查模式(等价于 codex review)审查改动,固定只读、以找缺陷为主,返回按严重度排序、带文件行号的问题列表。scope=uncommitted 审工作区未提交改动;base_branch 审当前分支相对基准分支的改动(value=分支名);commit 审某个提交(value=sha);custom 按自定义说明审(value=说明)。异步/等待语义同 codex_spawn,也返回任务 id。想让 Codex 改代码用 codex_spawn,只想让它挑毛病用这个。
Inputs: cwd, model, scope, value, +2 more.
codex_spawnADestructive
把一个任务派给 Codex 子代理,立即返回 8 位任务 id(wait_s>0 时先等一会儿,等到就直接给结果)。可以连续派多个,它们在同一个常驻 Codex 进程里并行执行。任务完成后结果会自动送回本会话;也可以用 codex_wait 主动等、codex_status 看进度、codex_steer 中途改方向、codex_interrupt 中断。传 thread_id 可在旧任务的上下文上续问;该 thread 上不能有仍在运行的任务。默认无沙箱、不审批:Codex 会直接改文件、跑命令。
Inputs: prompt (required), cwd, model, detach, +6 more.
codex_statusARead-onlyIdempotent
立即返回,不等待。不传 ids:一行一个列出本会话全部任务及状态。传 ids:看详情——运行中的显示最近动作、改动文件、输出预览;已结束的显示完整结果(超过 6000 字截断,full=true 看全文)。被 codex_interrupt 中断的任务,其已产出的部分也从这里取。
Inputs: ids, full.
codex_steerA
给一个正在运行的任务追加或修正指令,Codex 在当前步骤结束后转向,不用重来,已做的工作保留。只对运行中的任务有效;任务已结束时报错,此时应改用 codex_spawn(thread_id=...) 续问。想让它停下来而不是转向,用 codex_interrupt。
Inputs: id (required), prompt (required).
codex_waitARead-onlyIdempotent
阻塞等待一个或多个任务结束并返回它们的结果。不传 ids 就等本会话全部运行中的任务。超时只是返回当前状态,任务不会被杀,可以再次调用继续等。已结束的任务立即返回。等待期间每 10 秒发一次进度通知。只想看一眼不想等,用 codex_status。
Inputs: ids, mode, timeout.
Tool Schema Changelog
Recent tool additions, removals, and schema changes observed during successful MCP inspections.
Loading tool schema changelog…
TDQS
Scored across 6 tools
Each tool targets a distinct lifecycle action (spawn, status, wait, steer, interrupt, review), and descriptions actively disambiguate near-neighbors by naming the alternative ('只想看一眼不想等,用 codex_status'). The main residual overlap is codex_status vs codex_wait, since both return task results, though the blocking-immediate distinction is explained.
All six tools follow a uniform codex_<action> snake_case pattern (spawn, wait, status, steer, interrupt, review). Verbs are consistent and predictable throughout.
Six tools is well-scoped for a subagent-management server, covering spawn, monitoring, control, and review. Every tool earns its place with no redundant additions.
The surface covers the full task lifecycle: dispatch (spawn), monitor (status/wait), control (steer/interrupt), and review, plus thread continuation via thread_id. Minor gap: no explicit tool to enumerate historical/prior threads beyond session-scoped status.
Maintenance
Related MCP Connectors
Shared long-term memory & Stop-hook task handoff across Claude Code, Codex, Cursor, and mobile.
MCP hosting for AI agents: Claude or Codex writes the code, runs it and sends a live link.
Your AI apps as one team: hand work to Codex or Claude Code on your Mac, with a shared logbook.
Your AI mind directs coding agents; work reviewed against your memories: Claude Code, Codex, Cursor
Related MCP Servers
- AlicenseAqualityDmaintenanceEnables Claude Code to delegate tasks to OpenAI's Codex CLI (GPT-5.4) with structured execution traces, parallel execution, session persistence, and adversarial code review.15MIT
- AlicenseNot gradedqualityDmaintenanceEnables Codex to offload expensive code reading, editing, and checking to a worker agent via Claude Code, supporting async jobs and long-running tasks.MIT
- AlicenseNot gradedqualityBmaintenanceEnables Codex to delegate tasks to interactive Claude Code sessions as role-controlled subagents for exploration, code review, and implementation, using the existing Claude Code installation on macOS.MIT
- AlicenseNot gradedqualityBmaintenanceEnables delegating bounded tasks from Codex to Claude Code, including read-only reviews, isolated branch edits, long-running background work, and approval handling.MIT