ANTHROPIC_API_KEY Setup

How to configure the ANTHROPIC_API_KEY environment variable that Claude Code requires to authenticate with the Anthropic API. Covers macOS/Linux and Windows PowerShell with persistent configuration.

Syntax

claude-code
// macOS / Linux (bash or zsh):
export ANTHROPIC_API_KEY=sk-ant-...

// Persist across sessions (~/.zshrc or ~/.bashrc):
echo 'export ANTHROPIC_API_KEY=sk-ant-...' >> ~/.zshrc

// Windows PowerShell (current session):
$env:ANTHROPIC_API_KEY = "sk-ant-..."

// Persist in PowerShell profile:
# Add to $PROFILE:
$env:ANTHROPIC_API_KEY = "sk-ant-..."

Example

claude-code
// Verify the key is set:
echo $ANTHROPIC_API_KEY          # macOS/Linux
$env:ANTHROPIC_API_KEY           # PowerShell

// Start Claude Code (key must be set first):
claude
// > Welcome to Claude Code. Type your instruction.