Skip to content

Multiple OpenAI/Codex Accounts#569

Open
Rag30 wants to merge 29 commits intosteipete:mainfrom
Rag30:main
Open

Multiple OpenAI/Codex Accounts#569
Rag30 wants to merge 29 commits intosteipete:mainfrom
Rag30:main

Conversation

@Rag30
Copy link

@Rag30 Rag30 commented Mar 18, 2026

Multi-Account Codex Support with Per-Account Dashboard

What it does
Adds full multi-account support for Codex — add, manage, and switch between multiple OpenAI/Codex accounts (OAuth or API key) from a single CodexBar instance. Each account is fully isolated, including same-email accounts on different workspaces.

Account Management
Add accounts via OAuth (codex auth) or API key, each with its own CODEX_HOME
Drag-to-reorder, rename (pencil icon), delete (edit mode), set as default
"CodexBar accounts only" mode — ignore ~/.codex, use only explicitly added accounts
Usage Display

Per-account Session / Weekly / Code Review usage bars in the menu dropdown
Account switcher tabs in the menu dropdown
Active account's credits shown correctly even when no add-on rows exist
Per-Account OpenAI Dashboard

"OpenAI Web Dashboard" toggle controls dashboard button visibility
Each account row shows "Dashboard" or "Login to Dashboard" based on per-account login state
Per-account cookie isolation keyed by CODEX_HOME path — same-email accounts on different workspaces get separate WebKit sessions
"Usage Dashboard" / "Login to OpenAI Dashboard" in the menu reflects the active account's state
Logout clears the account's session and snapshot immediately
**API-key accounts are excluded from web scraping and dashboard login (no ChatGPT session exists for them)

Cost & Usage Availability

Cost and 30-day usage history are only available for accounts that can supply an OpenAI API key:

API-key accounts — fetched directly via the OpenAI REST API (/v1/organization/usage)
~/.codex default account — uses the API key from ~/.codex/auth.json if present
OAuth accounts (added via codex auth with a separate CODEX_HOME path) do not show cost or usage history. OAuth sessions have no associated API key, so there is no way to query the OpenAI usage endpoint. The Usage section is hidden for these accounts; a note in both the settings and the Usage section header makes this clear.

Single Account Widget                         Multi Account Widget                             Updated Codex Settings

Single Account Widget Multi Account Widget codex_stitched-5

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: 9ee0530c99

ℹ️ 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".

@ratulsarna
Copy link
Collaborator

@codex review

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: c99e55a00b

ℹ️ 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

@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: ec149a8ca4

ℹ️ 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

@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: 9f1c28541c

ℹ️ 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".

Rag30 added 4 commits March 21, 2026 13:19
Token-account and other provider config updates bump configRevision; rebuilding
every NSStatusItem via removeStatusItem reflows the system menu bar and makes
other apps' extras flicker. Rebuild only when provider order changes.

Made-with: Cursor
Resolve menu/icon/widget credits from codexActiveMenuCredits using
allAccountCredits for add-on accounts; primary keeps RPC/dashboard store.
Remove primary-only notice; show unlimited and loading states; add tests.

Made-with: Cursor
…rimary missing

- Use TokenAccountSupportCatalog envOverride for per-account credit refresh; load OPENAI_API_KEY-only env as API-key creds
- isDefaultTokenAccountActive + display index for fetches/UI when ~/.codex primary is gone
- Tests for env load and Claude token-account selection

Made-with: Cursor
Rag30 and others added 4 commits March 21, 2026 14:48
…ment

- Introduced a new setting to allow CodexBar to ignore ~/.codex as an implicit account, requiring users to manage accounts explicitly through the UI.
- Updated various components to reflect this change, including adjustments to account selection logic and UI elements.
- Enhanced the handling of account-related actions and settings to improve user experience and clarity.

Made-with: Cursor
Move Multi-Account toggles above the Accounts section so toggling
never shifts scroll position. Rename Use → Default/Make Default,
add drag-and-drop reordering, gate multi-account UI behind a toggle.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Add per-account WKWebView login windows for chatgpt.com dashboard,
replacing the failed synthetic OAuth cookie approach. Each account
gets isolated cookie storage. Dashboard login auto-opens after
OAuth account creation when web extras is enabled.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@Rag30 Rag30 changed the title Multiple OpenAI OAuth Multiple OpenAI/Codex Accounts Mar 22, 2026
Rag30 and others added 2 commits March 22, 2026 22:01
- Add per-account WKWebsiteDataStore keyed by CODEX_HOME path (not email)
  so accounts with the same email but different workspaces get separate
  dashboard sessions
- Add "OpenAI Web Dashboard" toggle in Multi-Account settings section
- Show "Dashboard" / "Login to Dashboard" button per account row based
  on individual login state, with logout option in edit mode
- Add "Usage Dashboard" / "Login to OpenAI Dashboard" in menu dropdown
  (below Buy Credits) reflecting active account's dashboard state
- Fix WKWebView and rename TextField keyboard input by switching to
  NSApp.activationPolicy(.regular) temporarily
- Fix dashboard window not closing Settings when dismissed
- View-only mode for already-logged-in accounts (no auto-close polling)
- Track dashboard login state via observable set on UsageStore for
  reactive SwiftUI updates
- Suppress cost data when "CodexBar accounts only" is on with no accounts

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Each account uses its own WKWebView cookie store via the dashboard login
window, making browser cookie import redundant and error-prone.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@Rag30
Copy link
Author

Rag30 commented Mar 23, 2026

@ratulsarna added features and streamlined codex experience more:

// Multi-account support: add, reorder, and switch between multiple Codex accounts with drag-and-drop
// Per-account OpenAI dashboard login with workspace-isolated WKWebView cookie stores (no browser cookie import)
// Reactive dashboard state tracking, menu bar dashboard button, and inline account rename/logout controls

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@Rag30
Copy link
Author

Rag30 commented Mar 23, 2026

@codex review

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: d04b7cbe87

ℹ️ 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".

Rag30 and others added 2 commits March 23, 2026 09:35
…ation history

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
…le dashboard key

P1: Clear all cached credits/dashboard/cost data when codexExplicitAccountsOnly
has no accounts, not just snapshots/errors/sourceLabel.

P1: Reset selected token account to primary when multi-account toggle is turned
off, so Codex stops fetching against a hidden CODEX_HOME override.

P2: Use stable ~/.codex path as the default account dashboard key instead of the
editable display label, so renaming doesn't break dashboard session persistence.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
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

let targetEmail = self.codexAccountEmailForOpenAIDashboard()
self.handleOpenAIWebTargetEmailChangeIfNeeded(targetEmail: targetEmail)

P1 Badge Reuse the account identifier when refreshing dashboard data

In multi-account mode, the dashboard login window stores cookies in a WKWebsiteDataStore keyed by the per-account identifier (CODEX_HOME path / token), but refreshOpenAIDashboardIfNeeded() still derives the fetch key from codexAccountEmailForOpenAIDashboard(). For any added Codex account, that means the post-login refresh reads a different cookie store than the one the user just signed into, so "Login to Dashboard" can immediately fall back to a login-required state; accounts that share the same email also collapse onto one dashboard session.

ℹ️ 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".

…oard, guard Add Account

P1: refreshOpenAIDashboardIfNeeded now uses CODEX_HOME path (same key as
the dashboard login window) instead of email, so per-account WKWebView
cookie stores are correctly matched after login.

P2: Skip dashboard login/logout UI for API-key accounts (apikey: prefix)
to prevent raw secrets from leaking into UserDefaults and menu payloads.

P2: Hide "Add Account..." menu item when codexMultipleAccountsEnabled is
off, preventing silent switch to a hidden account.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@Rag30
Copy link
Author

Rag30 commented Mar 23, 2026

@codex review

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: 0aaf96c5c3

ℹ️ 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".

Rag30 added 3 commits March 23, 2026 14:00
- Remove stale Add Account label override; use standard Switch/Add Account
- Fix Usage history (30 days) missing in multi-account sectioned card path
- Use card-style items for Credits history, Usage breakdown, Usage history
  buttons so chevron aligns with Subscription Utilization
- Fix stale openAIDashboardCookieImportStatus shown when enabling multi-account
- Fix dashboard error message showing raw file path in multi-account mode
- Persist widget snapshot immediately on multi-account toggle for instant update
- Include codexMultipleAccountsEnabled in menu structure fingerprint so
  account switcher disappears immediately on toggle off
The Login/Dashboard button label already communicates dashboard
login state. Credits come from the Codex RPC/OAuth API, not the
web dashboard scrape, so a dashboard-login error in the Credits
section is both misleading and redundant.
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

let accountEmail = self.store.codexAccountEmailForOpenAIDashboard()
let controller = self.creditsPurchaseWindow ?? OpenAICreditsPurchaseWindowController()
controller.show(purchaseURL: url, accountEmail: accountEmail, autoStartPurchase: autoStart)

P2 Badge Use the per-account dashboard key for Buy Credits

The rest of this change switches dashboard cookies to a CODEX_HOME-based identifier so accounts with the same email but different workspaces stay isolated, but Buy Credits still opens the WebKit store keyed by codexAccountEmailForOpenAIDashboard(). In the same-email/multiple-workspace case, this can reuse the wrong dashboard session and send the user to another account’s billing page.

ℹ️ 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".

@Rag30
Copy link
Author

Rag30 commented Mar 23, 2026

@codex review

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

let autoStart = true
let accountEmail = self.store.codexAccountEmailForOpenAIDashboard()
let controller = self.creditsPurchaseWindow ?? OpenAICreditsPurchaseWindowController()
controller.show(purchaseURL: url, accountEmail: accountEmail, autoStartPurchase: autoStart)

P1 Badge Reuse the dashboard store key in the Buy Credits flow

In multi-account mode, dashboard cookies are now isolated by the account identifier (CODEX_HOME path or ~/.codex), but Buy Credits… still opens OpenAICreditsPurchaseWindowController with codexAccountEmailForOpenAIDashboard(). That points the purchase window at a different WKWebsiteDataStore, so after logging into the dashboard for a specific Codex row, the billing flow can still open logged out or on the wrong account.

ℹ️ 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

@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

self.openAIDashboard = self.lastOpenAIDashboardSnapshot
self.openAIDashboardRequiresLogin = true

P2 Badge Drop the dashboard logged-in flag on session expiry

When the per-account ChatGPT session expires, this branch marks openAIDashboardRequiresLogin but leaves dashboardLoggedInEmails untouched. The menu/settings actions still render Usage Dashboard and pass viewOnly: true into openCodexDashboard, and OpenAIDashboardLoginWindowController skips login detection in that mode, so users cannot complete a re-login from this action until they manually log out the account first.

ℹ️ 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".

Rag30 and others added 7 commits March 23, 2026 14:52
… per-account sessions directories

- API-key Codex accounts now fetch cost/usage via the OpenAI REST API (OpenAIAPIUsageFetcher) instead of scanning local session logs, which were absent for those accounts
- OAuth/path accounts continue to scan local CODEX_HOME/sessions as before; cost fetch is suppressed entirely when the active account is not API-key backed
- Replace the ~/.codex/sessions symlink with a dedicated per-account sessions/ directory to keep cost data isolated across accounts
- Surface token cost errors in the menu card even when no snapshot data is available (error-only state)
- Add inline orange warning notice in Preferences when the active account's cost fetch fails (e.g. missing api.usage.read scope)
- Make ShellIntegration helpers injectable (FileManager, directory URLs) for unit testability
- Conditionally show "Cost only available for API configured accounts" hint based on multi-account state

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
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: 14721e9ced

ℹ️ 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".

…cit-accounts toggle

- Quote the \$(cat ...) command substitution in the precmd hook so paths
  with spaces are not split by zsh word-splitting
- Call repairCodexShellIntegrationIfNeeded() after setting codexExplicitAccountsOnly
  so active-codex-home is synced immediately when the toggle auto-selects
  the first explicit account

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@Rag30
Copy link
Author

Rag30 commented Mar 24, 2026

@codex review

@chatgpt-codex-connector
Copy link

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.

Rag30 added 2 commits March 23, 2026 22:13
- moveTokenAccount: clamp already-invalid activeIndex instead of re-persisting it
- codexMultipleAccountsEnabled setter: call repairCodexShellIntegrationIfNeeded so
  shell CODEX_HOME is updated immediately on enable, not only after a token-account write
- codexExplicitAccountsOnly getter: return false when multipleAccounts is off,
  preventing hand-edited config from leaving the two flags in a contradictory state
- refreshAllAccountCredits: await directly so credits and usage land in the same
  refresh cycle, eliminating the transient mismatch window in the menu
- UsageStore+ObservationHelpers: observe codexMultipleAccountsEnabled explicitly so
  toggling it always triggers a refresh, independent of implementation internals
- Fix two affected tests to enable codexMultipleAccountsEnabled before setting
  codexExplicitAccountsOnly, matching the new enforced invariant

Made-with: Cursor
@Rag30
Copy link
Author

Rag30 commented Mar 24, 2026

@codex review

@chatgpt-codex-connector
Copy link

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.

@Rag30
Copy link
Author

Rag30 commented Mar 26, 2026

@ratulsarna

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.

2 participants