Skip to content

401 authentication failed: Claude Desktop gateway token invalid - Claude Desktop

Quick fix

Clear the official Claude Desktop OAuth login state, or edit .claude.json, to resolve the 401 invalid gateway token.

Error output
Failed to authenticate. API Error: 401 认证失败: Claude Desktop gateway token 无效
English translation

Failed to authenticate. API Error: 401 authentication failed: Claude Desktop gateway token invalid

At the core: the Claude Desktop `claude-desktop-3p` entry point uses a different auth token from the one CC Switch configures. CC Switch writes a 36-character `inferenceGatewayApiKey` into the config while Claude Desktop actually sends a 108-character host-managed bearer token, so validation fails with a 401.

On top of that, if you previously signed in to a Pro account with `claude login`, the system leaves an `ANTHROPIC_AUTH_TOKEN` behind. That first-party OAuth login state overrides the third-party token CC Switch writes, so the actual call path for the Claude App / Cowork Gateway uses stale credentials or model routing — producing 401 authentication failures, an invalid API key, or model route not configured — while the Claude Code CLI works fine.

  1. Clear the first-party OAuth login state (recommended). Run `claude auth logout` on the command line, then quit Claude Desktop completely (from the taskbar or Dock) and restart it.

  2. Edit the config file. On Windows, open the config file, add the `hasCompletedOnboarding` field, and set the auth field to `ANTHROPIC_API_KEY` when adding the provider in CC Switch.

    // C:\Users\{用户名}\.claude.json
    {
    "hasCompletedOnboarding": true
    }
  3. Switch models again. In CC Switch, switch the model to the default Claude Desktop first and restart Claude Desktop; then switch back to the third-party model (deepseek, for example) and restart Claude Desktop again.

  4. Configure local routing by hand. Turn local routing on in CC Switch settings and note the address (`http://127.0.0.1:15721`, for example). Enable developer mode in Claude Desktop (Help -> Troubleshooting -> Enable Developer Mode), go to Developer -> Configure third-party inference, choose Gateway on the Connection page, and set the Gateway base URL to your local routing address.

ToolClaude Desktop
Versionv2.1.143 - v3.17.0
PlatformsWindowsmacOS
Why does the Claude Code CLI work while the Claude App / Cowork errors?
Because the Claude Desktop `claude-desktop-3p` entry point actually sends a 108-character host-managed bearer token while CC Switch validates a 36-character one. The official OAuth login state may also override the third-party token, leaving the app on stale credentials.
`claude auth logout` did not help. What now?
Try switching back to the default Claude Desktop in CC Switch and restarting, then switching back to the third-party model and restarting. Or configure the Gateway base URL as your local routing address by hand in Claude Desktop developer mode.
Besides the 401, I sometimes see model route not configured or an invalid API key.
Also because the Claude App / Cowork Gateway did not sync the CC Switch routing config correctly and still uses the old provider key or default model routing on the actual call. Follow the steps to clear the login state or configure local routing by hand.

This is an unofficial community wiki with no affiliation to the cc-switch authors or the project itself. Its content is compiled from the project's public GitHub issues. This site distributes no software.