Skip to content

Conversation

@manikv12
Copy link

@manikv12 manikv12 commented Jan 25, 2026

Fixes #243

Summary

  • Fixes repeated keychain password prompts even after user grants "Always Allow" access to Claude Code credentials
  • Adds silent keychain access to avoid unexpected prompts during background operations
  • Caches credentials in CodexBar's own keychain to minimize access to Claude Code's keychain

Changes

  • Add allowKeychainPrompt parameter to ClaudeOAuthCredentialsStore.load() to control prompt behavior
  • Add loadFromClaudeKeychainWithoutPrompt() using LAContext.interactionNotAllowed to silently fail
  • Add invalidateCacheIfClaudeKeychainChanged() to detect credential changes without prompting
  • Skip keychain prompts during background refreshes and availability checks
  • Cache credentials in CodexBar's own keychain after first successful access
  • Re-migrate Claude credentials when they change to maintain proper accessibility settings

Test plan

  • All 548 tests pass (pre-existing BrowserDetection test failures unrelated to this change)
  • Verify keychain prompts are reduced when using Claude provider
  • Verify credentials are properly cached after first access
  • Verify account switches are detected and cache is invalidated

CodexBar was prompting for keychain password repeatedly even after
the user granted "Always Allow" access to Claude Code credentials.

Changes:
- Add `allowKeychainPrompt` parameter to `ClaudeOAuthCredentialsStore.load()`
- Add `loadFromClaudeKeychainWithoutPrompt()` using LAContext to silently fail
- Add `invalidateCacheIfClaudeKeychainChanged()` to detect credential changes
- Skip keychain prompts during background refreshes and availability checks
- Cache credentials in CodexBar's own keychain after first successful access
- Re-migrate Claude credentials when they change to update accessibility
Copilot AI review requested due to automatic review settings January 25, 2026 07:48
Copy link

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: e2fa96efbe

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR addresses issue #243 where CodexBar repeatedly prompts for keychain password despite "Always Allow" being selected. The fix implements a multi-layered caching strategy and silent keychain access to minimize user prompts.

Changes:

  • Added allowKeychainPrompt parameter to control when keychain prompts are shown, preventing unexpected prompts during background operations
  • Implemented silent keychain access using LAContext.interactionNotAllowed to read credentials without triggering prompts
  • Added credential caching in CodexBar's own keychain to reduce access frequency to Claude Code's keychain
  • Implemented change detection for both file-based and keychain-based credentials to maintain cache validity
  • Enhanced migration logic to re-migrate Claude credentials when they change

Reviewed changes

Copilot reviewed 9 out of 9 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
Sources/CodexBarCore/Providers/Claude/ClaudeOAuth/ClaudeOAuthCredentials.swift Core implementation: added allowKeychainPrompt parameter, silent keychain access methods, cache invalidation logic, and file fingerprinting to detect credential changes
Sources/CodexBar/KeychainMigration.swift Added logic to re-migrate Claude credentials when they change, tracking credentials via fingerprints to maintain proper accessibility settings
Sources/CodexBarCore/Providers/Claude/ClaudeUsageFetcher.swift Updated to use allowKeychainPrompt: false during background refreshes to prevent prompts
Sources/CodexBarCore/Providers/Claude/ClaudeProviderDescriptor.swift Updated availability check to use allowKeychainPrompt: false to prevent prompts during background checks
Sources/CodexBar/UsageStore.swift Updated debug dump to use allowKeychainPrompt: false to prevent prompts during diagnostic operations
Sources/CodexBar/UsageStore+Refresh.swift Added cache invalidation check after fetching to detect credential changes and trigger re-fetch if needed
Tests/CodexBarTests/ClaudeOAuthCredentialsStoreTests.swift Added tests for cache invalidation when credentials file changes, with some test setup improvements
Tests/CodexBarTests/KeychainMigrationTests.swift Added test entries for new keychain items and migration tracking reset functionality
CHANGELOG.md Documented the bug fix with details of the implementation approach

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

- Remove redundant fingerprint check in cached credentials (already validated by invalidateCacheIfCredentialsFileChanged)
- Remove redundant KeychainAccessGate assignment in test
- Add comment explaining cache re-store in test
@elpinguinofrio
Copy link

ser, pls approve, it's annoying, compute is idling while waiting user to "always allow" every time
Screenshot 2026-01-25 at 9 35 39 AM

@manikv12
Copy link
Author

manikv12 commented Jan 25, 2026

@steipete

⚠️ Known Limitation: Token Refresh May Require Re-authorization

While this PR significantly reduces keychain prompts, there's one scenario where prompts may still occur:

When Claude Code refreshes expired OAuth tokens (typically every few hours/days), it updates the keychain item which can reset the Access Control List (ACL). This means:

  1. CodexBar's "Always Allow" permission may be cleared
  2. The next time CodexBar tries to access credentials, it may prompt again
  3. After re-granting "Always Allow", the credentials are cached in CodexBar's own keychain

Why this happens:

  • Claude Code owns the Claude Code-credentials keychain item
  • When updating expired tokens, macOS may reset the ACL to default (owner-only)
  • CodexBar cannot programmatically modify another app's keychain ACL

Mitigation in this PR:

  • CodexBar caches credentials in its own keychain after first successful access
  • Silent detection of credential changes (invalidateCacheIfClaudeKeychainChanged())
  • Background refreshes use allowKeychainPrompt: false to avoid unexpected prompts
  • Re-migration attempts to restore proper accessibility when credentials change

Result: Prompts are reduced from "every access" to "occasionally after token refresh" - a significant improvement but not completely eliminated.

Complete fix would require: Claude Code to preserve third-party app ACL entries when updating credentials (feature request to Anthropic).

@tylerseymour
Copy link

Does this address the scenario where the user does not wish to grant keychain access at all? I'm not sure why this is a mandatory requirement when just processing .codex/ folder data...

@manikv12
Copy link
Author

@tylerseymour It wont address that you need permission to token to be able to get your usage from anthropic API what other way you will get your usage ?

@elpinguinofrio
Copy link

can we please merge this at least partial solution instead of waiting for perfect solution and address future issues in the future?

@manikv12
Copy link
Author

Its not on my hand. Only project owner can merge it.

@steipete
Copy link
Owner

I'm sorry. The internet is exploding rn.

@manikv12
Copy link
Author

@elpinguinofrio
Have you pulled down the branch and tested this branch on your local if it fixes your issue?

./Scripts/compile_and_run.sh

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.

"Always Allow" keychain prompt does not persist – repeatedly asks for login password on macOS

5 participants