Skip to main content

OpenAI Codex CLI

OpenAI Codex CLI (launched February 2026) is an open-source, terminal-based AI coding agent built in Rust. It competes directly with Claude Code and Kimi Code, offering unique features for developers who prioritize control, customization, and open-source auditability.

Open Source

Codex CLI is released under the Apache 2.0 license. Source code available at github.com/openai/codex.

Key Differentiators

FeatureCodex CLIClaude CodeKimi Code
LicenseApache 2.0 (open-source)ProprietaryApache 2.0
RuntimeRust (fast, low memory)Node.jsNode.js
PhilosophyFine-grained controlDeep reasoningCost efficiency
Custom CommandsYes (Markdown-defined)NoLimited
Memory FileAGENTS.mdCLAUDE.mdN/A
Context Window128K tokens200K tokens256K tokens
Base ModelGPT-5-CodexClaude 4.5Kimi K2.5
PricingChatGPT sub/API$20-200/mo$0.60/$2.50 per 1M

Why Codex CLI Matters

With over 1 million developers using it within the first month of launch, Codex CLI represents a significant shift in the AI coding landscape. It combines OpenAI's latest code-optimized models with a privacy-first, locally-executed architecture.

Key advantages:

  • Performance: Rust-based implementation delivers faster response times and lower memory usage
  • Control: Three-level approval system (suggest, edit, full-auto) plus custom slash commands
  • Transparency: Open-source codebase enables security audits and custom modifications
  • Integration: Native support for Model Context Protocol (MCP) and tool orchestration

Installation

Prerequisites

  • macOS 12+ or Linux (Windows support experimental)
  • Node.js 18+ (for CLI wrapper)
  • OpenAI API key or ChatGPT subscription

Quick Install

# Via npm
npm install -g @openai/codex

# Or download binary
curl -fsSL https://raw.githubusercontent.com/openai/codex/main/install.sh | bash

Authentication

# Set API key
codex auth login

# Or use environment variable
export OPENAI_API_KEY="sk-..."

Core Concepts

AGENTS.md

Similar to Claude Code's CLAUDE.md, Codex CLI uses AGENTS.md for project context:

# Project Agent Configuration

## Role
Senior full-stack developer specializing in TypeScript and React.

## Tech Stack
- Frontend: React 18, TypeScript, Tailwind CSS
- Backend: Node.js, Express, PostgreSQL
- Testing: Jest, React Testing Library

## Patterns
- Use functional components with hooks
- Prefer async/await over raw promises
- Follow RESTful API conventions

## Constraints
- Never expose database credentials
- Always validate user input
- Include error handling for all API calls

Place AGENTS.md in your project root. Codex CLI automatically loads it on startup.

Custom Slash Commands

Define custom commands in ~/.codex/commands/:

<!-- ~/.codex/commands/fix-tests.md -->
# Fix Tests

Run the test suite, identify failures, and fix them.

## Steps
1. Run `npm test` to identify failures
2. Analyze error messages and stack traces
3. Fix the underlying issues
4. Re-run tests to verify fixes
5. Report summary of changes

Usage:

codex /fix-tests

Approval Levels

Codex CLI operates in three permission modes:

LevelDescriptionUse Case
SuggestShows proposed changes, requires manual applicationSecurity-critical code
EditAutomatically edits files, shows diffStandard development
Full-AutoExecutes commands and edits without confirmationTrusted workflows

Configure in ~/.codex/config.json:

{
"approvalMode": "edit",
"allowedCommands": ["npm test", "npm run build"],
"blockedCommands": ["npm publish", "git push"]
}

Security & Governance

Sandboxing

Codex CLI implements defense-in-depth sandboxing:

  • macOS: Apple Seatbelt (sandbox-exec) restricts filesystem and network access
  • Linux: Landlock + seccomp-bpf for syscall filtering
  • Network isolation: Blocks outbound connections by default (configurable)

Enterprise Controls

For AEEF compliance:

  1. Audit Logging: All actions logged to ~/.codex/audit.log
  2. Policy Enforcement: Centralized config via AGENTS.md in version control
  3. Secret Protection: Automatic detection of API keys, tokens in context
  4. Approval Gates: Required for production deployments

AEEF Alignment

PRD-STD-001: Prompt Engineering

Codex CLI supports structured prompting through:

  • AGENTS.md for persistent context
  • Custom slash commands for repeatable patterns
  • Constraint specification in configuration

PRD-STD-002: Code Review

Integration options:

  • --diff-only flag for review-before-apply workflow
  • Git hooks for pre-commit validation
  • CI/CD integration via codex review command

PRD-STD-009: Autonomous Agent Governance

Codex CLI's approval system maps to AEEF's elicitation pattern:

  • Auto-execute: Full-Auto mode with allowlisted commands
  • Elicit: Edit mode with automatic application
  • Approve: Suggest mode for human review

Best Practices

1. Start with AGENTS.md

Always create an AGENTS.md file before starting a project. This establishes context and constraints upfront.

2. Use Approval Levels Appropriately

# High-risk: manual review
codex --approval suggest "Refactor authentication module"

# Standard: auto-edit with diff
codex --approval edit "Add input validation"

# Trusted: full automation
codex --approval full-auto "Run tests and fix failures"

3. Define Custom Commands

Create reusable commands for common workflows:

# /refactor-legacy
Analyze legacy code and suggest modernization:
1. Identify deprecated patterns
2. Propose TypeScript conversions
3. Add missing type definitions
4. Update tests accordingly

4. Version Control Integration

# Stage changes before AI session
git add -A

# Run codex with auto-commit on success
codex --approval edit "Implement feature X" && git commit -m "feat: X (AI-assisted)"

5. Cost Management

Monitor token usage:

codex --dry-run "Complex refactoring"  # Estimate cost

Comparison with Alternatives

Codex CLI vs Claude Code

AspectCodex CLIClaude Code
Setupnpm install, API keynpm install, auth
PhilosophyControl and customizationDeep reasoning and autonomy
Best ForCustom workflows, complianceComplex logic, large refactors
ExtensibilityHigh (custom commands)Medium (CLAUDE.md only)
Open SourceYesNo

Codex CLI vs Kimi Code

AspectCodex CLIKimi Code
ModelGPT-5-CodexKimi K2.5
Context128K256K
CostSubscription/APIPer-token
Unique FeatureCustom commandsAgent Swarm
Best ForControl and auditabilityParallel execution, cost

Troubleshooting

Common Issues

Issue: Commands fail with "permission denied" Solution: Check sandbox permissions in ~/.codex/config.json

Issue: Context not loading from AGENTS.md Solution: Verify file is in project root, restart Codex CLI

Issue: Custom commands not recognized Solution: Check ~/.codex/commands/ directory permissions

Performance Optimization

# For large codebases, use .codexignore
node_modules/
dist/
*.log

Resources