Submit a toolSubmit

Claude Code says Invalid API key. Fix the credential Claude Code is actually using

Claude Code fails with Invalid API key or Not logged in, often because ANTHROPIC_API_KEY overrides your subscription login. Short answer: 5 steps. 1) Run /status before you change anything; 2) If you want your Claude subscription, unset ANTHROPIC_API_KEY; 3) If you meant to use an API key, fix the value itself; 4) Sign in again when no credential is present; 5) Confirm /status shows the credential you expect.

Last updated: · This page is the decision checklist; the tools list for “Fix Claude Code authentication” is a separate URL.

The problem: Claude Code fails with Invalid API key or Not logged in, often because ANTHROPIC_API_KEY overrides your subscription login.

How do I fix this: Claude Code says Invalid API key?

  1. Run /status before you change anything

    In the Claude Code session, run /status and read which credential is active (subscription login, ANTHROPIC_API_KEY, apiKeyHelper, or a cloud provider). Auth errors mean Claude Code cannot prove who you are; /status is the first check in Anthropic's docs. https://code.claude.com/docs/en/errors

  2. If you want your Claude subscription, unset ANTHROPIC_API_KEY

    When ANTHROPIC_API_KEY is set and approved, Claude Code uses that Console key instead of your Pro/Max/Teams login, including for billing. In the same shell that launches claude, run unset ANTHROPIC_API_KEY (PowerShell: Remove-Item Env:ANTHROPIC_API_KEY). Remove it from your shell profile and any project .env that direnv or the IDE loads. Then relaunch claude and run /login if needed. https://support.claude.com/en/articles/12304248-manage-api-key-environment-variables-in-claude-code

  3. If you meant to use an API key, fix the value itself

    Invalid API key · Fix external API key means the env var or apiKeyHelper output was rejected, or Claude Code blocked a header-unsafe value (line break, NUL, non-ASCII). Check for typos and revocation in the Claude Console. In the same shell run env | grep ANTHROPIC (or Get-ChildItem Env:ANTHROPIC*). Retype the key rather than pasting from chat or a PDF. https://code.claude.com/docs/en/errors

  4. Sign in again when no credential is present

    Not logged in · Please run /login means this session has no valid credential. Run /login and complete the browser flow. If the browser shows a code instead of redirecting (common in WSL2, SSH, containers), paste it at the terminal prompt. For CI that cannot open a browser, use ANTHROPIC_API_KEY or a long-lived token from claude setup-token. https://code.claude.com/docs/en/authentication

  5. Confirm /status shows the credential you expect

    After the change, run /status again. The active row should match the account you intend to bill. If an apiKeyHelper is Failing, run that script in your own shell until it prints only the key on stdout and exits 0; /login cannot override a configured helper.

Which tools are best to fix Claude Code authentication?

Claude Code errors

Invalid API key, Not logged in, disabled-org keys, and header-unsafe credential values.

Authentication

Login flow, credential precedence, and setup-token for non-interactive use.

API key env vars

Why ANTHROPIC_API_KEY overrides a Claude subscription.

Claude Console keys

Create or revoke a Console API key when you intend to bill via API.

All tools for “Fix Claude Code authentication” →

Related fixes

See also AI tools launched today on the daily board.