Claude Code: Invalid API key · Fix external API key

Claude Code found an API key in `ANTHROPIC_API_KEY` (or a configured key helper) and Anthropic rejected it: the key is mistyped, revoked, or belongs to another organization. The exact message, why Claude Code prints it, and the fix.

Updated November 23, 2026 · Checked against Claude Code 2.1.308, reproduced in EnvHaven 1.9.0

The message

Invalid API key · Fix external API key

What it means

Claude Code found an API key in ANTHROPIC_API_KEY (or a configured key helper) and Anthropic rejected it: the key is mistyped, revoked, or belongs to another organization.

Fix

  1. Check what Claude Code sees: echo $ANTHROPIC_API_KEY | cut -c1-12.
  2. Create a new key in the Anthropic Console and set it again, or unset the variable (unset ANTHROPIC_API_KEY) to sign in with a subscription through /login instead.
  3. Remove stale keys from shell profiles such as ~/.zshrc, so an old one does not come back in new terminals.

In an EnvHaven workspace

Yes, if a wrong key is set. Keys saved from the workspace dashboard can be replaced there.

Where this comes from

This message was produced by Claude Code (Claude Code 2.1.308) itself, in a throwaway EnvHaven 1.9.0 container, on 2026-11-23; the text above is copied from that output.