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:

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:

  1. Claude Code sends requests to a local endpoint such as http://127.0.0.1:15721.
  2. CC Switch looks at the currently enabled Claude provider.
  3. 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

ScenarioLocal routing required?Recommended launch method
API key provider with an Anthropic Messages APIOptionalCC Switch terminal or normal terminal
API key provider with OpenAI Chat / Responses onlyRequiredDepends on provider configuration
Codex OAuth or Copilot-style OAuth providerRequiredRun 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:

  1. Switch to the Claude app in CC Switch.
  2. Click + to add a provider.
  3. Select a preset, or use a custom OpenAI-compatible provider.
  4. Fill in the API key and base URL.
  5. Open Advanced Options and select the API format the provider actually supports.
  6. Fill in the model mapping.
  7. Save and enable the provider.
  8. Open Settings → Routing → Local Routing and enable both the global router and the Claude app route.
Provider APISelect in CC Switch
Anthropic Messages compatibleAnthropic Messages
OpenAI /v1/chat/completionsOpenAI Chat Completions
OpenAI /v1/responsesOpenAI Responses API
Gemini Native generateContentGemini 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

  1. Enable the Codex OAuth provider in the Claude provider list.
  2. Open Settings → Routing → Local Routing.
  3. Turn on the global routing switch.
  4. 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.