agent-codexcli
Orchestrates the local OpenAI Codex CLI as an execution engine, enabling agents to start and resume Codex sessions, run focused reviews, steer or cancel running tasks, and track Git-based change summaries.
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., "@agent-codexcli Ask Codex to fix the failing tests and summarize the git diff."
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.
Agent-CodexCLI
English | 简体中文
Agent-CodexCLI (agent-codexcli) is an MCP server and Agent Skill that lets any MCP-compatible AI agent orchestrate your local OpenAI Codex CLI as an execution engine — with session reuse, async polling, mid-flight steering, bounded process-tree cleanup, Git diff tracking, and quota safeguards.
Features
Session Reuse (
session_id): Resume existing Codex threads (codex exec resume) to preserve conversation context, prompt cache, and saved session permissions (unless explicitly overridden).Async Execution & Progress Notifications: Long-running tasks return a lightweight
runningpayload (task_id,status,session_id,elapsed_ms) oncewait_secondselapses, emitting MCP progress notifications every 15 seconds when the client supplies aprogressToken. Poll withcodex_waitor check viacodex_status.Mid-Flight Steering (
codex_steer): Interrupt an active run (once itssession_idis available) and immediately resume the samesession_idwith updated instructions (mode: "interrupt", default), or enqueue a follow-up (mode: "queue").Focused Reviews (
codex_review): Runcodex exec review(read-only by default; accepts asandboxoverride) against uncommitted changes, a base branch, a specific commit, or custom instructions.Process-Tree & Pipe Cleanup: Terminates Codex and child processes on Windows (
taskkill+ CIM creation-time bounds) and POSIX (detached process group-pid), with bounded pipe-drain timeouts so leaked descriptors cannot hang callers.Safe Executable Discovery & Git Summaries: Resolves
gitandcodexfrom trusted absolutePATHentries (ignoring working-directory/relativePATHentries and disablingcore.fsmonitor), and captures baseline snapshots before writable runs for best-effortchanged_filesandgit_diff_statreporting.Quota & Reset-Card Safeguards: Automatically stops tasks on HTTP 429 or structured/text quota exhaustion (
status: "rate_limited") and includes a best-effort prompt guard against accidental/usageor quota reset-card triggers.
Related MCP server: codex-app-server-mcp
Prerequisites
Node.js
>= 22.0.0Git on
PATH(required for snapshot-based change reporting and Git tests)Codex CLI (
@openai/codex) installed locally and authenticated (for example viacodex loginor your configured provider in~/.codex/config.toml)
Installation & Build
git clone https://github.com/ZqwerR/Agent-CodexCLI.git
cd Agent-CodexCLI
npm install
npm run buildMCP Client Setup
Generic MCP Client
Add agent-codexcli to your MCP client configuration (replace /path/to/Agent-CodexCLI with your cloned directory):
{
"mcpServers": {
"agent-codexcli": {
"command": "node",
"args": ["/path/to/Agent-CodexCLI/dist/index.js"]
}
}
}Installing the Agent Skill
Copy skills/agent-codexcli to your agent's skills directory (for example ~/.agents/skills/agent-codexcli or ~/.gemini/config/skills/agent-codexcli) so your orchestrator agent follows the recommended workflow automatically.
Antigravity Setup & Best Practices
Antigravity uses a 180-second (3m0s) default per-call MCP timeout (and exposes timeoutSeconds in server configuration). When configuring agent-codexcli in ~/.gemini/config/mcp_config.json, setting both wait budgets to 165 seconds leaves a margin below the default cap (note that launch/Git snapshot work or interrupt steering adds minor overhead, so 165s is a margin rather than a hard guarantee):
{
"mcpServers": {
"agent-codexcli": {
"command": "node",
"args": ["C:/path/to/Agent-CodexCLI/dist/index.js"],
"env": {
"CODEX_DEFAULT_WAIT_SECONDS": "165",
"CODEX_DEFAULT_POLL_WAIT_SECONDS": "165"
}
}
}
}For strict host deadlines, pass
wait_seconds: 0to gettask_idimmediately, then poll with boundedcodex_wait(task_id, wait_seconds: 150).Avoid passing
wait_seconds >= 180inside Antigravity unless you also raisedtimeoutSecondsinmcp_config.json.Copy
skills/agent-codexclito~/.gemini/config/skills/agent-codexclito enable/agent-codexcli.On Windows, see Sandbox, Permissions & Windows Compatibility before opting into
danger-full-access.
Model & Reasoning Effort Inheritance
By default, Agent-CodexCLI does NOT force a model or reasoning effort:
When
CODEX_DEFAULT_MODELandCODEX_DEFAULT_REASONING_EFFORTare unset (and not passed per tool call),agent-codexcliomits--model,review_model, andmodel_reasoning_effortso Codex CLI directly inherits your local~/.codex/config.toml(including custom providers, auth, MCPs, and plugins).If you set
CODEX_DEFAULT_MODELor passmodelper call,codex_run/codex_steerpass--model=..., andcodex_reviewsets both--model=...and-c review_model=....Reported
modelandreasoning_effortfields in task summaries reflect requested overrides (and are omitted when inherited from~/.codex/config.toml).
Sandbox, Permissions & Windows Compatibility
New
codex_runtasks default toworkspace-writeacross all platforms (overridable viaCODEX_DEFAULT_SANDBOXor per-callsandbox). Note that passing an explicit sandbox flag on new runs overrides named Codex permission profiles fromconfig.toml.Resuming sessions (
codex_run(session_id=...)): Whensandboxis omitted on resume,agent-codexcliomits-c sandbox_mode=...so Codex preserves the session's saved permissions instead of silently widening aread-onlysession.codex_reviewdefaults toread-onlyindependently ofCODEX_DEFAULT_SANDBOX(and accepts an explicitsandboxoverride if needed).Windows Trusted-Use Note: Codex CLI's
workspace-writesandbox on Windows can break child commands or file/tool calls. After troubleshootingworkspace-writein trusted repositories, you can explicitly opt in by passingsandbox: "danger-full-access"oncodex_runor setting"CODEX_DEFAULT_SANDBOX": "danger-full-access"in your MCP serverenv.
Operational Notes, Logs & Safeguards
Rate-Limit Circuit Breaker: If Codex outputs HTTP 429 or structured/text quota errors (
insufficient_quota,usage_limit_reached, etc.),agent-codexcliterminates the process tree and preservesstatus: "rate_limited"(rate_limited: true) withrate_limit_reason. Do not automatically retry; report the reason to the user.Best-Effort Reset-Card Prompt Guard: Prompts instructing Codex to run
/usageor redeem a quota reset card are blocked by default (negated mentions like"Do not run /usage"and normal paths likedocs/usage.mdare allowed). Opt out withCODEX_DISABLE_RESET_CARD_GUARD=1(ortrue).codex_steerqueueMode: Rejects per-callmodel,reasoning_effort, andsandboxoverrides (uses saved session settings), and passes the message via CLI flags (--message=...), which are visible to local process inspection and subject to platform command-line length limits.Git Change Summaries: Best-effort snapshots can capture concurrent external workspace edits; untracked files appear in
changed_fileswithout appearing ingit_diff_stat.Diagnostic Logs: Per-task
.logfiles are stored in a private user state directory by default (%LOCALAPPDATA%/agent-codexcli/logson Windows;$XDG_STATE_HOME/agent-codexcli/logsor~/.local/state/agent-codexcli/logson macOS/Linux). Logs contain raw prompts, command output, and diagnostics and may include sensitive project data; retention is bounded byCODEX_MAX_LOG_FILES(default100).
Tool Reference
Tool | Purpose | Key Parameters |
| Start a new Codex task or resume a |
|
| Run |
|
| Wait for a running task to complete or return minimal running status |
|
| Non-blocking check of one task or list of all tracked tasks |
|
| Interrupt & resume a session (default) or enqueue a follow-up |
|
| Terminate a running task and its child process tree |
|
Environment Variables
Variable | Default | Effect |
| (unset — inherits | Default |
| (unset — inherits | Default |
|
| Default sandbox for new |
|
| Initial sync wait for |
|
| Wait budget for |
| Auto-detected | Explicit path or absolute- |
| Private user state dir | Directory for per-task |
|
| Number of completed tasks retained in memory (5–500). |
|
| Maximum simultaneous active Codex tasks (1–50). |
|
| Maximum retained |
| (empty) | Comma-separated regexes or substrings for custom provider rate-limit detection. |
|
| Set to |
Development & Testing
npm install
npm run typecheck
npm run build
npm testnpm test runs TypeScript type-checking, compiles dist/, and executes the regression suite in tests/regression.test.mjs using tests/fake-codex.mjs.
License
Available Tools
6 toolscodex_cancelB
Terminate a running Codex background task and its child process tree.
Inputs: task_id (required).
codex_reviewA
Run a code review with Codex CLI (codex exec review), read-only by default (accepts sandbox override).
Defaults: sandbox="read-only", model=(inherited from ~/.codex/config.toml), reasoning_effort=(inherited from ~/.codex/config.toml), wait_seconds=300.
When model is specified (or CODEX_DEFAULT_MODEL is set), it also sets Codex's review_model override.
If no review target (uncommitted/base/commit/prompt) is provided, defaults to uncommitted changes.
Inputs: cwd (required), base, model, title, +8 more.
codex_runA
Run Codex CLI (Executor) on a task or continue an existing Codex session via session_id. Inherits ~/.codex/config.toml (model, reasoning effort, custom provider, auth, MCPs, plugins, notify), disables unbounded_connection_retries, and applies a best-effort reset-card prompt guard (opt out via CODEX_DISABLE_RESET_CARD_GUARD=1 or true). Defaults for new runs: model=(inherited from ~/.codex/config.toml), reasoning_effort=(inherited from ~/.codex/config.toml), sandbox="workspace-write", wait_seconds=300. When session_id is provided and sandbox is omitted, saved session permissions are preserved instead of reapplying CODEX_DEFAULT_SANDBOX. Progress notifications are emitted every 15s when the client supplies a progressToken. If execution exceeds wait_seconds, returns status="running" with task_id so you can call codex_wait / codex_status / codex_cancel. If status="rate_limited", STOP immediately and ask the user; never retry or trigger a reset card.
Inputs: cwd (required), prompt (required), model, images, +7 more.
codex_statusA
Non-blocking check of a specific Codex task_id, or omit task_id to list all active and recent Codex tasks managed by this server.
Inputs: task_id.
codex_steerA
Send a new or updated instruction to an in-progress or existing Codex session. Two modes:
"interrupt" (DEFAULT): Cancels the running Codex task (if active and session_id is known) and resumes the same session_id with the new prompt so Codex stops obsolete work right away.
"queue": Enqueues a follow-up independently via CLI arguments (subject to platform command-line length and process visibility limits) using saved session settings; rejects per-call model, reasoning_effort, and sandbox overrides. Use only when explicitly requested. Applies the best-effort reset-card prompt guard unless CODEX_DISABLE_RESET_CARD_GUARD=1 or true.
Inputs: prompt (required), cwd, mode, model, +9 more.
codex_waitA
Wait up to wait_seconds (default 180) for a background Codex task to finish. Returns minimal status ({task_id, status, session_id, elapsed_ms}) while still running, and full structured output once finished. Emits progress notifications every 15s when the client supplies a progressToken.
Inputs: task_id (required), wait_seconds.
Tool Schema Changelog
Recent tool additions, removals, and schema changes observed during successful MCP inspections.
Loading tool schema changelog…
TDQS
Scored across 6 tools
codex_run and codex_steer can both target an existing session, but the descriptions separate continuing a run from interrupting/steering it. wait, status, cancel, and review are clearly differentiated, leaving only minor overlap around session continuation.
All six tools use the codex_ prefix plus a concise snake_case action (run, review, wait, status, steer, cancel), making names highly predictable. status is a noun rather than a verb, but it still fits the consistent action-style pattern.
Six tools map neatly to launching, reviewing, monitoring, waiting on, steering, and cancelling Codex CLI work. There is no obvious padding, and the count is well-scoped for an async CLI execution wrapper.
The set covers the core async execution lifecycle and a read-only review path, with status also serving as a list operation. Minor gaps remain: no dedicated output/history retrieval beyond wait/status, and session management is only implicit through run and steer.
Maintenance
Related MCP Connectors
A paid remote MCP for OpenAI Codex agent coordination MCP, built to return verdicts, receipts, usage
Shared memory MCP server for Claude Code, Codex, Gemini CLI and Cursor. Cited, editable.
A paid remote MCP for OpenAI Codex harness MCP, built to return verdicts, receipts, usage logs, and
A paid remote MCP for OpenAI Codex context compressor, built to return verdicts, receipts, usage log
Related MCP Servers
- AlicenseAqualityCmaintenanceEnables MCP-compatible coding agents to execute the local Codex CLI as a coding agent, including code reviews, session resume/fork, and CLI diagnostics.9MIT
- AlicenseAqualityBmaintenanceEnables Claude Code or any MCP client to delegate hands-on coding work to OpenAI Codex over a persistent app-server process, keeping long-lived threads with follow-ups, async polling, approvals, steering, and interrupts. Supports native code review, resuming existing sessions, structured output, and parallel worktree-isolated tasks.1024 npm1MIT
- AlicenseNot gradedqualityCmaintenanceWraps the Codex engine in a local stdio MCP server so any MCP-capable agent can run coding turns as tools, with blocking runs, start/poll progress, command approvals, interrupts, thread resume, and token usage. It also supports custom OpenAI-compatible providers, letting teams blocked by signup, payment, or network limits still use the engine.MIT
- AlicenseAqualityCmaintenanceBridges the OpenAI Codex CLI app-server to MCP clients, letting agents launch and resume Codex coding sessions within a chosen workspace under configurable sandbox and approval policies. It exposes tools for sending prompts, long-polling task progress and live command output, approving or canceling runtime requests, and listing or reading past session history.5MIT