The Codex MCP Server integrates the Codex CLI into MCP-enabled clients (like Claude Code) for AI-powered code analysis, editing, and automation with safety controls.
Core Capabilities:
Execute Codex Commands (
ask-codex): Send prompts with file analysis using@syntax, supporting 7+ AI models (gpt-5-codex, o3, o4-mini, codex-1, etc.) and image file paths for visual analysisBatch Processing (
batch-codex): Execute multiple atomic tasks with parallel execution for mass refactoring and automated transformationsCreative Brainstorming (
brainstorm): Generate ideas using structured methodologies (SCAMPER, design-thinking, lateral, divergent, convergent) with domain context, feasibility analysis, and innovation scoringSafe Code Editing: Control file system access via sandbox modes (read-only, workspace-write, danger-full-access) and approval policies (never, on-request, on-failure, untrusted)
Structured Refactoring: Use
changeModefor OLD/NEW patch-style edits with chunk-based pagination (fetch-chunk) for large responsesModel Selection: Choose from cloud models or local Ollama server (OSS mode) optimized for different tasks
Web Search Integration: Enable research capabilities via feature flags for latest information retrieval
Configuration Management: Use profiles, feature flags, custom working directories, and per-request overrides
Cross-Platform Support: Works on Windows, macOS, and Linux with enhanced Windows support
Diagnostics: Test connectivity (
ping), view help (Help), check version (version), and test timeout handling (timeout-test)
Provides integration with OpenAI's Codex CLI, enabling code analysis, automated refactoring, documentation generation, and interactive code editing with approval workflows and sandbox execution modes
Codex MCP Tool
Codex MCP Tool is an open‑source Model Context Protocol (MCP) server that connects your IDE or AI assistant (Claude, Cursor, etc.) to the Codex CLI. It enables non‑interactive automation with codex exec, safe sandboxed edits with approvals, and large‑scale code analysis via @ file references. Built for reliability and speed, it streams progress updates, supports structured change mode (OLD/NEW patch output), and integrates cleanly with standard MCP clients for code review, refactoring, documentation, and CI automation.
Latest Release (v1.2.4): Enhanced Windows compatibility - Now using cross-spawn for reliable npm global command execution across all platforms (Windows, macOS, Linux). See changelog
Ask Codex questions from your MCP client, or brainstorm ideas programmatically.
TLDR:
+ Codex CLI
Goal: Use Codex directly from your MCP-enabled editor to analyze and edit code efficiently.
Prerequisites
Before using this tool, ensure you have:
✅ Cross-Platform Support: Fully tested and working on Windows, macOS, and Linux (v1.2.4+)
One-Line Setup
Verify Installation
Type /mcp inside Claude Code to verify the Codex MCP is active.
Alternative: Import from Claude Desktop
If you already have it configured in Claude Desktop:
Add to your Claude Desktop config:
Import to Claude Code:
Configuration
Register the MCP server with your MCP client:
For NPX Usage (Recommended)
Add this configuration to your Claude Desktop config file:
For Global Installation
If you installed globally, use this configuration instead:
Configuration File Locations:
Claude Desktop:
macOS:
~/Library/Application Support/Claude/claude_desktop_config.jsonWindows:
%APPDATA%\Claude\claude_desktop_config.jsonLinux:
~/.config/claude/claude_desktop_config.json
After updating the configuration, restart your terminal session.
Example Workflow
Natural language: "use codex to explain index.html", "understand this repo with @src", "look for vulnerabilities and suggest fixes"
Claude Code: Type
/codex-clito access the MCP server tools.
Usage Examples
Model Selection
With File References (using @ syntax)
ask codex to analyze @src/main.ts and explain what it doesuse codex to summarize @. the current directoryanalyze @package.json and list dependencies
General Questions (without files)
ask codex to explain div centeringask codex about best practices for React development related to @src/components/Button.tsx
Brainstorming & Ideation
brainstorm ways to optimize our CI/CD pipeline using SCAMPER methoduse codex to brainstorm 10 innovative features for our app with feasibility analysisask codex to generate product ideas for the healthcare domain with design-thinking approach
Codex Approvals & Sandbox
Codex CLI supports fine-grained control over permissions and approvals through sandbox modes and approval policies.
Understanding Parameters
The
sandbox: true→ Enables fullAuto mode (equivalent tofullAuto: true)sandbox: false(default) → Does NOT disable sandboxing, just doesn't enable auto modeImportant: The
sandboxparameter is a convenience flag, not a security control
Granular Control Parameters:
sandboxMode: Controls file system access levelapprovalPolicy: Controls when user approval is requiredfullAuto: Shorthand forsandboxMode: "workspace-write"+approvalPolicy: "on-failure"yolo: ⚠️ Bypasses all safety checks (dangerous, not recommended)
Sandbox Modes
Mode | Description | Use Case |
| Analysis only, no file modifications | Code review, exploration, documentation reading |
| Can modify files in workspace | Most development tasks, refactoring, bug fixes |
| Full system access including network | Advanced automation, CI/CD pipelines |
Approval Policies
Policy | Description | When to Use |
| No approvals required | Fully trusted automation |
| Ask before every action | Maximum control, manual review |
| Only ask when operations fail | Balanced automation (recommended) |
| Maximum paranoia mode | Untrusted code or high-risk changes |
Configuration Examples
Example 1: Balanced Automation (Recommended)
Example 2: Quick Automation (Convenience Mode)
Example 3: Read-Only Analysis
Smart Defaults (v1.2+)
Starting from version 1.2.0, the server automatically applies intelligent defaults to prevent permission errors:
✅ If
approvalPolicyis set butsandboxModeis not → auto-setssandboxMode: "workspace-write"✅ If
search: trueoross: true→ auto-setssandboxMode: "workspace-write"(for network access)✅ All commands include
--skip-git-repo-checkto prevent errors in non-git environments
Troubleshooting Permission Errors
If you encounter ❌ Permission Error: Operation blocked by sandbox policy:
Check 1: Verify sandboxMode
Check 2: Use convenience flags
Check 3: Update to latest version
Common Issues
Issue 1: MCP Tool Timeout Error
If you encounter timeout errors when using Codex MCP tools:
Add this to your shell profile (~/.bashrc, ~/.zshrc, or PowerShell profile) to make it permanent.
Issue 2: Codex Cannot Write Files
If Codex responds with permission errors like "Operation blocked by sandbox policy" or "rejected by user approval settings", configure your Codex CLI settings:
Create or edit ~/.codex/config.toml:
⚠️ Security Warning: The danger-full-access mode grants Codex full file system access. Only use this configuration in trusted environments and for tasks you fully understand.
Configuration File Locations:
macOS/Linux:
~/.codex/config.tomlWindows:
%USERPROFILE%\.codex\config.toml
After updating the configuration, restart your MCP client (Claude Desktop, Claude Code, etc.).
Basic Examples
use codex to create and run a Python script that processes dataask codex to safely test @script.py and explain what it does
Default Behavior:
All
codex execcommands automatically include--skip-git-repo-checkto avoid unnecessary git repository checks, as not all execution environments are git repositories.This prevents permission errors when running Codex in non-git directories or when git checks would interfere with automation.
Advanced Examples
Tools (for the AI)
These tools are designed to be used by the AI assistant.
Core Tools
ask-codex: Sends a prompt to Codex viacodex exec.Supports
@file references for including file contentOptional
modelparameter - available models:gpt-5-codex(default, optimized for coding)gpt-5(general purpose, fast reasoning)o3(smartest, deep reasoning)o4-mini(fast & efficient)codex-1(o3-based for software engineering)codex-mini-latest(low-latency code Q&A)gpt-4.1(also available)
sandbox=trueenables--full-automodechangeMode=truereturns structured OLD/NEW editsSupports approval policies and sandbox modes
Automatically includes to prevent permission errors in non-git environments
brainstorm: Generate novel ideas with structured methodologies.Multiple frameworks: divergent, convergent, SCAMPER, design-thinking, lateral
Domain-specific context (software, business, creative, research, product, marketing)
Supports same models as
ask-codex(default:gpt-5-codex)Configurable idea count and analysis depth
Includes feasibility, impact, and innovation scoring
Example:
brainstorm prompt:"ways to improve code review process" domain:"software" methodology:"scamper"
ping: A simple test tool that echoes back a message.Use to verify MCP connection is working
Example:
/codex-cli:ping (MCP) "Hello from Codex MCP!"
help: Shows the Codex CLI help text and available commands.
Advanced Tools
fetch-chunk: Retrieves cached chunks from changeMode responses.Used for paginating large structured edit responses
Requires
cacheKeyandchunkIndexparameters
timeout-test: Test tool for timeout prevention.Runs for a specified duration in milliseconds
Useful for testing long-running operations
Slash Commands (for the User)
You can use these commands directly in Claude Code's interface (compatibility with other clients has not been tested).
/analyze: Analyzes files or directories using Codex, or asks general questions.
prompt(required): The analysis prompt. Use@syntax to include files (e.g.,/analyze prompt:@src/ summarize this directory) or ask general questions (e.g.,/analyze prompt:Please use a web search to find the latest news stories).
/sandbox: Safely tests code or scripts with Codex approval modes.
prompt(required): Code testing request (e.g.,/sandbox prompt:Create and run a Python script that processes CSV dataor/sandbox prompt:@script.py Test this script safely).
/help: Displays the Codex CLI help information.
/ping: Tests the connection to the server.
message(optional): A message to echo back.
Recent Updates
v1.2.4 (2025-10-27)
🔧 Major Improvement:
Windows Compatibility Enhancement: Replaced Node.js native
spawn()with industry-standardcross-spawnpackageRoot cause: Previous
shell: truefix still failed on some Windows configurationsSolution: Use
cross-spawn(50M+ weekly downloads, used by Webpack/Jest) for automatic Windows.cmdhandlingBenefits:
Zero configuration required for Windows users
Automatic handling of
.cmd,.ps1, and.exeextensionsCompatible with both CMD and PowerShell environments
<5ms performance overhead
Dependencies: Added
cross-spawn@^7.0.6and@types/cross-spawn
🐛 Bug Fixes:
Enhanced ENOENT error diagnostics with Windows-specific 4-step troubleshooting guide
Added optional chaining for
stdout/stderrto handle null values in TypeScript strict mode
📝 Documentation:
Added comprehensive Windows troubleshooting section in docs
Documented
spawn codex ENOENTerror resolution steps
v1.2.3 (2025-10-27)
🐛 Bug Fixes:
Windows Compatibility: Fixed Codex CLI detection failing on Windows despite proper installation
Root cause:
spawn()withshell: falsecouldn't resolve.cmdextensions on WindowsSolution: Enabled shell mode for cross-platform command execution
Impact: Zero performance impact (~10ms overhead), maintains security with array-form arguments
Platforms verified: Windows, macOS, Linux via GitHub Actions CI
📝 Documentation:
Updated all package references from
@trishchuk/codex-mcp-toolto@cexll/codex-mcp-serverEnhanced cross-platform setup instructions
🔍 Testing:
CI/CD now validates on Ubuntu, macOS, and Windows across Node.js 18.x, 20.x, and 22.x
v1.2.2 & Earlier
Smart sandbox mode defaults to prevent permission errors
Enhanced debug information for troubleshooting
Automatic
--skip-git-repo-checkflag for non-git environmentsWeb search integration with feature flags
Structured change mode with pagination support
Platform Support
Platform | Status | Notes |
Windows | ✅ Fully Supported | Enhanced in v1.2.4 with cross-spawn |
macOS | ✅ Fully Supported | Tested on Darwin 23.5.0+ |
Linux | ✅ Fully Supported | Tested on Ubuntu Latest |
Minimum Requirements:
Node.js v18.0.0 or higher
Codex CLI installed and authenticated (
npm install -g @openai/codex)
Acknowledgments
This project was inspired by the excellent work from jamubc/gemini-mcp-tool. Special thanks to @jamubc for the original MCP server architecture and implementation patterns.
Contributing
Contributions are welcome! Please submit pull requests or report issues through GitHub.
License
This project is licensed under the MIT License. See the LICENSE file for details.
Disclaimer: This is an unofficial, third-party tool and is not affiliated with, endorsed, or sponsored by OpenAI.