Quick setup guide to use OpenAI Codex as a code reviewer within Claude Code via MCP.
- Claude Code installed
- Node.js and npm installed
- OpenAI Codex installed
Replace YOUR_API_KEY_HERE with your actual OpenAI API key:
claude mcp add --scope user --transport stdio codex \
--env OPENAI_API_KEY=YOUR_API_KEY_HERE \
-- npx -y @openai/codex mcp serveclaude mcp add --scope user --transport stdio codex --env OPENAI_API_KEY=YOUR_API_KEY_HERE -- npx -y @openai/codex mcp serve1. Check MCP connection:
claude mcp listYou should see: codex: npx -y @openai/codex mcp serve - ✓ Connected
2. Test with Claude:
Start a Claude Code session and ask:
"Use the Codex MCP to answer: what is 2+2?"
If you get a response, it's working!
Just ask Claude naturally to use Codex:
"Write a user authentication function, then ask Codex to review it for security issues"
"Ask Codex to review src/parser.py for bugs and performance issues"
"Get Codex's opinion on this implementation approach before we start"
Claude will:
- Read/write the code
- Send it to Codex via MCP for review
- Get feedback (bugs, security, suggestions)
- Evaluate which suggestions are valid
- Implement improvements
- Report findings
The MCP will hang forever if misconfigured!
mcp__codex__codex(
prompt="Review this code...",
approval_policy="never", # Required!
sandbox="read-only"
)mcp__codex__codex(
prompt="Review this code...",
approval_policy="on-request" # Never use this!
)Why? approval_policy="on-request" waits for interactive user approval that never comes, causing an infinite hang.
Note: You don't need to write this code yourself - Claude handles the MCP calls. This is just documentation of what Claude needs to do correctly.
Check:
- Your OpenAI API key is valid:
echo $OPENAI_API_KEY(macOS/Linux) or$env:OPENAI_API_KEY(Windows) - The
@openai/codexpackage is accessible:npx @openai/codex --version - Run
claude mcp listto see detailed error messages
Solution: Remind Claude to use approval_policy="never" in the MCP call.
Provide more context in your request:
- Explain what the code does
- Mention specific concerns (security, performance, edge cases)
- Include relevant constraints or requirements
Remove and re-add the MCP server:
claude mcp remove codex
# Then run the installation command again with new API keyYou: "Write a function to divide two numbers, then ask Codex to review it."
Claude writes:
def divide(a, b):
return a / bClaude asks Codex for review...
Codex responds:
"Missing zero division check on line 2. Will raise ZeroDivisionError if b=0."
Claude fixes:
def divide(a, b):
if b == 0:
raise ValueError("Cannot divide by zero")
return a / bClaude reports:
"Codex identified a critical issue - no zero division handling. I've implemented the fix above."
claude mcp remove codexMIT - Use freely!
Created by: Joey Marshall Resources: