May 11, 20264 min readSetupClaude Opus 4.6Codex CLI

How to use Claude Opus 4.6 in Codex CLI

Codex CLI is OpenAI's terminal coding agent, and it speaks the OpenAI Chat Completions format. That detail matters: anything that exposes an OpenAI-compatible endpoint can stand in for the model behind Codex. So you can keep the Codex workflow you already like — file edits, shell execution, multi-step planning — while the actual reasoning is done by Anthropic's Claude Opus 4.6.

This guide shows the fastest way to do that with AnyModel, a single OpenAI-compatible gateway that reaches GPT, Claude, Gemini, DeepSeek, GLM, Kimi, Qwen and Grok behind one API key.

Why route Codex through a gateway

Codex defaults to OpenAI models. Pointing it at Claude normally means juggling separate accounts, separate keys and a translation layer for Anthropic's API shape. A gateway removes all of that. You set one base_url, one key, and choose the model with a string id. Switching from a GPT model to Claude Opus 4.6 is literally one field — nothing else in your setup changes.

That also makes side-by-side evaluation cheap. If you want to see how Opus 4.6 stacks up against other coding models before committing, the model list and the compare page are good starting points.

Step 1: Get an API key

Create a free account at AnyModel. You get 1,000,000 tokens on signup, and a total of 6,000,000 if you link Telegram — no credit card required. After the free tokens, it is pay-per-token: no subscription, no minimums.

Step 2: Install with one line

AnyModel ships a one-line installer for Codex CLI. It writes the correct base_url and key into your Codex config so you do not have to hand-edit TOML:

bash <(curl -fsSL "https://anymodel.org/i?tool=codex") <YOUR_API_KEY>

Replace <YOUR_API_KEY> with the key from your dashboard. The same installer supports tool=claude for Claude Code, plus opencode and hermes.

If you prefer a manual setup, point Codex at the OpenAI-compatible endpoint directly:

  • base_url: https://anymodel.org/v1
  • api_key: your AnyModel key

This manual pattern is also how you wire up other clients — Cursor, Windsurf, Zed, Cline, Aider, Continue or Gemini CLI — since they all accept a custom OpenAI-compatible base URL and key.

Step 3: Select Claude Opus 4.6

With the endpoint configured, choose the model. In Codex you can set it in your config or pass it at launch:

codex --model claude-opus-4-6

Check the models page for the exact id string, since model identifiers occasionally change as providers update versions. Because routing is unchanged, you can flip between Opus 4.6 and any other model mid-project just by changing that id.

When Opus 4.6 is the right call

Claude's Opus tier is built for hard reasoning: large refactors, debugging across many files, and tasks where you want the agent to plan carefully before touching code. It tends to shine when the problem is ambiguous and the cost of a wrong edit is high.

For lighter, high-volume work — quick edits, boilerplate, formatting — a smaller or cheaper model is often the better trade. Keep both configured and switch per task:

Task Suggested approach
Multi-file refactor or tricky bug Claude Opus 4.6
Architecture planning, code review Claude Opus 4.6
Quick fixes, repetitive edits A faster/cheaper model
Cost-sensitive bulk runs Compare options on the gateway

Because every model sits behind the same key and endpoint, you are never locked in. Try a few and let results decide.

A note on privacy

By default, prompts pass through the gateway. If you are working with sensitive code, enable Ghost Mode — an opt-in, zero-retention setting where prompts and responses are not stored on our side (only a token counter remains). Be clear-eyed about the limit: the model provider still receives your prompt to generate a response, so this is not "100% privacy." It removes our-side retention, not the provider's processing.

Wrap-up

Running Claude Opus 4.6 in Codex CLI comes down to three moves: get a key, run the one-line installer, and set the model id. After that, the full Codex agent loop is powered by Opus-grade reasoning, and you can switch models any time without reconfiguring. For deeper dives and comparisons, the blog has more setup walkthroughs.

Ready to try it? Create a free AnyModel account and start with millions of free tokens — no card needed.

Read next