--- summary: "Accepted design for Claude subscription accounts and per-account menu bar items." read_when: - Reviewing Claude multi-account support - Designing per-account status items - Evaluating claude-swap integration --- # Claude multi-account and status item decision Status: **Phase 1 account display implemented; Phase 2 explicit account activation accepted.** Related: [#1756](https://github.com/steipete/CodexBar/issues/1756), [#1268](https://github.com/steipete/CodexBar/issues/1268), and the bounded Claude sign-in repair in [#1811](https://github.com/steipete/CodexBar/pull/1811). ## Accepted direction 1. Use an opt-in `claude-swap` adapter as the first Claude subscription multi-account source. 2. Normalize its results behind a provider-neutral account snapshot before adding any status item UI. 3. Make per-account status items opt-in, replace the provider item for that provider, cap selection at four, and keep them mutually exclusive with Merge Icons. 4. Allow an explicit click on an inactive account card to invoke exactly `cswap --switch-to --json`. Keep automatic switching and session launching out of scope. This solves the durable OAuth refresh problem without making CodexBar a second credential vault. It also avoids a Claude-only status item implementation that would need to be redesigned for Codex and other providers. ![Proposed multi-account settings and status items](screenshots/claude-multi-account-status-items-proposal.svg) ## Current architecture and gap CodexBar has three account concepts today: - The ambient Claude OAuth credential is routed from CodexBar's cache, Claude Code's credentials file, or Claude Code's Keychain item. It represents one active credential. Claude Code-owned expired credentials delegate refresh back to the CLI; CodexBar-owned cached credentials can refresh directly. - `ProviderTokenAccount` stores a label and one token plus optional provider metadata. It has no refresh token or expiry model. Claude entries therefore work for session cookies, Admin API keys, or short-lived OAuth access tokens, but they are not durable multi-subscription OAuth sessions. - `TokenAccountUsageSnapshot` and `CodexAccountUsageSnapshot` separately project multi-account usage into menus. Status items remain provider-scoped: `StatusItemIdentity` has only `merged` and `provider`, and `statusItems` is keyed by `UsageProvider`. The recently merged [#1800](https://github.com/steipete/CodexBar/pull/1800) scopes Claude OAuth history to the routed Keychain identity. [#1776](https://github.com/steipete/CodexBar/pull/1776) prevents CLI-runtime usage refreshes from delegating credential repair to Claude Code, while app and user-initiated repair remain available. Both changes improve single-active-account correctness; neither discovers or displays multiple subscriptions. The closed [#1707](https://github.com/steipete/CodexBar/pull/1707) should not be revived. It coupled account discovery, credential resolution, provider routing, menu rendering, and animation across a large patch while broadening Keychain and prompt behavior. The safer seam is a credential-free usage adapter first. ## Source options | Option | Credential ownership | Durability | Risk | Recommendation | | --- | --- | --- | --- | --- | | First-party OAuth account vault | CodexBar | High | New login, refresh, storage, revocation, migration, and security surface | Defer | | Bounded `claude-swap` adapter | `claude-swap` | High | External executable and schema dependency | **Phase 1–2** | | Discover Claude Code Keychain entries | Claude Code / ambiguous | Unknown | Undocumented enumeration; prompt and identity hazards | Reject | | Existing token accounts | CodexBar config | Low for OAuth | Access token expires without refresh metadata | Keep for current cookie/API-key uses | As of [`claude-swap` v0.18.0](https://github.com/realiti4/claude-swap/releases/tag/v0.18.0), `cswap --list --json` still returns a versioned object with `schemaVersion: 1`, an active account number, account slots, redaction-sensitive email labels, 5-hour and 7-day usage percentages, optional model-scoped weekly windows, and reset timestamps. Handled failures return an error object and non-zero exit. Direct switching returns the same versioned envelope. CodexBar does not need `--token-status`, credential files, Keychain access, or raw OAuth values for display or explicit activation. ## Phase 1 adapter contract - Disabled by default. User chooses an executable path and enables “Read accounts from claude-swap.” - Execute exactly the argument array `cswap --list --json`. Never invoke a shell or accept config-defined passthrough arguments. - Require `schemaVersion == 1`; reject unknown versions and partial top-level shapes. - The optional top-level `supportsAccountSwitching` boolean defaults to `true` for schema-v1 compatibility. With `false`, account cards and chips remain inspectable but never offer switching or re-authentication actions. A present non-boolean value (including `null` or a number) is rejected as a malformed capability. - Bound runtime and stdout, terminate on timeout, and retain the last successful snapshot with a stale marker. - Parse only slot number, email, `organizationUuid`, active state, usage status, 5-hour/7-day percentages, optional `usage.scoped` display names and percentages, reset timestamps, display-only `organizationName` (always present, may be empty), and optional display-only `alias` when non-empty. Ignore malformed or unknown scoped rows without discarding valid account-wide windows. Unknown extra JSON fields remain ignored. Empty `organizationName` is not an error; `alias` is not required. - Use optional `usageFetchedAt` for the measurement's last-updated time, so polling the adapter's cache does not make old usage appear freshly measured. Missing or malformed timestamps retain the refresh-time fallback and valid windows. - Parse optional display-only `usage.spend`, `disabled`, and `lastGoodUsage` with `lastGoodFetchedAt`. Malformed additive fields fail independently of valid live windows; ignore the row's free-form `message`. Source-declared last-known measurements keep their own timestamp and a visible age beside diagnostics, and never drive the age-less menu icon or ready-account suggestions. Cache only numeric quota data, capture time, provenance, and the existing account fingerprint. - `unavailable` does not establish a polling-failure cause. Retain the existing same-account, unexpired at-limit windows only when the source supplies no explicit last-good measurement; preserve their freshness provenance. - Disabled slots are excluded only from source-owned automatic rotation. They remain explicit switch targets; `foreign_credential` is also recoverable through the existing explicit slot activation contract. - Never log or persist raw email, organization UUID, organization name, or alias. Respect Hide Personal Info. Forecast history hashes the normalized email and organization UUID as a pair, independently of the activation slot. Personal accounts may have an empty organization UUID; email changes start a new history. When two or more slots share an email, disambiguate with `email · organizationName` or `email · Account N`; a user-chosen alias wins. Unique emails stay email-only. - Use the source-issued numeric slot for identity (`claude-swap:`), not email or credential-derived values. - The claude-swap usage adapter never reads `claude-swap` storage, Claude Code storage, environment credentials, or Keychain entries. The subprocess remains solely responsible for its own credential access. The adapter copies only allow-listed usage/identity fields into its model and never logs or persists raw stdout. Separately, the local cost scanner reads only session `projects` logs under known claude-swap profile roots, as documented in [claude.md](claude.md#cost-usage-local-log-scan); it does not read the adapter's credential storage. - Never run `auto`, `run`, `--switch`, `--switch-to`, `--add-account`, export, import, purge, or any other command in Phase 1. - Isolate adapter failure from ambient Claude usage and discard canceled list/version reads. Users without `claude-swap` see no behavior change. The executable is an optional external dependency, not a bundled component. Preferences should show detected version, last refresh, adapter errors, and a link to the upstream project; CodexBar should not install or update it. ## Phase 2 explicit activation contract - Only an explicit click on an actionable account card or actionable inactive account chip can start a switch. Normal activation targets inactive slots. An active slot reporting `foreign_credential` offers **Re-authenticate**, using the same slot command so claude-swap can reconcile its proven credential mismatch. No force flag is used; selecting the active segment remains inspection-only. - The Segmented layout labels its chips **Switch Claude Code account**. An inactive actionable chip switches Claude Code's credentials; active and unavailable chips only inspect that slot. Chips retain their short account identities, with action-specific tooltips and accessibility labels that respect Hide Personal Info. - Derive the numeric slot from the already validated account snapshot and execute exactly `cswap --switch-to --json`; never accept free-form arguments or invoke a shell. - Serialize switches, validate `schemaVersion == 1` and the returned target slot, and bound captured output. - Once launched, let the external credential transaction reach its natural exit without forced timeout or cancellation. If the adapter setting changes, hide its UI state and discard its result when the original configuration is no longer current. - Refresh ambient Claude usage and the adapter account list after completion. Publish known switch errors before waiting for that refresh, independently from list-refresh errors, and preserve the last successful usage snapshots. Keep the transaction guard until reconciliation finishes; discard the error if its configuration changes. - Show **Switching account…** while the external command is running, then **Refreshing account status…** while ambient usage and the independently scheduled adapter account list are reconciled. Wait for a replacement list read while its configuration is still current. Update the open menu through its tracking-safe rebuild scheduler; keep the requested slot and disabled controls through both phases. The adapter's refreshed account list alone determines active styling, and a known switch error remains visible beside progress. This feedback does not diagnose or shorten a slow refresh. - Configuration invalidation clears visible progress without cancelling the transaction. Returning to the same executable path cannot revive the old phase or error, and another activation waits for the original task to drain. - Keep expired, missing, unknown, and Keychain-inaccessible credential slots non-actionable. Never auto-switch, launch sessions, add/import/export/purge accounts, or mutate credentials directly. ## Provider-neutral account model Introduce one projection used by menus and status items rather than teaching status item code about Claude OAuth: ```swift struct ProviderAccountUsageSnapshot: Identifiable { let id: ProviderAccountIdentity let provider: UsageProvider let displayLabel: String let isActive: Bool let canActivate: Bool let snapshot: UsageSnapshot? let error: String? let sourceLabel: String? } struct ProviderAccountIdentity: Hashable { let source: String let opaqueID: String } ``` Adapters own identity conversion. UI receives a user alias or privacy-safe ordinal when personal information is hidden. No provider may fill identity, plan, or usage fields using another provider's data. Existing `TokenAccountUsageSnapshot` and `CodexAccountUsageSnapshot` can migrate behind this projection in small, separately reviewed steps. Their credential and refresh logic stays source-specific. ## Per-account status item behavior Proposed setting under each provider's Accounts section: - `One provider icon` (default; current behavior) - `Selected account icons`, with up to four account checkboxes Selecting account icons replaces that provider's aggregate item; it does not add duplicates. Account items use a stable `StatusItemIdentity.account(provider:source:opaqueID:)`, preserve existing provider autosave names, and open the provider menu focused on that account. A short user alias or ordinal badge distinguishes otherwise identical provider icons. Hide Personal Info replaces labels with `Account 1`, `Account 2`, and so on. Merge Icons continues to mean exactly one status item. Account-icon controls are disabled while it is enabled, with a button to turn Merge Icons off. Existing users and status item positions remain unchanged until they opt in. The alternative proposed in the #1268 discussion is a per-account toggle that adds selected account items, leaves unselected accounts under the provider item, and coexists with Merge Icons. That is more granular, but it creates duplicate provider/account items, makes “Merge Icons” no longer mean one item, and multiplies autosave and recovery states. The replacement mode above is the recommendation; if maintainers prefer the additive mode, grouping and Merge Icons semantics must be decided before implementation. ## UI proof The mock above shows the recommended mode and its Merge Icons conflict. It is intentionally a decision artifact, not an implementation screenshot. The following packaged synthetic-account proof verifies the bounded current behavior: the separate ambient OAuth action is named “Sign in with Claude Code…”, while inactive claude-swap cards retain their explicit “Switch Account…” action. No real credential, browser session, or provider call was used. ![Packaged synthetic Claude sign-in proof](screenshots/claude-sign-in-synthetic-proof.png) ## Accepted decisions 1. The optional external `claude-swap` dependency is accepted for exact `cswap --list --json` execution and explicit `cswap --switch-to --json` activation. 2. Automatic switching, account add/import/export/purge, and session launching stay out of scope. 3. Provider-neutral account snapshots land before any per-account status item work. 4. Per-account status items are capped at four and mutually exclusive with Merge Icons. 5. Status item labels use aliases or privacy-safe ordinals, never email identity. Any further change to these decisions requires a new product/auth review before implementation because it changes storage, status item migration, process authority, or the credential boundary. ## Implementation and validation sequence 1. Add fixtures for schema v1, error payloads, unknown versions, invalid percentages/timestamps, output limits, and process timeout. Use a fake executable only. 2. Add the opt-in adapter and provider-neutral projection. Verify no credential reads and no impact on ambient Claude. 3. Add settings-state and menu-model tests. Keep AppKit status item creation out of headless tests. 4. Add status item identity/migration tests, then implement account items behind the opt-in setting. 5. Add exact-argv, strict switch-result, serialization, and refresh tests using a fake executable only. 6. Run focused tests, `make check`, `make test`, packaged synthetic proof, and macOS UI proof with redacted fixtures. No credential import, automatic switching, session launching, or compatibility shim is part of this proposal.