Skip to content

Fix menu bar persistence and Codex API key authentication#342

Open
anudeepadi wants to merge 1 commit intosteipete:mainfrom
anudeepadi:fix/codex-api-key-credentials
Open

Fix menu bar persistence and Codex API key authentication#342
anudeepadi wants to merge 1 commit intosteipete:mainfrom
anudeepadi:fix/codex-api-key-credentials

Conversation

@anudeepadi
Copy link

Summary

This PR fixes two critical issues in CodexBar:

  1. Menu bar icon persistence issues
  2. Codex API key authentication not being recognized

Changes Made

Menu Bar Persistence Fixes

  • ✅ Add applicationShouldTerminateAfterLastWindowClosed() to prevent app termination when all windows close
  • ✅ Replace .transient with .stationary for hidden keepalive 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:

  • Desktop space switches (Mission Control)
  • Window closures (Cmd+W)
  • Sleep/wake cycles
  • Empty provider states

Codex API Key Authentication Fix

  • ✅ Update AuthFile struct to include OPENAI_API_KEY field
  • ✅ Add fallback logic in loadAccountInfo() to handle API key authentication
  • ✅ Return "API Key User" when authenticated via API key (JWT claims unavailable)

Problem: The loadAccountInfo() function only supported OAuth tokens with JWT idToken, causing API key authentication to fail silently when users had OPENAI_API_KEY set in ~/.codex/auth.json.

Solution: Added support for both authentication methods (OAuth tokens + API keys) with graceful fallback.

Testing

  • Built and tested locally with API key authentication
  • Verified menu bar icon persistence across space switches
  • Confirmed no regressions in OAuth token authentication path

Files Modified

File Changes
Sources/CodexBar/CodexbarApp.swift Added applicationShouldTerminateAfterLastWindowClosed()
Sources/CodexBar/HiddenWindowView.swift Changed window collection behavior to .stationary
Sources/CodexBar/StatusItemController.swift Set merged icon to always be visible
Sources/CodexBarCore/UsageFetcher.swift Added API key authentication support

Impact

  • Fixes issue where menu bar icon disappears during space transitions
  • Fixes issue where app terminates when settings window is closed
  • Fixes issue where API key authentication is not recognized
  • No breaking changes - maintains backward compatibility with OAuth tokens

Related Issues

Resolves authentication issues when using OPENAI_API_KEY in ~/.codex/auth.json instead of OAuth tokens.

## 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.
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: 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".

Comment on lines +638 to +641
if let idToken = auth.tokens?.idToken {
guard let payload = UsageFetcher.parseJWT(idToken) else {
return AccountInfo(email: nil, plan: nil)
}

Choose a reason for hiding this comment

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

P2 Badge 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 👍 / 👎.

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