How to use GPT-5.1 Codex in Claude Code
Claude Code is one of the best terminal coding agents available, and a lot of developers love its workflow. But you might prefer GPT-5.1 Codex for certain tasks — long refactors, precise diffs, or just a second opinion from a different model family. The good news: you don't have to choose your client based on which lab made the model. You can run GPT-5.1 Codex inside Claude Code.
This guide shows you how, using AnyModel as the gateway.
Why route Claude Code to GPT-5.1 Codex
Claude Code talks to an OpenAI-compatible (Anthropic-style) backend. Normally that backend is Anthropic's API. If you point it at a gateway that speaks the same protocol and exposes GPT-5.1 Codex, the client doesn't care who trained the model — it just sends requests and renders responses.
AnyModel is exactly that gateway. One OpenAI-compatible endpoint (https://anymodel.org/v1), one API key, and access to every major model: GPT, Claude, Gemini, DeepSeek, GLM, Kimi, Qwen, and Grok. Switching models means changing the model id — nothing else in your setup changes. Browse the full lineup on the models page.
Step 1: Get a key (free to start)
Create an account and grab your API key. You start with 1,000,000 free tokens, and you can reach a total of 6,000,000 tokens by linking Telegram. No credit card required. After the free tokens, it's pay-per-token — no subscription, no monthly minimums.
Register here and copy your key from the dashboard.
Step 2: Install with one line
AnyModel ships a one-line installer for a handful of supported tools — codex, claude, opencode, and hermes. Since we're configuring Claude Code, use tool=claude:
bash <(curl -fsSL "https://anymodel.org/i?tool=claude") <YOUR_API_KEY>
Replace <YOUR_API_KEY> with the key from your dashboard. The script configures Claude Code to use the AnyModel base URL and your key, so the client is ready to talk to the gateway.
If you also use the standalone Codex CLI, the same installer works with
tool=codex.
Step 3: Select GPT-5.1 Codex
Once Claude Code is pointed at AnyModel, choose GPT-5.1 Codex as your active model. In Claude Code you can set the model id either through its model-selection command or by setting the model in your config — the value is the AnyModel model id for GPT-5.1 Codex (check the models page for the exact id).
That's the whole trick: same client, same keybindings, same agent loop — different brain.
Switching models on the fly
Because every model lives behind the same endpoint and key, comparing them is trivial. Run a tricky refactor through GPT-5.1 Codex, then re-run it through Claude or Gemini and see which diff you like best. There's nothing to re-auth and no second account to manage. If you're weighing options, our model comparison breaks down strengths and pricing side by side.
| What you change | What stays the same |
|---|---|
The model id |
Base URL, API key, client config |
| The model's behavior/cost | Your Claude Code workflow |
A note on privacy
By default, AnyModel handles your prompts to route and bill them. If you work on sensitive code, enable Ghost Mode — opt-in, zero-retention API keys where prompts and responses aren't stored on our side (we keep only a token counter for billing). To be clear: the underlying model provider still receives your prompt to generate a response, so this isn't "100% privacy" — but nothing is retained on the gateway.
Using other editors instead
If your team also works in Cursor, Windsurf, Zed, Cline, Aider, Continue, or Gemini CLI, the one-line installer doesn't cover those. Use a manual OpenAI-compatible setup instead: set the base URL to https://anymodel.org/v1, paste your key, and select your model. Same endpoint, same key — just configured by hand.
Wrapping up
Running GPT-5.1 Codex in Claude Code takes about two minutes: get a key, run one command, pick the model. From there you can flip between GPT, Claude, Gemini, and the rest without touching your config — a genuinely flexible setup for anyone who refuses to be locked into a single model family. For more setup walkthroughs, see the blog.
Ready to try it? Create your free AnyModel account and get a million tokens to start — no card needed.
AnyModel