Authentication methods
- OAuth (claude.ai)
- API key
- AWS Bedrock
- GCP Vertex AI
The default method for personal use. Claude Code opens a browser window and authenticates through your claude.ai account.To log in manually at any time, run:
Start Claude Code
Run
claude in your terminal. If you are not authenticated, the login prompt appears automatically.Complete browser login
A browser window opens to claude.ai. Sign in with your Anthropic account and authorize Claude Code.
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-exportANTHROPIC_API_KEY in new terminal sessions—Claude Code retrieves the key from the Keychain on startup.
To remove a stored key, log out:
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. SetANTHROPIC_API_KEY_HELPER to the path or command that prints a valid API key to stdout:
0 and print only the key on stdout.
Login and logout
| Command | Description |
|---|---|
claude /login | Trigger the authentication flow manually |
claude /logout | Clear 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:Environment variables
| Variable | Purpose |
|---|---|
ANTHROPIC_API_KEY | Direct API key; overrides Keychain and OAuth |
ANTHROPIC_BASE_URL | Override the default Anthropic API endpoint |
ANTHROPIC_BEDROCK_BASE_URL | Bedrock endpoint for AWS authentication |
ANTHROPIC_VERTEX_BASE_URL | Vertex AI endpoint for GCP authentication |
ANTHROPIC_API_KEY_HELPER | Path to a script that returns an API key on stdout |