fix: detect Claude auth from settings env#527
Conversation
📝 WalkthroughWalkthroughThis PR adds support for reading Claude authentication credentials from Changes
Possibly related PRs
Suggested reviewers
Poem
🚥 Pre-merge checks | ✅ 2 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Tip Try Coding Plans. Let us write the prompt for your AI agent so you can ship faster (with fewer bugs). Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
server/routes/cli-auth.js (1)
137-167:⚠️ Potential issue | 🟠 MajorHandle
ANTHROPIC_AUTH_TOKENinprocess.envtoo.This now reports authenticated when
ANTHROPIC_AUTH_TOKENcomes from~/.claude/settings.json, but the same token still reports unauthenticated when it is already exported into the server process because Priority 1 only checksANTHROPIC_API_KEY. That creates a false negative on/claude/statusfor an otherwise valid Claude setup.Proposed fix
- if (process.env.ANTHROPIC_API_KEY && process.env.ANTHROPIC_API_KEY.trim()) { + if (typeof process.env.ANTHROPIC_API_KEY === 'string' && process.env.ANTHROPIC_API_KEY.trim()) { return { authenticated: true, email: 'API Key Auth', method: 'api_key' }; } + + if (typeof process.env.ANTHROPIC_AUTH_TOKEN === 'string' && process.env.ANTHROPIC_AUTH_TOKEN.trim()) { + return { + authenticated: true, + email: 'Configured via environment', + method: 'api_key' + }; + }🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@server/routes/cli-auth.js` around lines 137 - 167, The current auth check only treats process.env.ANTHROPIC_API_KEY as a valid env-sourced credential, but ignores process.env.ANTHROPIC_AUTH_TOKEN; update the initial Priority 1 block to also accept a non-empty process.env.ANTHROPIC_AUTH_TOKEN as an authenticated credential (same returned shape as the settingsEnv branch), so that both ANTHROPIC_API_KEY and ANTHROPIC_AUTH_TOKEN in the process environment result in authenticated: true; locate the checks around process.env.ANTHROPIC_API_KEY and loadClaudeSettingsEnv() and apply the same logic used for settingsEnv.ANTHROPIC_AUTH_TOKEN to process.env.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Outside diff comments:
In `@server/routes/cli-auth.js`:
- Around line 137-167: The current auth check only treats
process.env.ANTHROPIC_API_KEY as a valid env-sourced credential, but ignores
process.env.ANTHROPIC_AUTH_TOKEN; update the initial Priority 1 block to also
accept a non-empty process.env.ANTHROPIC_AUTH_TOKEN as an authenticated
credential (same returned shape as the settingsEnv branch), so that both
ANTHROPIC_API_KEY and ANTHROPIC_AUTH_TOKEN in the process environment result in
authenticated: true; locate the checks around process.env.ANTHROPIC_API_KEY and
loadClaudeSettingsEnv() and apply the same logic used for
settingsEnv.ANTHROPIC_AUTH_TOKEN to process.env.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro
Run ID: d21252d7-7fc3-4a48-bf8f-76e2416b340e
📒 Files selected for processing (1)
server/routes/cli-auth.js
Summary
~/.claude/settings.jsonenv valuesANTHROPIC_API_KEYandANTHROPIC_AUTH_TOKENfrom settings as authenticated.credentials.jsonOAuth detection unchangedValidation
node --check server/routes/cli-auth.js/claude/statusroute handler locally and verified it returnsauthenticated: trueforANTHROPIC_AUTH_TOKENstored insettings.jsonSummary by CodeRabbit