Page summary

Start the local routing service and understand its ports, status, and request entry point.

Key takeaways
  • Start the local routing endpoint used by Claude Code and other tools.
  • Understand how CC Switch handles request conversion, logs, and provider control.
  • Use this page when you need OpenAI-compatible or Codex routing.

4.1 Local Routing Service

Overview

Local routing starts an HTTP service on your machine. Once an app enters Routing mode, that app's API requests go to CC Switch first, and CC Switch forwards them to the current provider.

Primary uses:

Apps that support local routing: Claude Code, Codex, Gemini CLI, Grok Build. Claude Desktop's "Model Mapping" mode is also forwarded through local routing; see 2.6 Claude Desktop.

💡 You don't need local routing to track usage: with routing off, CC Switch also collects usage from each tool's local session logs. See 4.4 Usage Statistics.

Start Local Routing

Local routing normally doesn't need to be started by hand:

Clicking the "Direct / Routing / Aggregation" tabs at the top is only for viewing and doesn't change any configuration. To actually switch, use the button under the tabs that spells out the consequence ("Start routing", "Switch to Aggregation", "Back to direct").

You can also click "Start" manually in the "Service" area under "Settings → Local routing". If the service isn't running while an app is in Routing or Aggregation mode, the app page shows "routing service isn't running, so requests will fail" with two buttons: "Start service" and "Back to direct".

Routing Configuration

Basic Configuration

In "Settings → Local routing → Service":

SettingDescriptionDefault
Listen AddressIP address local routing binds to; IPv4, IPv6 and localhost are supported127.0.0.1
Listen PortPort local routing listens on (1024–65535)15721
Record Request UsageWrites the usage and status of routed requests to the local statistics database; when off, Usage has no per-request details for routed requestsEnabled

Retry count and timeouts are configured per app; see 4.3 Failover.

Modify Configuration

  1. Change the address or port under "Listen address and port"
  2. Click "Save and restart service" (only clickable when there are changes)

After saving, the service restarts automatically with the new address and port.

Listen Address Options

AddressDescription
127.0.0.1Only accessible from local machine (recommended)
0.0.0.0Allow LAN access

Connection Address

The address CC Switch writes into client configs (including Claude Desktop's gateway URL) follows the listen address by default, with 0.0.0.0 written as 127.0.0.1. When a client can't reach this machine through loopback, fill in "Connection address" with an IP or hostname it can reach. Saving rewrites the clients that use routing right away. The connection address is saved on this device only and isn't synced to your other devices.

For example, Claude Desktop sessions inside WSL2 (default NAT mode) can't reach Windows' 127.0.0.1: set the listen address to 0.0.0.0, set the connection address to a Windows IP that WSL can reach (such as the vEthernet (WSL) adapter address), and allow the port through Windows Firewall.

Running Status

The top of "Settings → Local routing → Service" shows the service status: "Running · up X h Y min" when running, otherwise "Stopped". While the service is running, these statistics are shown on the right:

MetricDescription
RequestsTotal number of requests since startup
Success ratePercentage of successful requests
Active connectionsNumber of requests currently being processed

Apps using routing

"Apps using routing" lists every app in Routing or Aggregation mode, with its target, for example:

Claude Code · Routing    Routed to PackyCode
Codex · Aggregation      Default AIGoCode
Claude Desktop · Model mapping · kept running    Current provider xxx

"Open" on the right of each row opens that app's page. When no app is using routing, this shows "No app is using routing".

Failover Queue

Queues are managed in the "Routing" tab of each app page, and their parameters are tuned under "Auto failover" in "Settings → Local routing". See 4.3 Failover.

How It Works

Request Flow

sequenceDiagram
    participant CLI as CLI Tool (Claude)
    participant Proxy as Local Routing (CC Switch)
    participant API as API Provider (Anthropic)
    participant DB as Data Store (Logger)

    CLI->>Proxy: Send API request
    Proxy->>DB: Record request log / track usage
    Proxy->>API: Forward request
    API-->>Proxy: Return response
    Proxy-->>CLI: Return response

Configuration Changes

Once an app enters Routing mode, CC Switch points that app's request address at local routing:

Claude:

{
  "env": {
    "ANTHROPIC_BASE_URL": "http://127.0.0.1:15721"
  }
}

Codex:

[model_providers.custom]   # section of the current provider
base_url = "http://127.0.0.1:15721/v1"

Gemini:

GOOGLE_GEMINI_BASE_URL=http://127.0.0.1:15721

Grok Build: the request address in ~/.grok/config.toml points to http://127.0.0.1:15721/grokbuild/v1.

While routing, the API Key in the config file is replaced with a placeholder; the real Key is kept in CC Switch and injected by local routing when it forwards requests.

Format Conversion

Local routing automatically converts requests and responses according to the provider's configured "Upstream Format", for both streaming and non-streaming requests.

Claude Code / Claude Desktop side (the client sends Anthropic Messages requests):

Provider Upstream FormatLocal Routing Behavior
Anthropic MessagesPass-through (no conversion)
OpenAI Chat CompletionsConverts to OpenAI Chat format and responses back
OpenAI Responses APIConverts to OpenAI Responses format and responses back
Gemini Native generateContentConverts to Gemini native format and responses back

Codex / Grok Build side (the client sends OpenAI Responses requests):

Provider Upstream FormatLocal Routing Behavior
Responses (native)Pass-through (no conversion)
Chat CompletionsConverts to Chat Completions format and responses back
Anthropic MessagesConverts to Anthropic Messages format and responses back

The upstream format is configured per provider in the advanced options when adding or editing a provider; see 2.1 Add Provider → Upstream Format (Claude) and Upstream Format and Model Mapping for Codex / Grok Build.

Note: Format conversion requires local routing to be running, with the corresponding app in Routing mode.

Stop Local Routing

While an app is in Routing or Aggregation mode, the service can't be stopped: the "Stop" button under "Settings → Local routing → Service" is greyed out with the hint "Some apps still use the routing service. Switch them back to direct first."

There are two ways to take apps out of routing:

When no app is using routing, you can click "Stop" to shut the service down directly.

After Leaving Routing

When an app leaves routing, CC Switch will:

  1. Write the app's config file back to the direct provider (the one in use before it entered routing, labeled "Direct" on its card)
  2. Save request logs
  3. Close connections

Quitting CC Switch also writes apps back to direct first, but each app's mode stays unchanged and is re-attached on the next launch; if re-attaching fails, the app goes back to direct and you get a notice.

Request Logs

Enable Recording

Turn on the "Record Request Usage" toggle in "Settings → Local routing → Service" (on by default).

Log Contents

Each request record includes:

FieldDescription
TimeRequest time
AppClaude / Codex / Gemini / Grok Build
ProviderProvider used
ModelRequested model
TokensInput/output token count
LatencyRequest duration
StatusSuccess/failure

View Logs

View request logs in "Usage" in the sidebar.

FAQ

Port Already in Use

Error message: Address already in use

Solution:

  1. Change the port (anywhere from 1024 to 65535)
  2. Or close the program occupying the port

Local Routing Fails to Start

Check:

Request Timeout

Possible causes:

Solutions: