This document explains how codex-bridge is structured for maintainers.
codex-bridge is an MCP server over stdio. The published npm package is @ndcorder/codex-bridge, and the binary is codex-bridge.
Entry points:
src/cli.ts: command dispatcher.codex-bridge initruns setup; any other invocation starts the MCP server.src/index.ts: MCP server construction and tool registration.src/tools.ts: tool handlers, session lookup, risk radar, research/debug orchestration.src/codex.ts: Codex CLI process execution, timeouts, retries, model resolution, and output capture.src/session.ts: in-memory session history, stats, and working memory.src/research-artifacts.ts: durable research dossier writer.src/prompts.ts: prompt builders and bridge system prompt.
src/index.ts creates an McpServer named codex-bridge at version 1.1.0 and connects it to StdioServerTransport.
Each tool registration defines:
- tool name
- description shown to the MCP client
- Zod input schema
- handler that returns MCP text content
Most Codex-backed tools catch errors and return an MCP error response with isError: true.
src/codex.ts shells out to the Codex CLI with execFile, not a shell string.
The wrapper:
- resolves model from request,
CODEX_BRIDGE_MODEL,CODEX_MODEL, or defaultgpt-5.3-codex - writes Codex output to a temporary file with
-o - passes large prompts through stdin to avoid argv size limits
- applies timeout and retry controls
- caps captured stderr so huge prompt or command dumps do not flood errors
- removes temporary directories in a
finallyblock
The default timeout is 120000 milliseconds. The default retry count is 1. The default retry backoff is 500 milliseconds.
src/tools.ts stores sessions in an in-memory Map.
Session key resolution order:
- explicit
session_id working_dirdefault
Session controls:
CODEX_BRIDGE_MAX_SESSIONS: max session count, default200CODEX_BRIDGE_SESSION_TTL_MS: inactivity TTL, default86400000
When max sessions is exceeded, the oldest touched sessions are evicted. TTL cleanup runs opportunistically when sessions are accessed or listed.
Session stores recent exchanges and extracts lightweight working memory:
- current plan from
codex_plan - high/critical findings from
codex_review - risk radar summary from
codex_risk_radar - research findings from
codex_research - debug verdict from
codex_debug
This context is injected into later prompts where relevant.
codex_research can write a durable dossier when working_dir is provided.
Path shape:
<working_dir>/.codex-bridge/research/<timestamp-topic-uuid>/
Files include:
metadata.jsonreport.mdsources.mdopen-questions.mdfollow-ups.mdturn-XX-<phase>.mdprompts/turn-XX-<phase>.md
Directory creation is exclusive and retries with a UUID suffix to avoid collisions.
codex_risk_radar is local and does not call Codex.
It scans added diff lines and optional commit message text for categories such as:
- auth/permissions
- input parsing
- async/concurrency
- state/caches
- crypto/secrets
- database/queries
- file/network I/O
- error handling
It stores the risk summary in session memory for follow-on planning or review.
Primary test layers:
- Unit tests in
tests/*.test.ts - MCP stdio smoke test in
tests/mcp-smoke.test.ts - Bake-off black-box tests under
benchmark/bakeoff
Common commands:
npm run build
npm test
npm run test:bakeoff
npm run verifyRelease verification uses:
npm run release:prepareThis runs verify, package dry-run, and release notes generation.
The npm package intentionally ships runtime output and docs only:
dist/srcREADME.mdCHANGELOG.mddocs/*.md
Build artifacts under dist/tests and benchmark sources are not published.