Skip to content

fix(claude): detect macOS Keychain authentication - #1033

Open
sudo-eugene wants to merge 2 commits into
siteboon:mainfrom
TheWebEng:agent/claude-macos-auth-status
Open

fix(claude): detect macOS Keychain authentication#1033
sudo-eugene wants to merge 2 commits into
siteboon:mainfrom
TheWebEng:agent/claude-macos-auth-status

Conversation

@sudo-eugene

@sudo-eugene sudo-eugene commented Jul 18, 2026

Copy link
Copy Markdown

Closes #556

What changed

On macOS, CloudCLI can report Claude as disconnected even while conversations work because Claude Code stores OAuth credentials in Keychain rather than ~/.claude/.credentials.json. Authentication status now comes from claude auth status --json, with the existing environment, settings, and legacy credential-file paths retained for compatibility.

Why

Claude Code itself is the reliable authority for whether its credentials are usable. Asking the CLI avoids duplicating platform-specific credential-storage logic or attempting to read Keychain directly, and keeps CloudCLI aligned with the authentication source Claude actually uses at runtime.

The status response is parsed even when Claude exits with status 1, because that is its documented logged-out result rather than an unsupported-command failure. Timeouts remain distinguishable from a genuine logged-out response so Keychain-only users are not silently misreported.

This is a deliberately narrow follow-up to #881. That PR also changed the login command and refresh behavior; maintainers requested separate changes and noted that the existing /login flow exposes additional authentication choices. Those behaviors remain untouched here.

Out of scope

The login command, available login methods, and modal refresh behavior are unchanged.

Before and after

Before

CleanShot 2026-07-18 at 11 43 02@2x

After

CleanShot 2026-07-18 at 11 42 43@2x

Test plan

  • npx tsx --tsconfig=server/tsconfig.json --test server/modules/providers/tests/claude-auth.test.ts
  • npm run typecheck
  • npm run lint (passes with the repository's existing warnings)
  • npm run build (passes with the repository's existing CSS and bundle-size warnings)
  • Verified the development API reports authenticated: true with method cli:claude.ai for a macOS Keychain-backed login
  • Verified the Agents account card shows Connected in the development UI

Summary by CodeRabbit

  • New Features
    • Added CLI-based authentication status detection for Claude (including login state, method, and email when available).
    • CLI results now take precedence, while existing environment and credential-file checks remain in place.
  • Bug Fixes
    • Improved handling of CLI errors, missing binaries, and non-standard outputs.
    • Correctly differentiates CLI timeouts from logged-out states to avoid incorrect authentication reporting.

@coderabbitai

coderabbitai Bot commented Jul 18, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

Important

Review skipped

No new commits to review since the last review.

⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: f3455188-b559-4c64-a65f-4e2c635c271d

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review
📝 Walkthrough

Walkthrough

ClaudeProviderAuth now supports injected CLI execution and checks claude auth status --json before falling back to legacy credential files. Tests cover installation failures, authenticated and logged-out CLI responses, and timeout handling.

Changes

Claude CLI authentication

Layer / File(s) Summary
CLI status detection
server/modules/providers/list/claude/claude-auth.provider.ts, server/modules/providers/tests/claude-auth.test.ts
Adds injectable CLI execution, maps Claude CLI JSON authentication results to credential status values, and validates installation, authentication, logout, and timeout cases.
Credential resolution and validation
server/modules/providers/list/claude/claude-auth.provider.ts
Checks CLI status before continuing to the legacy credential-file logic when CLI status is unavailable.

Sequence Diagram(s)

sequenceDiagram
  participant ClaudeProviderAuth
  participant ClaudeCLI
  participant CredentialFiles
  ClaudeProviderAuth->>ClaudeCLI: claude auth status --json
  ClaudeCLI-->>ClaudeProviderAuth: Authentication JSON or error
  alt CLI status is available
    ClaudeProviderAuth-->>ClaudeProviderAuth: Return CLI-derived status
  else CLI status is unavailable
    ClaudeProviderAuth->>CredentialFiles: Read legacy credentials
    CredentialFiles-->>ClaudeProviderAuth: Credential data or error
  end
Loading

Possibly related PRs

Suggested reviewers: viper151, blackmammoth

Poem

I’m a bunny checking CLI trails,
Where Keychain authentication prevails.
JSON hops in, statuses shine,
Timeouts draw a clearer line.
Fallback files wait in the night.

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title is concise and accurately highlights the main change: detecting Claude macOS Keychain auth.
Linked Issues check ✅ Passed The PR satisfies [#556]’s core fix by using claude auth status --json to detect Keychain-backed auth, and it leaves the separate login-refresh work out of scope.
Out of Scope Changes check ✅ Passed The added injection and test coverage support the auth fix, and no unrelated functionality changes are evident.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@sudo-eugene
sudo-eugene marked this pull request as ready for review July 18, 2026 09:43
@sudo-eugene

Copy link
Copy Markdown
Author

@coderabbitai review

@coderabbitai

coderabbitai Bot commented Jul 18, 2026

Copy link
Copy Markdown
Contributor
✅ Action performed

Review finished.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
server/modules/providers/list/claude/claude-auth.provider.ts (1)

29-37: 🎯 Functional Correctness | 🟠 Major | ⚡ Quick win

Handle spawnSync results in checkInstalled()
spawnSync returns an error object for a missing executable instead of throwing, so this try/catch still reports the CLI as installed. Check result.error and result.status before returning true.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@server/modules/providers/list/claude/claude-auth.provider.ts` around lines 29
- 37, Update checkInstalled() to capture the result of spawnSync and return true
only when no result.error exists and the process exits successfully (status 0).
Preserve the existing false result for failures, including missing executables
and nonzero exit statuses.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Outside diff comments:
In `@server/modules/providers/list/claude/claude-auth.provider.ts`:
- Around line 29-37: Update checkInstalled() to capture the result of spawnSync
and return true only when no result.error exists and the process exits
successfully (status 0). Preserve the existing false result for failures,
including missing executables and nonzero exit statuses.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: 17a1d3ce-6a45-40d7-9b07-19624df019c8

📥 Commits

Reviewing files that changed from the base of the PR and between 27eaf01 and 672d15c.

📒 Files selected for processing (2)
  • server/modules/providers/list/claude/claude-auth.provider.ts
  • server/modules/providers/tests/claude-auth.test.ts

@sudo-eugene

Copy link
Copy Markdown
Author

@coderabbitai review

@coderabbitai

coderabbitai Bot commented Jul 18, 2026

Copy link
Copy Markdown
Contributor
✅ Action performed

Review finished.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

claude code login issue in OSX

2 participants