Login
Back to Blog
EnglishTutorial

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

A complete Codex CLI installation guide for developers covering setup on Mac, Linux, and Windows, plus API configuration with Crazyrouter.

C
Crazyrouter Team
March 15, 2026 / 1392 views
Share:
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#

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.

Implementation Guides

Related Posts

Crazyrouter Codex CLI: Use Codex with One API Key and an OpenAI-Compatible GatewayTutorial

Crazyrouter Codex CLI: Use Codex with One API Key and an OpenAI-Compatible Gateway

Set up OpenAI Codex CLI through Crazyrouter with one command on Windows, macOS, and Linux. Use an OpenAI-compatible base URL, one API key, and model routing for GPT, Claude, Gemini, DeepSeek, and Qwen-style workflows.

Jun 4
Codex CLI Installation Guide 2026 for WSL, Devcontainers, and ProxiesTutorial

Codex CLI Installation Guide 2026 for WSL, Devcontainers, and Proxies

A Codex CLI installation guide for real developer environments, including WSL, remote containers, proxy settings, troubleshooting, and multi-model fallback options.

Mar 21
Claude Code Installation and Usage Guide - AI Programming Assistant SetupTutorial

Claude Code Installation and Usage Guide - AI Programming Assistant Setup

Complete guide to install and configure Claude Code, the AI programming assistant. Learn how to set up Node.js, configure API tokens, and start coding with AI in your terminal.

Jan 24
Codex CLI Installation Guide 2026: macOS, Linux, Windows, Proxies, and CITutorial

Codex CLI Installation Guide 2026: macOS, Linux, Windows, Proxies, and CI

A developer-focused June 2026 guide to Codex CLI installation, alternatives, implementation patterns, pricing tradeoffs, and when to use Crazyrouter for unified AI API access.

Jun 4
MCP (Model Context Protocol) Complete Guide: The New Standard for AI Tool IntegrationTutorial

MCP (Model Context Protocol) Complete Guide: The New Standard for AI Tool Integration

Everything developers need to know about MCP (Model Context Protocol). Covers what it is, how it works, how to build MCP servers, and why it matters for AI application development.

Feb 23
How to Access GPT-5 and GPT-5.2 via API - Complete Developer GuideTutorial

How to Access GPT-5 and GPT-5.2 via API - Complete Developer Guide

Learn how to access OpenAI's latest GPT-5, GPT-5.2, and o3-pro models through a unified API. Step-by-step guide with Python, Node.js, and curl examples.

Jan 22