Glossary/Claude Code & MCP

ANTHROPIC_API_KEY

ANTHROPIC_API_KEY is the environment variable Claude Code and the Claude API look for to authenticate your requests. You get the value from the Anthropic Console, and Claude Code reads it from your shell environment, a .env file, or a secrets manager, not from a config file you edit by hand.

Why it matters

Claude Code checks a few places for this variable in order: your current shell session, a project .env file, and any value a secrets tool injects into the process before it starts. If none of them are set, Claude Code will ask you to log in or paste a key.

Do I need a different key for each project?

No. One ANTHROPIC_API_KEY works across every project on your Mac. The only reason to use more than one is to track usage separately.

What happens if I paste it into the chat by accident?

Treat it as leaked. Revoke it in the Anthropic Console and generate a new one, the same as any other exposed secret.

Related

Looking for a different way to manage your keys? See the best Claude Code API key manager alternatives, or browse every term in the glossary.