agent-codexcli
You can orchestrate local OpenAI Codex CLI tasks from an MCP client with async execution, session reuse, steering, reviews, monitoring, and cancellation.
Start new Codex runs or resume existing sessions (
codex_run) with prompt, cwd, model/reasoning/sandbox overrides, images, extra writable dirs, worktree support, and configurable wait budgets.Wait for or poll background tasks (
codex_wait,codex_status) with progress notifications, incremental unread output, and task listing.Steer active or existing sessions (
codex_steer) by interrupting and resuming the same session, or queueing follow-up instructions.Run Codex code reviews (
codex_review) against uncommitted changes, a base branch, a specific commit, or custom review instructions; read-only by default.Cancel running tasks and terminate their child process trees (
codex_cancel).Use foreground live terminal viewing, Git change/diff summaries, session permission preservation, quota/rate-limit safeguards, and best-effort prompt guards.
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-MCP-SKILL
English | 简体中文
Agent-CodexCLI-MCP-SKILL (MCP server & Skill identifier: 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.Foreground Live Terminal Viewer opens by default when a desktop terminal is available. Pass
foreground: falseto run in the background.Incremental Conversational Output appears in
new_messageson running and terminal summaries.codex_statuscan peek at unread updates between polls.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-MCP-SKILL.git
cd Agent-CodexCLI-MCP-SKILL
npm install
npm run buildMCP Client Setup
Interactive Configuration Wizard
Run npm run setup from the source checkout, or agent-codexcli setup if the CLI is installed. Press Enter to keep the displayed value. The wizard saves viewer settings, wait budgets, the sandbox for new runs, model and reasoning effort overrides, and the reset-card guard. It prints a ready-to-paste mcp_config.json snippet that points to dist/index.js and the selected config file.
The precedence is per-call arguments > environment variables > config.json > built-in defaults. The server reads the file at startup. Restart your MCP server after changing saved settings.
Windows uses
%APPDATA%/agent-codexcli/config.jsonand falls back to%LOCALAPPDATA%/agent-codexcli/config.json.On macOS and Linux, an absolute
XDG_CONFIG_HOMEselects$XDG_CONFIG_HOME/agent-codexcli/config.json. Otherwise the path is~/.config/agent-codexcli/config.json.CODEX_CONFIG_PATHselects a different file. Useagent-codexcli setup --config <path>to select one from the wizard.Use
agent-codexcli setup --showto see the saved and effective server settings, oragent-codexcli setup --resetto delete the saved file. With npm, pass flags after--, as innpm run setup -- --show.
Generic MCP Client
Add agent-codexcli to your MCP client configuration (replace /path/to/Agent-CodexCLI-MCP-SKILL with your cloned directory):
{
"mcpServers": {
"agent-codexcli": {
"command": "node",
"args": ["/path/to/Agent-CodexCLI-MCP-SKILL/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. Choose the Antigravity preset in the wizard or set both wait budgets to 165 seconds in ~/.gemini/config/mcp_config.json as shown below. This leaves room for launch, Git snapshot, and interrupt steering overhead.
{
"mcpServers": {
"agent-codexcli": {
"command": "node",
"args": ["C:/path/to/Agent-CodexCLI-MCP-SKILL/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.
Foreground Live Terminal Viewer & Toggle
codex_run, codex_review, and interrupt-mode codex_steer can open a separate terminal with live task output. On Windows the launcher prioritizes native PowerShell via conhost.exe and does not require Windows Terminal. macOS uses Terminal, and Linux auto-detects a supported terminal emulator. In CI, headless sessions, or when launch fails, the task continues in the background.
Pass foreground: false for a background run or foreground: true to request the viewer for a single call. The viewer stays open after completion by default. Enable auto-close and set its delay in the wizard or with the environment variables below. On macOS, foregroundAutoClose exits the viewer and shell. Terminal.app closes the window according to the profile’s “When the shell exits” setting. Once the viewer connects, manually closing it during a run cancels the task by default. Set CODEX_FOREGROUND_CLOSE_CANCELS_TASK=0 to let the task continue when the viewer closes.
Incremental Unread Conversational Output
Running and terminal summaries include new_messages when unread conversational agent_message text is available. Each poll includes up to 4,000 characters total, keeping the newest messages. Consuming calls such as codex_run and codex_wait mark omitted overflow as delivered too. Inspect log_path for the full history. codex_status, with or without a task_id, peeks at the same updates without consuming them. Use final_message for the completed task’s final reply.
Model & Reasoning Effort Inheritance
By default, Agent-CodexCLI-MCP-SKILL does NOT force a model or reasoning effort:
With no resolved model or reasoning effort override,
agent-codexcliomits--model,review_model, andmodel_reasoning_effortso Codex CLI directly inherits your local~/.codex/config.toml(including custom providers, auth, MCPs, and plugins). Enterinheritin the wizard to clear a saved override.A model override from a call, an environment variable, or
config.jsonmakescodex_runand interruptcodex_steerpass--model=....codex_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. Change the default in the wizard or withCODEX_DEFAULT_SANDBOX, or passsandboxper call. 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: Uses saved session settings, rejects per-callmodel,reasoning_effort,sandbox, andforegroundoverrides, 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, with a read-only peek at |
|
| 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 |
|
| Open the foreground viewer by default when a terminal is available. |
|
| Close the viewer automatically after the task finishes. |
|
| Delay before auto-close (0–60 seconds). |
|
| Cancel a running task when its viewer is closed manually. |
| Platform user config path | Override the path to |
| 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
- AlicenseAqualityDmaintenanceEnables 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.1042 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