Skip to main content
Codex CLI is OpenAI’s official command-line AI coding agent. It lets you complete code generation, refactoring, debugging, file editing, and system command execution directly from your terminal using natural language. Compared to other AI coding tools, Codex CLI features full sandbox isolation and fine-grained permission control.

Installation

1

Check Node.js Version

Requires Node.js 22+.
2

Install Codex CLI

Configure ePhone AI

Codex CLI uses model_providers to define custom API providers, and the top-level model_provider key to specify which provider to use by default.
1

Set the API Key Environment Variable

2

Create the Configuration File

Add the following to ~/.codex/config.toml:
Three critical settings — all are required:
  • model_provider = "ephone" — without this, Codex routes known model names like gpt-4o directly to OpenAI’s servers
  • wire_api = "responses" — the only protocol supported by Codex, using the Responses API
  • env_key = "OPENAI_API_KEY" — this is the name of the environment variable, not the API key value itself

Getting Started & Approval Modes

On first launch, choose an approval mode that controls how Codex handles permissions: Set the default approval mode in config.toml:

Common Commands

CLI Launch Options

In-Session Commands

Use these slash commands during an interactive session:
Use the /model command to switch models mid-session without restarting.

Project Configuration: AGENTS.md

Codex automatically reads AGENTS.md files on startup as project context instructions, similar to Claude Code’s CLAUDE.md. Through layered configuration, you can set different rules for different projects and directories.

Discovery Order

  1. Global: ~/.codex/AGENTS.md — shared defaults for all projects
  2. Project root: <project-root>/AGENTS.md — project-level rules
  3. Subdirectories: <subdir>/AGENTS.md — subdirectory overrides
Each level also supports AGENTS.override.md, which takes priority over AGENTS.md in the same directory.

Global Configuration Example

Project Configuration Example

Subdirectory Override Example

Configuration Profiles

Profiles let you quickly switch between different configuration sets — ideal for different projects or scenarios:
Switch profiles at launch with --profile:
Each profile needs model_provider = "ephone" — otherwise switching profiles may fall back to the default OpenAI provider.

MCP Server Integration

Codex CLI supports MCP (Model Context Protocol) to connect external tools, significantly extending its Agent capabilities.
Once configured, Codex can query documentation, interact with GitHub, and more — without manually providing context.

Reasoning Control

For models that support reasoning (e.g., o4-mini), you can control reasoning depth:
Higher reasoning effort means deeper thinking but higher token usage. Use medium for daily tasks and high for complex refactoring. Codex supports web search during conversations to fetch the latest documentation and information:
  • cached: Uses an OpenAI-maintained index (default, fast)
  • live: Fetches live web pages (most current info)
  • disabled: Turns off search entirely
You can also enable search at launch with --search:

Sandbox & Security

Codex provides three sandbox levels to protect your system:

Usage Examples

Code Refactoring

Bug Fixing with Screenshots

Project Scaffolding

Git Operations

Code Review

Full Configuration Reference

Troubleshooting

Cause: Missing model_provider = "ephone" in config. Codex routes known model names (like gpt-4o) to the built-in OpenAI provider.Fix: Ensure model_provider = "ephone" is set at the top level of config.toml.If you previously logged into Codex via ChatGPT, also clear cached credentials:
Cause: Missing model_provider configuration, causing Codex to route WebSocket connections to OpenAI’s servers instead of ePhone AI.Fix: Ensure model_provider = "ephone" is set at the top level of config.toml. This routes connections to wss://api.ephone.ai/v1/responses.
Cause: env_key should contain the name of the environment variable (e.g., "OPENAI_API_KEY"), not the API key value itself.Fix: Set env_key = "OPENAI_API_KEY" and make sure the variable is exported via export OPENAI_API_KEY="sk-...".
Cause: The profile doesn’t include model_provider, so it reverts to the default OpenAI provider.Fix: Add model_provider = "ephone" to every profile section.

Important Notes

Codex CLI’s autonomous mode calls the model frequently and executes system commands — token usage is much higher than regular chat. We recommend using a Tier 2 account to avoid hitting rate limits.
  • Set disable_response_storage = true to disable API response storage — required for third-party providers
  • Use the /compact command to compress overly long conversation history and prevent context window limits
  • Log files are located at ~/.codex/log/ — check them for troubleshooting

Official Codex Docs

OpenAI developer documentation

GitHub Repository

Source code & issues

AGENTS.md Spec

Project configuration spec