How to use Claude Sonnet 4.6 in Codex CLI
Codex CLI is OpenAI's terminal coding agent, and by default it talks to OpenAI models. But the tool speaks the standard OpenAI Chat Completions protocol, which means you can point it at any compatible endpoint. With AnyModel, that lets you run Claude Sonnet 4.6 — Anthropic's strong coding-and-reasoning model — directly inside Codex CLI without switching tools.
This guide shows the fastest way to set it up and how to keep your familiar Codex workflow intact.
Why route Codex CLI to Claude Sonnet 4.6
Sonnet 4.6 is well suited to agentic coding: multi-file edits, long-context refactors, and careful instruction-following. Running it inside Codex CLI gives you Anthropic's model behavior with the Codex interface you already know — no need to learn a second agent.
Through AnyModel, you get one OpenAI-compatible endpoint that reaches every supported model — GPT, Claude, Gemini, DeepSeek, GLM, Kimi, Qwen, and Grok — behind a single API key. Switching models is just changing the model id; nothing else in your config moves. That makes it trivial to compare Sonnet 4.6 against GPT or Gemini on the same task. (Curious how they stack up? See the model comparison.)
Step 1: Get an API key
Create a free account and grab your key. You start with 1,000,000 tokens on signup, and up to 6,000,000 total if you link Telegram — no credit card required. After that it's pay-per-token: no subscription, no minimums.
Step 2: Install with one line
AnyModel ships a one-line installer that configures Codex CLI to use the AnyModel endpoint for you. Run this in your terminal, replacing the placeholder with your real key:
bash <(curl -fsSL "https://anymodel.org/i?tool=codex") <YOUR_API_KEY>
That sets the base URL to https://anymodel.org/v1 and wires in your key. The same installer supports tool=claude (Claude Code), opencode, and hermes if you use those too.
Note: the one-line installer covers
codex,claude,opencode, andhermesonly. For Cursor, Windsurf, Zed, Cline, Aider, Continue, or Gemini CLI, use a manual OpenAI-compatible setup instead (details below).
Step 3: Select Claude Sonnet 4.6
Once Codex is pointed at AnyModel, choose the model. You can set it for a session with the model flag, or make it your default in ~/.codex/config.toml:
model = "claude-sonnet-4.6"
The exact id is listed on the models page — copy it from there to be safe, since ids are case- and format-sensitive. To swap back to GPT or try Gemini later, change this one line. Nothing else needs to be touched.
Manual setup (other clients)
If you're configuring a tool the installer doesn't cover, point it at the OpenAI-compatible endpoint manually:
| Setting | Value |
|---|---|
| Base URL | https://anymodel.org/v1 |
| API key | your AnyModel key |
| Model | claude-sonnet-4.6 |
Most editors and CLIs have an "OpenAI-compatible" or "custom base URL" field — drop those three values in and you're done.
Tips for a smooth workflow
- Verify the route first. Run a tiny prompt and confirm the response looks like Sonnet before starting a big task.
- Mind the context window. Sonnet 4.6 handles long context well, but trimming irrelevant files keeps responses sharp and tokens lean.
- Watch token usage. Since billing is per-token, large repo-wide operations cost more — scope your prompts to the files that matter.
- Privacy-sensitive work? Enable Ghost Mode, our opt-in zero-retention option: we don't store prompts or responses, only a token counter. Keep in mind the model provider still receives your prompt — Ghost Mode covers our side, not theirs.
Wrapping up
Pointing Codex CLI at Claude Sonnet 4.6 takes one install command and one model id. From there you keep the Codex experience while gaining the freedom to switch between Claude, GPT, Gemini, and more from a single key and endpoint. For more setup walkthroughs, browse the blog.
Ready to try it? Create a free account — a million tokens to start, no card needed.
AnyModel