Use Local Routing to Connect Codex Models to Claude Code
This guide explains the setup behind a common CC Switch troubleshooting scenario: you have signed in with ChatGPT / Codex OAuth, added a Claude provider, but Claude Code still asks you to log in, says a model does not exist, or makes it unclear whether requests are actually routed to Codex. It also covers regular GPT or OpenAI-compatible API key providers.
Start with the key points:
- If you use a Codex OAuth reverse proxy, add it as a Claude provider instead of writing Codex credentials directly into Claude Code.
- If your provider gives you an API key and an OpenAI-compatible endpoint, choose the right API format, fill in the model mapping, and enable local routing.
- Codex OAuth and non-Anthropic API formats require Local Routing plus Claude application routing so Claude Code requests enter CC Switch first.
- For Codex OAuth providers, start Claude Code from a normal terminal with
claude. Do not launch the session from a Codex OAuth provider card. - Seeing Sonnet, Opus, or Haiku inside Claude Code does not mean Codex is unused. The upstream model is determined by the model mapping in CC Switch.
What is being converted?
Claude Code expects Anthropic-style requests and environment variables. Codex behind a ChatGPT account uses a different authentication and API flow. CC Switch local routing sits in the middle:
- Claude Code sends requests to a local endpoint such as
http://127.0.0.1:15721. - CC Switch looks at the currently enabled Claude provider.
- The router forwards the request to Codex OAuth or to another upstream provider while handling protocol conversion, logs, hot switching, and failover.
This does not turn Claude Code into a Codex client. It gives Claude Code a stable local Anthropic-compatible entry point and lets CC Switch translate and route the request.
Choose the right scenario
| Scenario | Local routing required? | Recommended launch method |
|---|---|---|
| API key provider with an Anthropic Messages API | Optional | CC Switch terminal or normal terminal |
| API key provider with OpenAI Chat / Responses only | Required | Depends on provider configuration |
| Codex OAuth or Copilot-style OAuth provider | Required | Run claude from a normal terminal |
OAuth providers cannot be fully represented as simple environment variables. For Codex OAuth, the reliable path is a normal terminal plus local routing.
If your provider directly offers GPT models
If your gateway gives you an API key, base URL, and model ID, do not use the Codex OAuth login flow. Configure it as a Claude provider:
- Switch to the Claude app in CC Switch.
- Click + to add a provider.
- Select a preset, or use a custom OpenAI-compatible provider.
- Fill in the API key and base URL.
- Open Advanced Options and select the API format the provider actually supports.
- Fill in the model mapping.
- Save and enable the provider.
- Open Settings → Routing → Local Routing and enable both the global router and the Claude app route.
| Provider API | Select in CC Switch |
|---|---|
| Anthropic Messages compatible | Anthropic Messages |
OpenAI /v1/chat/completions | OpenAI Chat Completions |
OpenAI /v1/responses | OpenAI Responses API |
Gemini Native generateContent | Gemini Native generateContent |
Prepare Codex OAuth
Use CC Switch v3.13.0 or newer. You need a ChatGPT account with Codex access, a network path that can reach OpenAI authentication pages, and a working Claude Code installation.
If this is your first Claude Code installation, run claude once in a normal terminal so ~/.claude/settings.json exists before CC Switch tries to take over routing.
Step 1: Sign in with ChatGPT / Codex OAuth
Open Settings → OAuth Center, find ChatGPT (Codex OAuth), and start the device-code login flow. You can also add a Codex OAuth preset from the Claude provider page and follow the same login prompt.
If login fails with 403, treat it as an outbound network issue. Try another region, temporarily use a global proxy rule, and verify that the browser can open https://auth.openai.com/codex/device and https://chatgpt.com.
Step 2: Add the Codex OAuth Claude provider
After login succeeds, add a Claude provider based on the Codex OAuth preset. Select the signed-in ChatGPT account, check the model mapping, and save the provider. You normally do not need to manually set the base URL or API format for the preset.
Step 3: Enable the provider and local routing
- Enable the Codex OAuth provider in the Claude provider list.
- Open Settings → Routing → Local Routing.
- Turn on the global routing switch.
- Enable the Claude application route.
Older screenshots may call this feature Local Proxy or Proxy Takeover. The goal is the same: Claude Code must send requests through the CC Switch local router.
Step 4: Verify Claude configuration
Check ~/.claude/settings.json from a normal terminal. The important part is that Claude Code points to the local router:
{
"env": {
"ANTHROPIC_BASE_URL": "http://127.0.0.1:15721",
"ANTHROPIC_AUTH_TOKEN": "PROXY_MANAGED"
}
}
If you changed the routing port, replace 15721 with your custom port.
Step 5: Start Claude Code from a normal terminal
Run:
claude
Do not start this session from a Codex OAuth provider card. That shortcut may try to inject a single provider as environment variables, which is not enough for OAuth-based routing.
Understand model display
Claude Code may still show Sonnet, Opus, or Haiku because those are Claude Code roles. CC Switch maps those roles to the upstream model IDs you configured, such as gpt-5.5 or another Codex-compatible model.
Display quirks in /model, usage logs, or final upstream model names do not necessarily mean routing failed. First verify three things: local routing is on, Claude settings point to 127.0.0.1:15721, and the enabled Claude provider in CC Switch is your Codex OAuth provider.
FAQ
Claude Code still asks me to log in
Restart Claude Code from a normal terminal and check that ~/.claude/settings.json points to the local router.
The provider says gpt-5.5 does not exist
If you launched from a provider card, switch to a normal terminal. Also check whether the upstream account actually has access to the mapped model.
Model fetching says an API key is required
Codex OAuth is not a regular API key provider, and the upstream may not expose a /models endpoint. Manually fill in the recommended model ID.
Local routing takeover fails
Run claude once to generate the Claude Code settings file, then enable Claude application routing again in CC Switch.