Codex CLI is a coding agent from OpenAI that runs locally on your computer.
If you want Codex in your code editor (VS Code, Cursor, Windsurf), install in your IDE.
If you want the desktop app experience, run
codex app or visit the Codex App page.
If you are looking for the cloud-based agent from OpenAI, Codex Web, go to chatgpt.com/codex.
This is a fork of openai/codex that restores and natively implements three outbound wire protocols on a single internal representation:
- Responses (
/v1/responses) — upstream's only remaining wire. - Chat Completions (
/v1/chat/completions) — removed by upstream in Feb 2026 (PR #10157); reintroduced here as a first-class protocol. - Anthropic Messages (
/v1/messages) — Claude-native, including the extended-thinking chain (thinking_delta/signature_deltaSSE frames,budget_tokensclamping,cache_controlephemeral breakpoints, and verbatim signature-preserving replay ofthinkingblocks).
Mental model (why the fork is shaped this way):
- One IR, three spokes. All wires share
ResponseItemas the single internal representation (hub-and-spoke, not pairwise translation). Complexity stays O(N) instead of O(N²). - Minimal fork seam. The divergence from upstream is contained to ~3 registration points:
WireApi,ModelProviderInfo, and a per-wire dispatch incore/src/client.rs. Upstream still only definesWireApi::Responses, so our chat/messages variants never collide with upstream drift. - goose-blueprint Anthropic implementation. The Anthropic SSE state machine in
codex-api/src/sse/messages.rsis modeled on goose's pattern (Block's Rust agent), not a hand-rolled parser. - Real-gateway verified. Every wire was tested end-to-end against a live combo gateway (H1 联调档案):tool calls, parallel tool-call grouping,
max_tokenshit signaling, and thinking-chain round trips. Any degradation is fail-loud, not silent — e.g., truncatedtool_useJSON surfaces asApiError::Stream, never a fabricated{}. - Per-provider tuning. Additional
anthropic_max_tokens,anthropic_thinking_budget,anthropic_prompt_cachingOption<_>fields let each provider opt in without touching global defaults.
Upstream is tracked as upstream/main. This fork's local agent docs (docs/agents, docs/specs, PONYTAIL-DEBT.md, etc.) are intentionally not committed here — they live in the working machine's sibling D:/Aworker/codex/docs/ directory and are not pushed.
wire_api is one protocol per provider — there is no auto-negotiation and no failover. To use several protocols at once you declare multiple providers (they can even point at the same base URL) and pick one per run with -p:
# ~/.codex/config.toml
# default: upstream behaviour, one provider, one wire
model_provider = "openai"
# --- Responses wire (OpenAI native /v1/responses) ---
[model_providers.gw-resp]
name = "gw-resp"
base_url = "https://example.com/v1" # note: path stays at /v1; the wire appends /responses, /chat/completions, or /messages itself
wire_api = "responses"
env_key = "MY_API_KEY"
# --- Chat Completions wire (OpenAI legacy, restored by this fork) ---
[model_providers.gw-chat]
name = "gw-chat"
base_url = "https://example.com/v1"
wire_api = "chat"
env_key = "MY_API_KEY"
# --- Anthropic Messages wire (/v1/messages) ---
[model_providers.gw-msg]
name = "gw-msg"
base_url = "https://example.com/v1"
wire_api = "anthropic"
env_key = "MY_API_KEY"
# optional anthropic-only knobs (per-provider; leave unset to use built-in defaults):
anthropic_max_tokens = 128000 # output budget, otherwise a built-in default
anthropic_thinking_budget = 8192 # extended-thinking budget_tokens (clamped to 1024..max_tokens-1)
anthropic_prompt_caching = true # marks system prompt + last tool with cache_control: ephemeralThen select a wire and model per invocation:
codex -p gw-resp -m some-openai-model "…"
codex -p gw-chat -m deepseekpro "…"
codex -p gw-msg -m claude-… "…" # thinking chain streams natively (TUI shows reasoning deltas)Behaviour notes:
experimental_bearer_token = "PROXY_MANAGED"(or a real token) also works in place ofenv_keyfor gateways that inject auth downstream.- The same physical gateway endpoints strike all three wires (
POST /v1/responses,POST /v1/chat/completions,POST /v1/messages) — fork never strips or rewrites paths. - On the Anthropic wire, replay of the model's
thinkingblocks is done verbatim with the SSEsignature(anthropic's tool-use round contract); unsigned reasonings are dropped rather than altered. Non-data-URI images are dropped loudly. Truncated tool-call JSON errors out — never silently fabricated. - A turn always runs on exactly one wire; switching wires mid-thread means starting a new turn with
-p.
Run the following on Mac or Linux to install Codex CLI:
curl -fsSL https://chatgpt.com/codex/install.sh | shRun the following on Windows to install Codex CLI:
powershell -ExecutionPolicy ByPass -c "irm https://chatgpt.com/codex/install.ps1 | iex"The standalone installers download from https://releases.openai.com/codex by default and fall back to GitHub Releases if a metadata or asset download is unavailable. To force GitHub Releases, set CODEX_INSTALLER_USE_RELEASES_OPENAI_COM to false (0 and no are also accepted):
curl -fsSL https://chatgpt.com/codex/install.sh | CODEX_INSTALLER_USE_RELEASES_OPENAI_COM=false sh$env:CODEX_INSTALLER_USE_RELEASES_OPENAI_COM='false'; irm https://chatgpt.com/codex/install.ps1 | iexCodex CLI can also be installed via the following package managers:
# Install using npm
npm install -g @openai/codex# Install using Homebrew
brew install --cask codexThen simply run codex to get started.
You can also go to the latest GitHub Release and download the appropriate binary for your platform.
Each GitHub Release contains many executables, but in practice, you likely want one of these:
- macOS
- Apple Silicon/arm64:
codex-aarch64-apple-darwin.tar.gz - x86_64 (older Mac hardware):
codex-x86_64-apple-darwin.tar.gz
- Apple Silicon/arm64:
- Linux
- x86_64:
codex-x86_64-unknown-linux-musl.tar.gz - arm64:
codex-aarch64-unknown-linux-musl.tar.gz
- x86_64:
Each archive contains a single entry with the platform baked into the name (e.g., codex-x86_64-unknown-linux-musl), so you likely want to rename it to codex after extracting it.
Run codex and select Sign in with ChatGPT. We recommend signing into your ChatGPT account to use Codex as part of your Plus, Pro, Business, Edu, or Enterprise plan. Learn more about what's included in your ChatGPT plan.
You can also use Codex with an API key, but this requires additional setup.
This repository is licensed under the Apache-2.0 License.
