Skip to content

Failed to authenticate: Claude Desktop gateway token invalid — Claude

Quick fix

Sign out of the stale official account session in Claude Desktop and restart the app. If the error persists, switch to the default provider and then switch…

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 is invalid

These issues report that connection tests from the Claude Code CLI or CC Switch can succeed while requests from Claude Desktop / Cowork Gateway still fail. A comment on #2865 attributes one case to a mismatch between the host-managed bearer token used by Desktop and the gateway token configured in CC Switch; it recommends running `claude auth logout` and fully quitting and restarting Desktop. A user in #3196 also confirmed that logging out resolved the issue, while another user reported that it did not, so this method does not work in every case.

The maintainer’s closure note for #3196 says that the interface and configuration-writing method changed substantially in cc-switch v4.0. #5008 discusses another possible authentication conflict: after signing in with `claude login`, `ANTHROPIC_AUTH_TOKEN` remained set while `ANTHROPIC_API_KEY` was also configured. That issue says this is still a user-side workaround; the related discussion is in #3162. The issues describe different approaches and do not establish one fix that applies to every case.

  1. Fully quit Claude Desktop, run `claude auth logout` in a terminal, then restart Desktop. Users in #2865 and #3196 reported that this restored access; others reported that it did not.

  2. If the error persists, switch to Claude Desktop Official in CC Switch and restart Claude Desktop. Then switch back to the original provider and restart it again. A user in #3196 reported that this worked.

  3. If you use Windows, previously signed in to the official account with `claude login`, and later set a proxy API key, check whether `C:\Users\{用户名}\.claude.json` contains `"hasCompletedOnboarding": true`, and confirm that the provider authentication field uses `ANTHROPIC_API_KEY`. This troubleshooting method is reported in #5008; that issue does not confirm that it resolves all gateway token errors.

    C:\Users\{用户名}\.claude.json
    {
    "hasCompletedOnboarding": true
    }
ToolClaude Code / Claude Desktop
VersionUnknown
PlatformsWindows
What should I do if the error persists after running `claude auth logout`?
A user in #3196 reported that the command did not work. You can try switching to Claude Desktop Official in CC Switch, restarting Desktop, then switching back to the original provider and restarting it. A user in that issue confirmed that this worked.
Why does the Claude Code CLI work while Claude Desktop / Cowork Gateway returns 401?
A comment on #2865 says Desktop Gateway may use an authentication token that differs from the one used by the CLI or configured in CC Switch; the CLI and Desktop call paths behave differently.
What should I check if I previously signed in with a Claude Pro account and set a proxy API key?
#5008 mentions checking whether Windows `C:\Users\{用户名}\.claude.json` contains `"hasCompletedOnboarding": true` and setting the provider authentication field to `ANTHROPIC_API_KEY`; the maintainer says this is only a user-side workaround.

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.