Add support for ANTHROPIC_API_KEY environment variable authentication detection #346
+43
−4
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.

Summary
This PR enhances Claude authentication detection to support both the
ANTHROPIC_API_KEYenvironment variable and the OAuth credentials file, matching the authentication priority order used by the Claude Agent SDK.Changes
Modified Files
server/routes/cli-auth.jsKey Updates
Updated
checkClaudeCredentials()function to checkANTHROPIC_API_KEYenvironment variable first, then fall back to~/.claude/.credentials.jsonOAuth tokensModified
/api/cli-auth/claude/statusendpoint to return authentication method indicator:method: 'api_key'when usingANTHROPIC_API_KEYenvironment variablemethod: 'credentials_file'when using OAuth credentials filemethod: nullwhen not authenticatedAdded comprehensive documentation with JSDoc comments explaining:
Authentication Priority Order
ANTHROPIC_API_KEYenvironment variable (highest priority)~/.claude/.credentials.jsonOAuth tokens (fallback)This priority order matches the Claude Agent SDK's authentication behavior, ensuring consistency between how we detect authentication and how the SDK actually authenticates.
API Response Format
The
/api/cli-auth/claude/statusendpoint now returns:{ "authenticated": true, "email": "[email protected]", "method": "credentials_file" }Or when using API key:
{ "authenticated": true, "email": "API Key Auth", "method": "api_key" }Backward Compatibility
✅ Fully backward compatible - existing code checking the
authenticatedfield will continue to work as expected.Important Note
ANTHROPIC_API_KEYis set, API calls are charged via pay-as-you-go rates instead of subscription rates, even if the user is logged in with a claude.ai subscription.References
Managing API key environment variables in Claude Code
Agent SDK Overview
Testing
The implementation has been verified to:
ANTHROPIC_API_KEYenvironment variable first🤖 Generated with Claude Code
Summary by CodeRabbit
ANTHROPIC_API_KEYenvironment variable for authentication, prioritized over stored OAuth tokens✏️ Tip: You can customize this high-level summary in your review settings.