
Codex CLI Installation Guide for Mac, Linux, and Windows (2026)
Codex CLI Installation Guide for Mac, Linux, and Windows (2026)#
A lot of developers searching for codex cli installation guide do not actually need another generic install article. They need the shortest path from zero to useful. That means install commands, auth setup, and a way to swap models without rebuilding the workflow.
What is Codex CLI?#
Codex CLI is a terminal-first coding assistant workflow built around AI models for repository analysis, editing suggestions, code generation, and shell-oriented development tasks. It is attractive because it stays close to the developer's real environment.
Codex CLI vs Alternatives#
| Tool | Best for | Strength | Weakness |
|---|---|---|---|
| Codex CLI | terminal-native coding | flexible API-driven workflow | setup quality depends on model config |
| Claude Code | deeper reasoning in many coding tasks | high-quality code understanding | can be pricier |
| Gemini CLI | Google model workflows | good long-context support | ecosystem preference matters |
Step 1: Install the CLI#
The exact package name can change, so always confirm the current official docs. The workflow usually looks like this.
macOS / Linux#
npm install -g @openai/codex
codex --help
Windows (PowerShell)#
npm install -g @openai/codex
codex --help
If global npm installs are restricted, use npx instead.
npx @openai/codex --help
Step 2: Configure the API Key#
If you want provider flexibility, use a unified endpoint.
export OPENAI_API_KEY="YOUR_CRAZYROUTER_KEY"
export OPENAI_BASE_URL="https://crazyrouter.com/v1"
That lets you test coding-focused routes like GPT-5.2, Claude Sonnet, Gemini Pro, or DeepSeek without changing the rest of your OpenAI-compatible tooling.
Step 3: Run the First Prompt#
codex ask "Explain the architecture of this repo and identify dead code."
Step 4: Use API Calls Directly When Needed#
Python#
from openai import OpenAI
client = OpenAI(
api_key="YOUR_CRAZYROUTER_KEY",
base_url="https://crazyrouter.com/v1"
)
resp = client.chat.completions.create(
model="gpt-5.2-codex",
messages=[{"role": "user", "content": "Write integration tests for this FastAPI endpoint."}]
)
print(resp.choices[0].message.content)
Node.js#
import OpenAI from 'openai';
const client = new OpenAI({
apiKey: process.env.OPENAI_API_KEY,
baseURL: process.env.OPENAI_BASE_URL
});
const completion = await client.chat.completions.create({
model: 'gpt-5.2-codex',
messages: [{ role: 'user', content: 'Generate a TypeScript type guard for this schema.' }]
});
console.log(completion.choices[0].message.content);
cURL#
curl https://crazyrouter.com/v1/chat/completions -H "Authorization: Bearer $OPENAI_API_KEY" -H "Content-Type: application/json" -d '{
"model": "gpt-5.2-codex",
"messages": [
{"role": "user", "content": "Refactor this Bash script for readability."}
]
}'
Pricing Breakdown#
| Route | Example input / 1M | Example output / 1M | Notes |
|---|---|---|---|
| GPT-5.2 Codex route | about $0.9625 | about $8.80 | strong coding option |
| GPT-5 route | about $0.6875 | about $8.80 | balanced general use |
| Claude Sonnet route | about $1.65 | about $5.50 | strong coding reasoning |
Troubleshooting#
Command not found#
Your npm global bin path is probably missing from PATH.
Auth errors#
Check OPENAI_API_KEY and whether your CLI expects OPENAI_BASE_URL or a config file.
Model not found#
Use a listed model route from Crazyrouter pricing or the provider's current docs.
FAQ#
How do I install Codex CLI?#
Use npm or npx, then verify with codex --help.
Can I use Codex CLI on Windows?#
Yes. PowerShell works fine as long as Node and npm are installed.
Do I need an OpenAI key only?#
Not necessarily. OpenAI-compatible gateways like Crazyrouter can power the same workflow.
What is the cheapest model for Codex CLI tasks?#
Depends on the task. Premium coding models help on architecture; cheaper models are fine for tests and boilerplate.
Is Codex CLI better than Claude Code?#
Sometimes. Codex CLI is great for terminal-native flexibility. Claude Code may be stronger for harder reasoning tasks.
Summary#
The best Codex CLI installation guide is the one that gets you productive fast: install the package, configure a compatible endpoint, test on a real repository, and route tasks by value. If you want one key and multiple coding models, Crazyrouter is the most practical setup.


