Skip to content

How to Install OpenAI Codex CLI on Linux, macOS & WSL

Ā· 4 min read

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:

ModeWhat It DoesWhen to Use
Read OnlyCan only read files, no modificationsCode review, understanding a new codebase
On RequestAsks before each write/execute actionDaily development (recommended default)
Full AccessFully autonomous, no confirmationsTrusted automation, CI pipelines

Set at startup:

codex --approval-mode full-access

Or in config:

approval_policy = "on-request"

What Can Codex CLI Do?

TaskCommandNotes
Explain codecodex "What does this function do?"Reads surrounding context
Generate codecodex "Write a REST API for user management"Creates files, installs deps
Fix errorscodex "This test is failing, fix it"Reads error output, patches
Refactorcodex "Convert this to TypeScript"Multi-file changes
Run taskscodex "Set up ESLint and fix all warnings"Installs, configures, runs

How Does Codex CLI Compare to Claude Code?

Codex CLIClaude Code
LicenseApache-2.0 (open source)Proprietary
ModelsGPT-4o, o3Claude Opus, Sonnet
Context window200K tokens200K tokens
Safety modes3-tier approval systemPermission config file
PluginsCommunity ecosystemNone
StrengthQuick tasks, extensibleDeep understanding, complex refactoring
CostChatGPT Plus ($20/mo) or APIClaude 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

  • /model to switch models mid-session. GPT-4o for speed, o3 for complex reasoning.
  • /help shows 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

FAQ

Is Codex CLI free?
The tool itself is free and open-source (Apache-2.0). But you need a ChatGPT Plus subscription or an OpenAI API key to use it. API usage is billed per token.
Does Codex CLI work on Windows?
Yes, via WSL. Native Windows is not supported. Install WSL first, then follow the Linux installation steps.
What models does Codex CLI support?
GPT-4o, o3, and other OpenAI models. Switch models during a session with the /model command.
Codex CLI vs Claude Code — which is better?
They're complementary. Codex CLI is open-source with a plugin ecosystem and works well for quick tasks. Claude Code has deeper code understanding and handles complex refactoring better. Install both.
Can I use Codex CLI without a ChatGPT subscription?
Yes. You can use any OpenAI-compatible API endpoint by configuring a custom model provider in ~/.codex/config.toml.

Related Posts