Skip to main content
Claude Code supports four authentication methods. Choose the one that matches your setup.

Authentication methods

The default method for personal use. Claude Code opens a browser window and authenticates through your claude.ai account.
1

Start Claude Code

Run claude in your terminal. If you are not authenticated, the login prompt appears automatically.
2

Complete browser login

A browser window opens to claude.ai. Sign in with your Anthropic account and authorize Claude Code.
3

Return to terminal

After authorization, Claude Code receives your credentials and the session begins.
To log in manually at any time, run:
claude /login

macOS Keychain storage

On macOS, Claude Code automatically stores API keys in the system Keychain after the first successful authentication. You do not need to re-export ANTHROPIC_API_KEY in new terminal sessions—Claude Code retrieves the key from the Keychain on startup. To remove a stored key, log out:
claude /logout

API key helper

An API key helper is a custom script or command that Claude Code calls on demand to retrieve an API key. This is useful in environments where keys rotate frequently or are managed by a secrets manager. Set ANTHROPIC_API_KEY_HELPER to the path or command that prints a valid API key to stdout:
export ANTHROPIC_API_KEY_HELPER="/usr/local/bin/get-my-api-key"
Claude Code calls the helper at startup and caches the result for five minutes. The helper must exit with code 0 and print only the key on stdout.

Login and logout

CommandDescription
claude /loginTrigger the authentication flow manually
claude /logoutClear stored credentials (Keychain, OAuth tokens, and config)

Checking authentication status

Run the diagnostics command to see which authentication method is active and whether credentials are valid:
claude /doctor
The output shows your current auth source, account details, and any configuration issues.

Environment variables

VariablePurpose
ANTHROPIC_API_KEYDirect API key; overrides Keychain and OAuth
ANTHROPIC_BASE_URLOverride the default Anthropic API endpoint
ANTHROPIC_BEDROCK_BASE_URLBedrock endpoint for AWS authentication
ANTHROPIC_VERTEX_BASE_URLVertex AI endpoint for GCP authentication
ANTHROPIC_API_KEY_HELPERPath to a script that returns an API key on stdout

Build docs developers (and LLMs) love