How to Install OpenAI Codex CLI on Linux, macOS & WSL
What is Codex CLI?
Codex CLI is OpenAIās open-source terminal coding assistant. It reads your codebase, edits files, and runs commands ā similar to Claude Code but fully open-source (Apache-2.0) with 85k+ GitHub stars.
I use it alongside Claude Code. For quick questions and small edits, Codex is faster. For deep refactoring across many files, Claude Code wins.
Installation Demo
Full installation on a fresh machine. Scrub the timeline or adjust speed:
How to Install Codex CLI
Prerequisites
- Linux, macOS, or WSL
- A ChatGPT Plus account OR an OpenAI API key
Step 1: Run the Installer
# Recommended: official installer
curl -fsSL https://chatgpt.com/codex/install.sh | sh
# Alternative: macOS via Homebrew
brew install --cask codex
# Alternative: npm
npm install -g @openai/codex
Done when: codex --version prints something like codex-cli 0.133.0.
Step 2: Authenticate
Two options:
Option A: ChatGPT Account (simplest)
codex
Select āSign in with ChatGPTā on first run. Browser opens for OAuth.
Option B: API Key
Edit ~/.codex/config.toml:
model = "gpt-4o"
approval_policy = "on-request"
[model_providers.openai]
name = "OpenAI"
base_url = "https://api.openai.com/v1"
experimental_bearer_token = "sk-your-key-here"
wire_api = "responses"
Step 3: Verify
codex "Hello, what model are you running?"
Done when: You get a response with the model name.
How to Configure a Custom API Endpoint
For self-hosted or third-party OpenAI-compatible APIs:
model = "gpt-4o"
model_provider = "custom"
[model_providers.custom]
name = "My Proxy"
base_url = "https://your-proxy.example.com/v1"
experimental_bearer_token = "sk-your-key"
wire_api = "responses"
supports_websockets = false
Any endpoint that implements the OpenAI /v1/responses or /v1/chat/completions API works.
What Are the Three Approval Modes?
Codex CLI has a unique safety system ā you choose how much autonomy to give it:
| Mode | What It Does | When to Use |
|---|---|---|
| Read Only | Can only read files, no modifications | Code review, understanding a new codebase |
| On Request | Asks before each write/execute action | Daily development (recommended default) |
| Full Access | Fully autonomous, no confirmations | Trusted automation, CI pipelines |
Set at startup:
codex --approval-mode full-access
Or in config:
approval_policy = "on-request"
What Can Codex CLI Do?
| Task | Command | Notes |
|---|---|---|
| Explain code | codex "What does this function do?" | Reads surrounding context |
| Generate code | codex "Write a REST API for user management" | Creates files, installs deps |
| Fix errors | codex "This test is failing, fix it" | Reads error output, patches |
| Refactor | codex "Convert this to TypeScript" | Multi-file changes |
| Run tasks | codex "Set up ESLint and fix all warnings" | Installs, configures, runs |
How Does Codex CLI Compare to Claude Code?
| Codex CLI | Claude Code | |
|---|---|---|
| License | Apache-2.0 (open source) | Proprietary |
| Models | GPT-4o, o3 | Claude Opus, Sonnet |
| Context window | 200K tokens | 200K tokens |
| Safety modes | 3-tier approval system | Permission config file |
| Plugins | Community ecosystem | None |
| Strength | Quick tasks, extensible | Deep understanding, complex refactoring |
| Cost | ChatGPT Plus ($20/mo) or API | Claude Pro ($20/mo) or API |
My recommendation: Install both. Use Codex for quick edits and questions. Use Claude Code for multi-file refactoring and architecture work. They complement each other.
Tips From Daily Use
/modelto switch models mid-session. GPT-4o for speed, o3 for complex reasoning./helpshows all slash commands. There are more than youād expect.- Paste screenshots. Codex CLI accepts image input ā paste error screenshots directly.
- Start from project root. Same as Claude Code ā context matters.
Troubleshooting
āAuthentication failedā with ChatGPT account
Clear the cached session:
rm -rf ~/.codex/auth*
codex
Then re-authenticate.
Slow or no response
Check your API connectivity:
curl -I https://api.openai.com/v1/models
If this fails, check firewall/proxy settings.
āModel not foundā error
Your account may not have access to the requested model. Try switching:
codex --model gpt-4o
Links
- Codex CLI GitHub (85k+ stars)
- OpenAI Platform (API keys & billing)
- Codex CLI Docs