The agent CLI supports OAuth authentication for providers that offer subscription-based access, including:
- Anthropic (Claude Pro/Max subscription)
- GitHub Copilot (GitHub.com and Enterprise)
# Interactive login - select your provider
agent auth login
# Example: Select "Anthropic" > "Claude Pro/Max"
# Example: Select "GitHub Copilot" > "Login with GitHub Copilot"# List all configured credentials
agent auth list
# Check detailed status (experimental)
agent auth status# Use Claude with OAuth (after agent auth login with Anthropic)
echo "hello" | agent --model anthropic/claude-sonnet-4-5
# Use GitHub Copilot (after agent auth login with GitHub Copilot)
echo "hello" | agent --model github-copilot/gpt-4oInteractive login to any supported provider.
agent auth loginThis will:
- Show a list of available providers
- For OAuth providers (Anthropic, GitHub Copilot): Open browser for authentication
- For API key providers: Prompt for API key entry
- Store credentials securely in
~/.local/share/agent/auth.json
List all configured credentials.
agent auth list
# Output:
# ◇ Credentials ~/.local/share/agent/auth.json
# │
# ◆ Anthropic oauth
# ◆ GitHub Copilot oauth
# │
# └ 2 credentialsRemove credentials for a provider.
agent auth logout
# Select provider to log out fromCheck authentication status for all providers (experimental).
agent auth status
# Shows token expiration, etc.Claude Pro/Max subscribers can authenticate via OAuth:
agent auth login
# Select: Anthropic
# Select: Claude Pro/Max
# Follow browser prompts
# Paste authorization codeLogin methods:
- Claude Pro/Max - OAuth login for subscription users (recommended)
- Create an API Key - Generate an API key via OAuth
- Manually enter API Key - Enter existing API key
After login, use any Anthropic model:
echo "hello" | agent --model anthropic/claude-sonnet-4-5
echo "hello" | agent --model anthropic/claude-opus-4-1GitHub Copilot subscribers (individual or enterprise) can authenticate:
agent auth login
# Select: GitHub Copilot
# Select: GitHub.com or GitHub Enterprise
# Follow device code flowThe device code flow will:
- Show a verification URL and code
- Wait for you to authorize in browser
- Automatically complete once authorized
After login, use GitHub Copilot models:
echo "hello" | agent --model github-copilot/gpt-4o
echo "hello" | agent --model github-copilot/claude-sonnet-4-5For providers without OAuth support, enter API keys directly:
agent auth login
# Select provider (OpenAI, Google, OpenRouter, etc.)
# Enter API key when promptedOr use environment variables:
export OPENAI_API_KEY="sk-..."
export ANTHROPIC_API_KEY="sk-ant-api03-..."
export GOOGLE_GENERATIVE_AI_API_KEY="..."If you've already authenticated with Claude Code CLI, you can use those credentials:
# Claude Code CLI stores credentials in ~/.claude/.credentials.json
# Use the --use-existing-claude-oauth flag
echo "hello" | agent --use-existing-claude-oauthThis option:
- Reads OAuth tokens from
~/.claude/.credentials.json - Automatically uses the
claude-oauthprovider - Defaults to
claude-sonnet-4-5model if no model specified
Credentials from agent auth login are stored in:
~/.local/share/agent/auth.json
Format:
{
"anthropic": {
"type": "oauth",
"refresh": "sk-ant-ort01-...",
"access": "sk-ant-oat01-...",
"expires": 1765759825273
},
"github-copilot": {
"type": "oauth",
"refresh": "gho_...",
"access": "...",
"expires": 1765759825273
}
}Claude Code CLI credentials (used with --use-existing-claude-oauth) are in:
~/.claude/.credentials.json
OAuth tokens are automatically refreshed when expired:
- Anthropic: Uses refresh token to get new access token
- GitHub Copilot: Uses access token to get Copilot-specific token
No manual refresh is needed - the agent handles this automatically.
| Provider | Environment Variable |
|---|---|
| Anthropic (API) | ANTHROPIC_API_KEY |
| Anthropic (OAuth) | CLAUDE_CODE_OAUTH_TOKEN |
| OpenAI | OPENAI_API_KEY |
GOOGLE_GENERATIVE_AI_API_KEY |
|
| OpenRouter | OPENROUTER_API_KEY |
| GitHub Copilot | (OAuth only, no env var) |
Run agent auth login to authenticate with a provider.
Tokens are auto-refreshed. If you see this error, try:
agent auth logoutfor the provideragent auth loginto re-authenticate
- Ensure you have an active subscription (Claude Pro/Max, GitHub Copilot)
- Check your network connection
- Try again with
agent auth login
| Feature | OAuth | API Key |
|---|---|---|
| Billing | Subscription-based | Pay-as-you-go |
| Setup | Browser authorization | Copy/paste key |
| Token Format | sk-ant-oat... |
sk-ant-api... |
| Auto-refresh | Yes | N/A |
- Claude Code CLI - Official Claude CLI with OAuth
- Anthropic Console - API key management
- GitHub Copilot - GitHub AI assistant