Skip to content

fix(oauth-health): skip alert when credentials file absent (keychain auth)#40

Open
drewdemann wants to merge 1 commit intoearlyaidopters:mainfrom
drewdemann:fix/oauth-keychain-auth
Open

fix(oauth-health): skip alert when credentials file absent (keychain auth)#40
drewdemann wants to merge 1 commit intoearlyaidopters:mainfrom
drewdemann:fix/oauth-keychain-auth

Conversation

@drewdemann
Copy link
Copy Markdown

Summary

On modern macOS, the Claude CLI stores OAuth credentials in Keychain instead of ~/.claude/.credentials.json. The current OAuth health check treats a missing credentials file the same as a malformed one and repeatedly alerts the user via Telegram, even though the spawned Claude subprocess authenticates successfully via the CLI's own Keychain lookup.

Change

Distinguish three read outcomes in src/oauth-health.ts:

  • File missing (ENOENT) → log debug and skip. Keychain auth is the valid modern default, not a broken state.
  • File exists but unreadable or invalid JSON → alert (unchanged behavior).
  • File parsed but missing expiresAt → alert (unchanged behavior).

Expiry and expiring-soon alerts behave identically to before.

Motivation

I set up ClaudeClaw on a Mac where claude auth lives in Keychain (no ~/.claude/.credentials.json ever existed on disk). The bot otherwise worked perfectly — spawned Claude subprocesses authenticated and responded — but the health check fired every 30 minutes with "Cannot read OAuth token. File missing or invalid structure." False positives that drowned out the signal when a real expiry alert eventually matters.

Test plan

  • Verified on macOS 14 with no credentials file on disk: bot starts cleanly, no spurious alert, agent responses succeed.
  • npm run build passes.
  • Test case for malformed-file path (file exists, bad JSON) — alert still fires.
  • Test case for expired token — alert still fires.

No changes to the public API of initOAuthHealthCheck, OAUTH_CHECK_MINUTES, or OAUTH_ALERT_HOURS.

Happy to adjust the log message or wording if you have preferences.

🤖 Generated with Claude Code

On modern macOS, the Claude CLI stores OAuth credentials in Keychain
instead of ~/.claude/.credentials.json. The OAuth health check
currently treats a missing file the same as a malformed one and
repeatedly alerts the user via Telegram, even though the spawned
Claude subprocess authenticates successfully via the CLI's own
Keychain lookup.

Distinguish three read outcomes:
- File missing (ENOENT): log debug and skip. Keychain auth is valid.
- File exists but unreadable or invalid JSON: alert (unchanged).
- File parsed but missing expiresAt: alert (unchanged).

Expiry and expiring-soon alerts are unchanged.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant