Fix menu bar persistence and Codex API key authentication#342
Fix menu bar persistence and Codex API key authentication#342anudeepadi wants to merge 1 commit intosteipete:mainfrom
Conversation
## Menu Bar Persistence Fixes - Add applicationShouldTerminateAfterLastWindowClosed to prevent app termination when all windows close - Replace .transient with .stationary for hidden window to survive space transitions - Set merged icon to always be visible regardless of provider state - Remove unused anyEnabled variable These changes ensure the menu bar icon persists through space switches, window closures, and when no providers are enabled. ## Codex API Key Authentication Fix - Update AuthFile struct to include OPENAI_API_KEY field for API key support - Add fallback logic in loadAccountInfo() to handle API key authentication format - Return "API Key User" when authenticated via API key (JWT claims unavailable) Previously, loadAccountInfo() only supported OAuth tokens with JWT idToken, causing API key authentication to fail silently. This fix ensures CodexBar recognizes both OAuth and API key authentication methods from ~/.codex/auth.json.
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 19d68c92cb
ℹ️ 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".
| if let idToken = auth.tokens?.idToken { | ||
| guard let payload = UsageFetcher.parseJWT(idToken) else { | ||
| return AccountInfo(email: nil, plan: nil) | ||
| } |
There was a problem hiding this comment.
Fall back to API key when JWT parse fails
If auth.json contains both tokens.idToken and OPENAI_API_KEY (e.g., a user switches to API key auth but an old/empty/invalid idToken remains), the current logic returns early on parseJWT failure and never reaches the API key fallback. That means API key auth still fails in this mixed state even though the key is valid. Consider falling back to the API key path when parseJWT returns nil instead of returning immediately.
Useful? React with 👍 / 👎.
Summary
This PR fixes two critical issues in CodexBar:
Changes Made
Menu Bar Persistence Fixes
applicationShouldTerminateAfterLastWindowClosed()to prevent app termination when all windows close.transientwith.stationaryfor hidden keepalive window to survive space transitionsanyEnabledvariableThese changes ensure the menu bar icon persists through:
Codex API Key Authentication Fix
AuthFilestruct to includeOPENAI_API_KEYfieldloadAccountInfo()to handle API key authenticationProblem: The
loadAccountInfo()function only supported OAuth tokens with JWTidToken, causing API key authentication to fail silently when users hadOPENAI_API_KEYset in~/.codex/auth.json.Solution: Added support for both authentication methods (OAuth tokens + API keys) with graceful fallback.
Testing
Files Modified
Sources/CodexBar/CodexbarApp.swiftapplicationShouldTerminateAfterLastWindowClosed()Sources/CodexBar/HiddenWindowView.swift.stationarySources/CodexBar/StatusItemController.swiftSources/CodexBarCore/UsageFetcher.swiftImpact
Related Issues
Resolves authentication issues when using
OPENAI_API_KEYin~/.codex/auth.jsoninstead of OAuth tokens.