
OpenAI released Codex CLI in early 2025—a tool that lets you write code, edit files, and run commands directly in your terminal using AI. Unlike ChatGPT on the web, Codex CLI’s core strength is directly manipulating your local filesystem, so AI actually gets work done instead of just handing you snippets to paste.
This guide covers the complete setup from installation to your first task, taking about 10 minutes.
Prerequisites
You’ll need two things:
- Node.js 18+ (verify with
node --version) - OpenAI API Key (get it from platform.openai.com)
Your API key must have a linked payment method; free credits don’t support the models Codex uses.
Installation
npm install -g @openai/codex
Verify it worked:
codex --version
Authentication Setup
There are two ways to configure your API key:
Method 1: Environment Variable (Recommended)
export OPENAI_API_KEY="sk-xxxx..."
Add it to ~/.zshrc or ~/.bashrc to persist it:
echo 'export OPENAI_API_KEY="sk-xxxx..."' >> ~/.zshrc
source ~/.zshrc
Method 2: Runtime Input
Just run codex and it’ll prompt you for your API key on first launch. It saves to ~/.codex/config.json.
Three Operating Modes
Codex CLI is built around progressive autonomy—you choose how much you trust it with, based on your comfort level:
| Mode | Command | Behavior |
|---|---|---|
suggest (default) | codex | AI gives suggestions, requires your approval for each step |
auto | codex --approval-mode auto-edit | Auto-edits files, but asks for confirmation on shell commands |
full-auto | codex --approval-mode full-auto | Fully automatic, no confirmation needed for files or commands |
Beginners should start with suggest mode to get a feel for what it can and can’t do.
Your First Run
Start it up:
codex
Once in the interactive interface, describe your task in natural language.
Example 1: Understanding a Complex Function
> Help me understand the main.py in the current directory
Codex will read the file and explain the key logic.
Example 2: Modifying Code
> Update the parse_date function in utils.py to support a timezone parameter, defaulting to UTC
It’ll:
- Read
utils.py - Locate the
parse_datefunction - Present the modification plan and wait for your approval
- Write the changes to the file once you confirm
Example 3: Executing System Tasks
> Find Python files modified in the last 7 days in the current directory and list them
It generates the find command, executes it after your confirmation, and shows you the results.
Sandbox Mode
In full-auto mode, Codex executes commands in macOS’s sandbox environment (uses Docker on Linux) to prevent accidental operations from affecting other parts of your system.
Check sandbox status:
codex --help | grep sandbox
If you don’t need the sandbox (for example, you’re already in a Docker container), you can skip it with --no-sandbox.
Specifying the Model
Codex uses codex-mini-latest by default, but you can switch to more powerful models:
codex --model o4-mini
Or o3 (more capable but pricier):
codex --model o3
For everyday code tasks, codex-mini-latest is fast, cheap, and sufficient. Only upgrade to o4-mini or above for complex refactoring or architectural design.
Configuration Files
Codex supports a project-level configuration file, AGENTS.md (place it in your project root), to give AI additional context:
# AGENTS.md
This project is a Python algorithmic trading strategy using the Binance API.
## Code Standards
- Function names use snake_case
- All logging uses structlog
- All database operations go through db/repository.py
## Important Notes
- Don't modify config/secrets.py
- Backtesting logic is in the backtest/ directory
With this file in place, Codex will follow these rules when working on this project without you having to repeat yourself every time.
Cost Estimation
Codex CLI charges based on OpenAI API tokens, not a flat monthly fee.
In practice, a complete small task (reading + modifying + explaining a file) typically uses:
codex-mini-latest: $0.002–0.01o4-mini: $0.02–0.1
Daily usage runs about $5–20 a month, more flexible than a subscription.
Codex CLI vs Claude Code
I’ve used both for a while now, and here’s how they differ:
| Aspect | Codex CLI | Claude Code |
|---|---|---|
| Underlying Model | o3 / codex-mini (OpenAI) | Claude Sonnet / Opus (Anthropic) |
| Code Ability | Strong, o3 handles refactoring well | Strong, excellent long-context understanding |
| Tool Integration | Focused on code and terminal | Supports MCP/Skill extensions |
| Pricing | Pay-as-you-go (API) | Fixed monthly (Claude Pro) |
| Context Window | o3: 200k | Claude Opus 4.6: 200k |
Neither is objectively better—it depends on which account you already have and what type of work you’re mainly doing. I use Codex CLI for Python refactoring, Claude Code for ops automation and multi-tool orchestration.
Getting Started: Writing a Trading Monitor Script with Codex CLI
If you’re new to CLI AI tools, an easy entry point that delivers immediate value is writing a monitoring script for your trading account. For example:
- Monitor Pionex bots and send Telegram alerts when they hit range edges
- Monitor Binance perpetual accounts and get warnings before liquidation
- Analyze historical logs to find patterns
You can write it in 30 minutes and it delivers real value in production. If you haven’t touched crypto quant yet, Pionex is the lowest-barrier entry point.
If you run into any installation issues, drop a comment below.
📷 Cover · Generated with Flux Schnell AI · panshi.io brand style