This guide covers how to use Anthropic's Claude Code and OpenAI's Codex CLI together effectively. Both are terminal-based AI coding agents, and they complement each other well.
Codex CLI is OpenAI's open-source (Apache 2.0) coding agent that runs in your terminal. First released April 2025, it's built in Rust and supports GPT models optimized for coding.
Install:
# npm
npm install -g @openai/codex
# Homebrew (macOS)
brew install --cask codexAuthenticate via ChatGPT sign-in (works with existing Plus/Pro/Team plans) or API key.
| Claude Code | Codex CLI | |
|---|---|---|
| Models | Claude Opus 4.6, Sonnet 4.5 | GPT-5-Codex |
| Instructions file | CLAUDE.md |
AGENTS.md |
| Sandbox | macOS Seatbelt, configurable | Sandboxed by default (configurable via sandbox_mode) |
| Approval modes | Permission rules in settings.json | approval_policy + sandbox_mode in config.toml; --auto-edit / --full-auto flags |
| Multi-agent | Subagents, agent teams (experimental) | Single agent (parallelize manually) |
| Slash commands | Skills/commands system | Not built-in |
| License | Proprietary | Apache 2.0 |
| Config | ~/.claude/settings.json |
~/.codex/config.toml |
Both tools are highly capable across all tasks. In practice, use whichever you're more fluent with. Some reasons to reach for one over the other:
- Claude Code has built-in multi-agent support (subagents, agent teams), skills/commands, and hooks
- Codex CLI is open-source, has strict sandboxing by default, and works with your existing ChatGPT subscription
- When you're stuck with one tool, try the other -- different models sometimes see different solutions
The key to using both tools on the same project is a shared instructions file.
Put universal instructions in AGENTS.md and configure both tools to read it:
For Codex CLI: Reads AGENTS.md automatically.
For Claude Code: Add a fallback in CLAUDE.md:
# Project Instructions
See @AGENTS.md for build commands, architecture, and conventions.
# Claude Code-Specific
- Use `/self-review` before creating PRs
- Use subagents for codebase explorationln -s AGENTS.md CLAUDE.mdSimple but you lose the ability to have tool-specific instructions.
AGENTS.md # Universal instructions (both tools read this)
CLAUDE.md # @AGENTS.md + Claude-specific features
This is the recommended approach -- it gives you cross-tool compatibility while letting you use tool-specific features.
Codex can also be configured to read CLAUDE.md as a fallback in ~/.codex/config.toml:
project_doc_fallback_filenames = ["CLAUDE.md", "COPILOT.md"]Codex discovers AGENTS.md using a cascading hierarchy:
- Home directory (
~/.codex/AGENTS.md): Global defaults - Project root → current directory: Walks down, reads one file per directory
- Override files:
AGENTS.override.mdtakes priority overAGENTS.mdin the same directory
Files are concatenated from root down. The closest file to the edited code wins for conflicting instructions.
See templates/AGENTS.md for a starter template.
# Session 1: Claude Code implements the feature
claude
> "Implement the CSV export feature described in issue #234"
# Session 2: Codex reviews the implementation
codex "Review the changes on this branch for bugs, security issues, and test coverage"Ask both tools to solve the same problem independently, then compare approaches:
# Git worktrees keep both isolated
git worktree add ../feature-claude feature-branch-claude
git worktree add ../feature-codex feature-branch-codex
# Terminal 1
cd ../feature-claude && claude
# Terminal 2
cd ../feature-codex && codexUse git worktrees to run both tools simultaneously on different tasks:
git worktree add ../task-auth auth-refactor
git worktree add ../task-api api-endpoints
# Run Claude Code on auth refactor
cd ../task-auth && claude
# Run Codex on API endpoints
cd ../task-api && codex- Write the spec/tests with one tool
- Implement with the other
- The implementation tool can't "cheat" because it didn't write the tests
Configured via ~/.codex/config.toml with two independent settings:
approval_policy:"untrusted"(prompts before actions) or"on-request"(auto-approves)sandbox_mode:"read-only","workspace-write", or"danger-full-access"
Interactive UX flags:
codex --auto-edit # Auto-approve file edits, prompt for commands
codex --full-auto # No prompts, but sandboxedmodel = "gpt-5-codex"
approval_policy = "untrusted"
sandbox_mode = "workspace-write"
[profiles.fast]
model = "gpt-5-codex"
approval_policy = "on-request"- Keep AGENTS.md under 150 lines. Same principle as CLAUDE.md -- long files bury the signal.
- Wrap commands in backticks in both files so agents can copy-paste them.
- Use git worktrees when running both tools simultaneously to avoid file conflicts.
- Don't fight the tools. If one tool is struggling with a task, try the other instead of correcting it repeatedly.
- Update instructions when things change. Both tools rely on accurate build/test commands.
Both tools offer subscription-based access and pay-per-token API access. Check current pricing at claude.ai and chatgpt.com as plans and pricing change frequently.
For teams doing heavy AI-assisted development, having access to both gives you flexibility to use whichever is faster, cheaper, or better for the specific task at hand.