codex-bridge
Drives OpenAI Codex through the @openai/codex-sdk, maintaining persistent Codex threads per session key and sending bounded tasks for read-only analysis or workspace-write code changes.
Click on "Deploy Server".
Wait a few minutes for the server to deploy. Once ready, it will show a "Started" state.
In the chat, type
@followed by the MCP server name and your instructions, e.g., "@codex-bridge Use codex_analyze to review src/api for bugs with session api:review."
That's it! The server will respond to your query, and you can continue using it as needed.
Here is a step-by-step guide with screenshots.
claude-codex-bridge
🤖 用 AI 助手安装: 让你的 AI 助手 (Claude Code, Codex, Cursor 等) 读 AI-INSTALL.md, 按里面的步骤检查, 询问并安装. Using an AI assistant? Ask it to read AI-INSTALL.md and follow it.
配套的规则与模板在 https://github.com/harrison-ming/ai-workflows .
中文
这是什么
一个本地运行的 MCP (Model Context Protocol) stdio 服务器. Claude Code 调用它, 它再通过 @openai/codex-sdk 驱动 OpenAI Codex.
思路很简单: 一个 AI 当指挥, 一个 AI 干活. Claude 负责理解需求, 拆任务, 验收结果; Codex 接收边界清楚的小任务去分析或修改代码. 桥接器为每个 session_key 保存一个持久的 Codex 会话 (thread), 所以 Claude 可以在同一个项目里反复把任务交给 "同一个" Codex, 它记得之前的上下文.
环境要求
Node.js >= 22.13 (用到内置的
node:sqlite)已安装并登录 Codex CLI (桥接器使用本机的 Codex / ChatGPT 登录, 不读取
OPENAI_API_KEY)Claude Code
从源码安装
git clone https://github.com/harrison-ming/claude-codex-bridge.git
cd claude-codex-bridge
npm ci
npm run build构建产物在 dist/index.js.
注册到 Claude Code
claude mcp add codex-bridge -- node /path/to/claude-codex-bridge/dist/index.jsClaude Code 会在项目目录里启动 MCP 服务器, 默认情况下桥接器只允许 Codex 在这个启动目录 (及其子目录) 里工作. 如果要允许多个目录, 用环境变量指定:
claude mcp add codex-bridge \
-e CODEX_BRIDGE_ALLOWED_ROOTS="$HOME/projects/my-app:$HOME/projects/my-lib" \
-- node /path/to/claude-codex-bridge/dist/index.js多个目录之间用系统路径分隔符隔开 (macOS / Linux 是 :, Windows 是 ;).
MCP 工具
工具 | 作用 | Codex 沙箱 |
| 新建或续接一个持久的 Codex 会话, 只读分析 |
|
| 新建或续接一个持久的 Codex 会话, 允许修改工作区 |
|
| 列出桥接器保存的会话, 可按 | 不调用 Codex |
| 软归档或恢复一个会话映射, 不删除 Codex 端的历史. 允许根目录之外的会话同样返回 | 不调用 Codex |
codex_analyze 与 codex_execute 的参数:
参数 | 说明 |
| 会话名, 1-128 个字符, 只能是字母, 数字, |
| 交给 Codex 的任务, 最长 200,000 个字符 |
| 工作目录, 必须是绝对路径. 首次创建会话时必填, 之后可省略; 会话永久绑定到首次使用时的规范路径 (解析符号链接之后), 之后传不同的目录会报错 |
| 默认 |
同一个会话可以先用 codex_analyze 再用 codex_execute, 它们共用同一个 Codex thread, 沙箱模式按每次调用决定.
codex_sessions 参数: cwd (可选, 必须在允许列表内), include_archived (默认 false).
codex_session_archive 参数: session_key, archived (默认 true, 设为 false 即恢复).
返回内容: codex_analyze / codex_execute 的文本内容是 Codex 的最终回复, 结构化内容包含 session_key, thread_id, cwd, sandbox_mode, resumed, response, usage. codex_sessions 返回 sessions 数组, codex_session_archive 返回 session 对象, 每个会话对象包含 session_key, thread_id, cwd, sandbox_mode, status, archived, created_at, updated_at, last_used_at, archived_at, last_error. status 是最近一个回合的状态 (pending / active / error), 是否归档看单独的布尔字段 archived.
出错时工具返回 isError: true 和一个错误码, 例如 CWD_REQUIRED, WORKSPACE_NOT_ALLOWED, SESSION_CWD_MISMATCH, SESSION_ARCHIVED, SESSION_RETRY_REQUIRED, SESSION_BUSY, SESSION_NOT_FOUND, CODEX_TURN_FAILED.
配置
环境变量 | 默认值 | 说明 |
| 服务器启动时的当前目录 | 允许 Codex 工作的根目录列表, 用系统路径分隔符隔开. 每个根目录必须存在且是目录 |
| macOS: | 状态目录, 存放会话数据库 |
|
|
|
我的用法
先计划: 在 Claude 里把需求想清楚, 拆成几个互相独立, 能单独验证的小任务.
一次只派一个小任务: 给任务起一个稳定的
session_key(例如my-app:auth-refactor), 先用codex_analyze让 Codex 读代码给方案, 确认后再用codex_execute让它动手. prompt 里写清楚范围, 不做什么, 怎么算完成.验证: Claude 自己看 diff, 跑测试, 不直接相信 Codex 的总结.
单独一轮审查: 用另一个
session_key开一个新会话, 用codex_analyze只读审查这次改动, 避免让写代码的那个会话审查自己.
任务做完后用 codex_session_archive 归档, 让会话列表保持干净.
安全说明
工作区允许列表:
cwd必须是绝对路径, 解析符号链接后必须落在某个允许的根目录之内. 同名前缀的兄弟目录 (例如my-app-other) 和指向外部的符号链接都会被拒绝.环境变量过滤: 传给 Codex 子进程的环境变量是白名单 (
PATH,HOME, 语言, 代理, 证书,CODEX_HOME,XDG_*等).OPENAI_API_KEY,OPENAI_BASE_URL,CODEX_API_KEY等认证变量永远不会传过去, 所以 Codex 使用的是本机登录.Codex 运行选项: 审批策略固定为
never, 关闭网络访问, 永远不使用danger-full-access沙箱.会话锁: 同一个
session_key同一时间只能跑一个回合, 另一个调用会很快返回SESSION_BUSY. 不同的会话互不影响.错误信息脱敏: 返回给 Claude 的错误信息会遮掉看起来像 OpenAI key,
OPENAI_API_KEY=...,CODEX_API_KEY=...和Bearer ...的内容, 并截断到 2000 字符.
更多细节见 docs/security-model.md, 架构见 docs/architecture.md.
局限
实际的文件系统隔离靠的是 Codex 自己的沙箱和本机 Codex 配置, 桥接器只负责选择沙箱模式和检查
cwd.codex_execute下 Codex 可以修改整个工作目录里的文件, 请配合 git 使用, 便于检查和回滚.Codex 网络访问是关闭的, 需要联网的步骤 (例如安装依赖) 要由你或 Claude 自己完成.
一个回合在 Codex 返回之前会一直占着 MCP 调用, 没有流式输出和中途取消.
会话绑定的目录不能修改, 换目录就换一个
session_key.只在本机单用户场景下设计和测试, 不是多用户服务.
许可证
MIT, 见 LICENSE.
Related MCP server: claude-code-codex-agents
English
What it is
A local MCP (Model Context Protocol) stdio server. Claude Code calls it, and it drives OpenAI Codex through @openai/codex-sdk.
The idea: one commander AI, one worker AI. Claude understands the goal, breaks it into tasks and checks the results; Codex receives small, bounded tasks to analyze or change code. The bridge keeps one persistent Codex thread per session_key, so Claude can keep handing work to the "same" Codex within a project and it remembers earlier context.
Requirements
Node.js >= 22.13 (uses the built-in
node:sqlite)Codex CLI installed and logged in (the bridge uses your local Codex / ChatGPT login and does not read
OPENAI_API_KEY)Claude Code
Install from source
git clone https://github.com/harrison-ming/claude-codex-bridge.git
cd claude-codex-bridge
npm ci
npm run buildThe entry point is dist/index.js.
Register with Claude Code
claude mcp add codex-bridge -- node /path/to/claude-codex-bridge/dist/index.jsClaude Code starts MCP servers in the project directory. By default the bridge only lets Codex work in that launch directory and its subdirectories. To allow several directories, set an environment variable:
claude mcp add codex-bridge \
-e CODEX_BRIDGE_ALLOWED_ROOTS="$HOME/projects/my-app:$HOME/projects/my-lib" \
-- node /path/to/claude-codex-bridge/dist/index.jsSeparate entries with the platform path delimiter (: on macOS / Linux, ; on Windows).
MCP tools
Tool | Purpose | Codex sandbox |
| Start or resume a persistent Codex thread for read-only analysis |
|
| Start or resume a persistent Codex thread that may change the workspace |
|
| List saved bridge sessions, optionally filtered by | does not call Codex |
| Soft-archive or restore a session mapping; never deletes Codex thread history. Sessions outside the allowed roots also return | does not call Codex |
Parameters of codex_analyze and codex_execute:
Parameter | Description |
| Session name, 1-128 characters: letters, digits, |
| The task for Codex, up to 200,000 characters |
| Absolute working directory. Required when the session is created, optional afterwards. A session is permanently bound to the canonical path (symlinks resolved) of its first use; passing a different directory later fails with |
| Default |
One session can use codex_analyze and then codex_execute; both continue the same Codex thread, and the sandbox mode is chosen per call.
codex_sessions parameters: cwd (optional, must be allow-listed), include_archived (default false).
codex_session_archive parameters: session_key, archived (default true; false restores).
Output: the text content of codex_analyze / codex_execute is Codex's final response; the structured content holds session_key, thread_id, cwd, sandbox_mode, resumed, response and usage. codex_sessions returns a sessions array and codex_session_archive returns a session object; each session object holds session_key, thread_id, cwd, sandbox_mode, status, archived, created_at, updated_at, last_used_at, archived_at and last_error. status is the state of the last turn (pending / active / error); archival is the separate boolean archived.
On failure a tool returns isError: true with an error code such as CWD_REQUIRED, WORKSPACE_NOT_ALLOWED, SESSION_CWD_MISMATCH, SESSION_ARCHIVED, SESSION_RETRY_REQUIRED, SESSION_BUSY, SESSION_NOT_FOUND, CODEX_TURN_FAILED.
Configuration
Variable | Default | Description |
| the directory the server was launched from | Roots Codex may work in, separated by the platform path delimiter. Each root must exist and be a directory |
| macOS: | State directory holding the session database |
|
|
|
How I use it
Plan: think the goal through in Claude and split it into small tasks that are independent and verifiable on their own.
Dispatch one small task at a time: give it a stable
session_key(for examplemy-app:auth-refactor), ask Codex for a plan withcodex_analyze, then let it make the change withcodex_execute. State the scope, what not to touch, and what "done" means.Verify: Claude reads the diff and runs the tests itself instead of trusting Codex's summary.
Separate review round: open a new session under a different
session_keyand run a read-only review withcodex_analyze, so the session that wrote the code does not review itself.
Archive finished sessions with codex_session_archive to keep the list clean.
Security notes
Workspace allow-list:
cwdmust be absolute and, after resolving symlinks, fall inside an allowed root. Same-prefix siblings (for examplemy-app-other) and symlinks pointing outside are rejected.Environment filtering: the Codex child process gets an allow-listed environment (
PATH,HOME, locale, proxy, certificate variables,CODEX_HOME,XDG_*, and similar). Auth variables such asOPENAI_API_KEY,OPENAI_BASE_URLandCODEX_API_KEYare never forwarded, so Codex uses your local login.Codex run options: approval policy is fixed to
never, network access is disabled, and thedanger-full-accesssandbox is never used.Session locks: only one turn per
session_keyruns at a time; a concurrent call returnsSESSION_BUSYquickly. Different sessions do not block each other.Error redaction: error messages returned to Claude mask strings that look like OpenAI keys,
OPENAI_API_KEY=...,CODEX_API_KEY=...andBearer ..., and are truncated to 2000 characters.
See docs/security-model.md and docs/architecture.md for details.
Limitations
Actual filesystem isolation comes from Codex's own sandbox and your local Codex configuration; the bridge only picks the sandbox mode and checks
cwd.Under
codex_execute, Codex can change any file in the working directory. Use git so you can inspect and roll back.Codex network access is disabled; steps that need the network (such as installing dependencies) must be done by you or Claude.
A turn blocks the MCP call until Codex returns; there is no streaming or mid-turn cancellation.
A session's directory cannot be changed; use a new
session_keyfor a different directory.Designed and tested for a single local user, not as a multi-user service.
License
MIT, see LICENSE.
Available Tools
4 toolscodex_analyzeAnalyze with CodexBRead-only
Start or resume a persistent Codex thread in a read-only filesystem sandbox.
Inputs: prompt (required), session_key (required), cwd, retry_failed.
codex_executeExecute with CodexADestructive
Start or resume a persistent Codex thread using Codex workspace-write at an allowlisted cwd. Effective filesystem access also follows local Codex sandbox policy.
Inputs: prompt (required), session_key (required), cwd, retry_failed.
codex_session_archiveArchive or restore a Codex sessionBIdempotent
Soft-archive or restore a bridge mapping. This never deletes the underlying Codex thread history.
Inputs: session_key (required), archived.
codex_sessionsList Codex sessionsBRead-onlyIdempotent
List persistent bridge sessions, optionally filtered by an allowlisted canonical workspace.
Inputs: cwd, include_archived.
Tool Schema Changelog
Recent tool additions, removals, and schema changes observed during successful MCP inspections.
Loading tool schema changelog…
TDQS
Scored across 4 tools
codex_analyze and codex_execute both start/resume a persistent Codex thread and differ only in sandbox write access, which is a subtle distinction an agent could misjudge. The descriptions do explicitly name read-only vs workspace-write, so the boundary is recoverable. The two session tools (list vs archive/restore) are clearly distinct.
All tools share a predictable codex_ snake_case prefix, making the family obvious at a glance. The suffix convention wavers slightly: codex_analyze/codex_execute are verbs, codex_sessions is a bare noun, and codex_session_archive is a noun_verb compound. This is readable but not a single uniform pattern.
Four tools is well-scoped for a thin bridge that launches threads and manages session mappings. It is slightly lean, since there is no dedicated tool to fetch a thread's output or metadata, but nothing is redundant.
The surface covers launching/executing work, listing session mappings, and archiving/restoring them, which is a coherent lifecycle for the bridge layer. However there is no tool to inspect an individual session's details, retrieve prior thread output/history, or hard-delete a mapping, leaving agents without a way to read back results through the bridge.
Maintenance
Related MCP Connectors
Shared memory MCP server for Claude Code, Codex, Gemini CLI and Cursor. Cited, editable.
No-data MCP handoff for local Claude Code to Codex harness moves. $49 lifetime.
A paid remote MCP for OpenAI Codex agent coordination MCP, built to return verdicts, receipts, usage
Persistent memory and cross-session learning for AI coding assistants (hosted remote MCP).
Related MCP Servers
- AlicenseNot gradedqualityDmaintenanceEnables MCP clients to spawn and control Codex CLI and Claude Code sessions on the host machine, with session management and filesystem access.4MIT
- 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 Claude Code to delegate bounded, read-only analysis and isolated patch proposals to the locally installed Codex CLI over MCP, with sanitized live status, revision-aware polling, and reviewable results.1MIT
- AlicenseAqualityBmaintenanceEnables Claude Code to delegate coding tasks—investigation, review, long-running background jobs, and optional file edits—to a locally installed OpenAI Codex CLI, with the model and reasoning effort chosen per task and read-only execution by default. Follow-up requests reuse Codex's existing context, and write-enabled delegations can be confined to a managed git worktree so the user's own checkout stays untouched.9320 npm1MIT