Login
Back to Blog
Codex CLI Installation Guide for Mac, Linux, and Windows (2026)

Codex CLI Installation Guide for Mac, Linux, and Windows (2026)

C
Crazyrouter Team
March 15, 2026
5 viewsEnglishTutorial
Share:

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#

ToolBest forStrengthWeakness
Codex CLIterminal-native codingflexible API-driven workflowsetup quality depends on model config
Claude Codedeeper reasoning in many coding taskshigh-quality code understandingcan be pricier
Gemini CLIGoogle model workflowsgood long-context supportecosystem 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#

bash
npm install -g @openai/codex
codex --help

Windows (PowerShell)#

powershell
npm install -g @openai/codex
codex --help

If global npm installs are restricted, use npx instead.

bash
npx @openai/codex --help

Step 2: Configure the API Key#

If you want provider flexibility, use a unified endpoint.

bash
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#

bash
codex ask "Explain the architecture of this repo and identify dead code."

Step 4: Use API Calls Directly When Needed#

Python#

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#

javascript
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#

bash
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#

RouteExample input / 1MExample output / 1MNotes
GPT-5.2 Codex routeabout $0.9625about $8.80strong coding option
GPT-5 routeabout $0.6875about $8.80balanced general use
Claude Sonnet routeabout $1.65about $5.50strong 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.

Related Articles