Repository navigation
Switch between subscription accounts - #7272
Closed
omarchybot wants to merge 3 commits into
Closed
omarchybot wants to merge 3 commits into
omarchybot wants to merge 3 commits into
Conversation
A machine can hold more than one subscription for the same provider -- a personal Claude Max and a work one -- and Omarchy knew only whichever was signed in. These commands remember several and swap between them, the way `tailscale switch` moves between tailnets. The unit is the subscription, not the harness that spends it. One Anthropic subscription is reachable through Claude Code, pi and opencode, each holding its own credential copy, and the usage collector already merges all three into one record. Swapping ~/.claude alone would leave pi and opencode authenticated as the other account while their tokens kept landing in the same panel record, so an account is a bundle of per-harness credential slots and a switch moves every one of them. Two slot kinds, because the harnesses differ. Claude and Codex serve one provider each, so the whole config dir is swapped through an atomic symlink -- which also keeps transcripts per account. Pi and opencode keep every provider's credential in one auth.json, where swapping the file would switch the OpenAI account when you asked for Anthropic, so only that provider's key is stashed and restored. Credentials are never minted here: a slot is filled by running the harness's own login and capturing what it wrote. Every switch stashes the live values back into the outgoing account first, since OAuth blobs refresh themselves in place and a stored copy goes stale otherwise. A harness that is not installed is not a slot on this machine. An installed one with no credential for the account warns and is signed out rather than left authenticated as the wrong account -- a silent partial switch is the failure this design exists to prevent. Provisioning and Claude theming now reach every managed account dir rather than whatever the link currently points at, and a switch ledger records timestamped account changes so the collectors can later attribute pi and opencode sessions, which record the provider but not the account. Co-Authored-By: Claude Opus 5 <[email protected]> Co-Authored-By: Codex <[email protected]>
The panel drew one record per provider, which was right while a machine held one subscription each. With several, the record has to say which account it describes: an account's rate limits mean nothing beside another account's tokens. Each account now gets its own record, collected with that account's config directory in the environment so it reads that account's transcripts, and named <provider>@<account> so the panel can tell them apart while keeping the provider as the stable key for assets and settings. The limits probe cached to a fixed claude-limits.json, so a second account would have displayed the first account's remaining allowance. Every cache the collectors keep is now keyed by the resolved config directory. Pi, omp and opencode are the harder half. They spend a subscription without writing a transcript the account owns, and their session files record the provider but not which account was signed in, so adding their tokens to every account record would count the same spend several times. The switch ledger answers it: each message is attributed to whichever account was active when it was written, and history older than the ledger goes to the account it first names. Without a readable ledger they fall back to the active account alone -- never to all of them -- and any record that took them in says so with includesSharedSessions. A machine with a single account collects exactly what it collected before. Co-Authored-By: Claude Opus 5 <[email protected]> Co-Authored-By: Codex <[email protected]>
The panel drew one chip per provider and called that row a subscription switch. It now draws one per account, so the work subscription sitting at 92% is visible beside the personal one at 10% -- which is the question you actually have before switching, and it cannot be answered by a panel that only ever shows the account currently signed in. Chips still only change what you are looking at. Making an account active is a separate keypress and a separate control, because a click meant to read a number must never move a credential. Records are named <provider>@<account> now, so everything the panel keys off an id had to move to the provider: the enablement settings, whose existing entries still say claude and codex, the mark lookup, which still resolves claude.svg, and the sync merge, which keys on provider and account together so two accounts never collapse into one while the same account still merges across machines. The limits retry fed the record id back to the updater, which would have matched no collector at all once that id carried an account. Tokens spent through pi, omp or opencode draw from extra usage rather than the plan, so they show up in the charts while the limit meters ignore them. The panel says so where the mismatch appears, rather than leaving it looking like a rendering bug. The menu gains an Accounts submenu over the same list, marking the active account and switching on selection. Co-Authored-By: Claude Opus 5 <[email protected]> Co-Authored-By: Codex <[email protected]>
Contributor
There was a problem hiding this comment.
Pull request overview
Note
Copilot was unable to run its full agentic suite in this review.
This PR adds first-class support for multiple subscription accounts per provider (Anthropic/OpenAI), including credential bundle switching, account-attributed usage collection/sync identity, and UI/menu affordances to browse and switch accounts.
Changes:
- Introduces account management CLI commands (list/login/switch/logout) backed by a managed credential store and switch ledger.
- Updates usage collection + agents panel logic to key records by
(providerId, accountId)and attribute shared harness usage via the switch ledger. - Adds Omarchy Menu + panel UI controls for account switching and updates docs/tests to reflect canonical provider IDs (
anthropic,openai).
Reviewed changes
Copilot reviewed 20 out of 33 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| test/shell.d/menu-test.sh | Extends menu tests for the new agent-accounts volatile provider and switching behavior. |
| test/shell.d/fixtures/bar-widget-contract/shell.qml | Updates contract tests for canonical provider IDs and icon resolution mapping. |
| test/shell.d/agents-panel-test.sh | Adds assertions for account switching bindings, canonical IDs, and sync identity behavior. |
| test/shell.d/agent-usage-update-test.sh | Validates that bare providers still emit the account identity fields. |
| test/shell.d/agent-usage-fireworks-scanner-test.sh | Extends Fireworks scanner expectations to include account identity fields. |
| test/shell.d/agent-usage-codex-scanner-test.sh | Updates Codex collector expectations for providerId and cache schema bump. |
| test/shell.d/agent-usage-claude-scanner-test.sh | Updates Claude collector expectations for providerId. |
| test/shell.d/agent-usage-claude-limits-test.sh | Verifies Claude limits cache is keyed by resolved config directory digest. |
| test/shell.d/agent-usage-account-attribution-test.sh | New end-to-end tests for ledger-based attribution across accounts and legacy selectors. |
| test/shell.d/agent-account-test.sh | New tests covering account adoption, slot login/switch/logout, and provisioning interactions. |
| test/cli | Ensures omarchy-theme-set-claude works with OMARCHY_PATH and respects config overrides. |
| shell/plugins/menu/Menu.qml | Adds agent-accounts provider to Menu for listing/switching managed accounts. |
| shell/plugins/agents/manifest.json | Switches defaults to canonical provider IDs (anthropic, openai). |
| shell/plugins/agents/README.md | Documents account-aware records, shared-session attribution, and canonical IDs. |
| shell/plugins/agents/Panel.qml | Updates UI selection keying, adds Switch/Active hero control, chip labeling, shared-usage note, asset mapping. |
| shell/plugins/agents/Main.qml | Canonicalizes provider IDs, keys identity by provider/account, dedupes retries, and updates snapshot aggregation. |
| manual/17-ai.md | Documents subscription accounts, switching semantics, and panel behavior with shared harness usage. |
| manual/14-omarchy-cli.md | Updates CLI group description to include accounts. |
| docs/menu.md | Documents new agent-accounts provider contract and volatility. |
| default/omarchy/omarchy-menu.jsonc | Adds Accounts submenu under Setup > Defaults > Agent. |
| bin/omarchy-theme-set-claude | Applies theme to all managed Anthropic config slots (or override), with locking. |
| bin/omarchy-provision-user | Provisions skills into every managed config-dir slot via account backends. |
| bin/omarchy-agent-usage-update | Fans collectors out across managed accounts; normalizes canonical/legacy provider selectors; prunes stale records. |
| bin/omarchy-agent-usage-fireworks | Emits account identity fields for the bare Fireworks provider record. |
| bin/omarchy-agent-usage-codex | Converts to OpenAI/provider-account record, adds ledger attribution for shared sessions, bumps cache schema. |
| bin/omarchy-agent-usage-claude | Converts to Anthropic/provider-account record, adds ledger attribution and per-config-dir caches, updates limits cache keying. |
| bin/omarchy-agent-account-switch | New CLI to switch credential bundles across slots and request panel refresh. |
| bin/omarchy-agent-account-logout | New CLI to forget an inactive account by moving it to recoverable trash and pruning usage. |
| bin/omarchy-agent-account-login | New CLI to fill individual harness slots for a provider account, capturing credentials into managed store. |
| bin/omarchy-agent-account-list | New CLI to list accounts and per-slot readiness (text/JSON). |
| bin/omarchy-agent-account-backends | New shared backend implementing managed roots, adoption, locking, slot stash/restore, and switch ledger. |
| bin/omarchy-agent-account | New CLI to print the active provider account (or all active accounts when no default agent). |
| bin/omarchy | Updates “agent” group description to include accounts. |
Suppressed comments (1)
test/shell.d/menu-test.sh:1
- This
trap ... EXIToverwrites any previously registered EXIT trap in the script (including traps potentially set bybase-test.sh), which can cause earlier cleanup logic to be skipped. Prefer chaining with the existing trap (read current viatrap -p EXITand append) or reusing the shared tempdir cleanup helpers if the test harness provides them.
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
Comment on lines
+81
to
+91
| function providerAccountCount(p) { | ||
| if (!p) return 0 | ||
| var count = 0 | ||
| for (var i = 0; i < providers.length; i++) | ||
| if (providers[i].providerId === p.providerId) count++ | ||
| return count | ||
| } | ||
|
|
||
| function chipLabel(p) { | ||
| if (!p) return "" | ||
| if (providerAccountCount(p) > 1 && String(p.accountLabel || "") !== "") |
Comment on lines
98
to
108
| function scheduleLimitsRetry() { | ||
| var advising = [] | ||
| var seen = {} | ||
| for (var i = 0; i < agents.length; i++) { | ||
| var record = agents[i] ? agents[i].record : null | ||
| if (record && record.retryAdvised === true && providerEnabled(String(record.id || ""))) | ||
| advising.push(String(record.id)) | ||
| var providerId = providerIdForRecord(record) | ||
| if (record && record.retryAdvised === true && providerEnabled(providerId) && !seen[providerId]) { | ||
| advising.push(providerId) | ||
| seen[providerId] = true | ||
| } | ||
| } |
| actionFor: function(value) { return "omarchy-font-set " + Util.shellQuote(value) } | ||
| }, | ||
| "agent-accounts": { | ||
| script: "omarchy agent account list --json 2>/dev/null | jq -r '.[] | [((.providerName // .providerId) + \" · \" + .accountLabel), (.providerId + \"@\" + .accountId), (if .accountActive then (.providerId + \"@\" + .accountId) else \"\" end)] | @tsv' 2>/dev/null", |
Contributor
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
A machine can hold more than one subscription for the same provider — a personal Claude Max and a work one — and Omarchy knew only whichever was signed in. There was no way to remember a second, see it beside the first, or swap which one is live. This adds that, the way
tailscale switchmoves between tailnets.The unit is the subscription, not the harness
One Anthropic subscription is reachable through Claude Code, pi and opencode, each holding its own credential copy, and
omarchy-agent-usage-claudealready merges all three into a single record. So swapping~/.claudealone would have left pi and opencode authenticated as the other account while their tokens kept landing in the same record — account A's limits drawn beside account A+B's usage.An account is therefore a bundle of per-harness credential slots, and a switch moves every one of them. Two slot kinds, because the harnesses differ:
auth.json, where swapping the file would switch the OpenAI account when you asked for Anthropic. Only that provider's key is stashed and restored.Credentials are never minted here: a slot is filled by running the harness's own login and capturing what it wrote. Every switch stashes the live values back into the outgoing account first, because OAuth blobs refresh themselves in place and a stored copy goes stale otherwise.
A harness that is not installed is not a slot on this machine. An installed one with no credential for the account is signed out rather than left authenticated as the wrong account — a silent partial switch is the failure this design exists to prevent.
Usage records
One record per account, named
<provider>@<account>, collected with that account's config directory. The limits probe previously cached to a fixedclaude-limits.json, so a second account would have displayed the first one's remaining allowance; every cache is now keyed by the resolved config directory.Pi, omp and opencode sessions record the provider but not the account, so adding their tokens to every record would count the same spend several times over. A switch ledger settles it: each message is attributed to whichever account was active when it was written, and history older than the ledger goes to the account it first names. Without a readable ledger they fall back to the active account alone, never to all of them.
Panel and menu
One chip per account with the active one marked, so the work subscription at 92% is visible beside the personal one at 10% — the question you actually have before switching, and one a panel showing only the signed-in account cannot answer. Chips still only change what you are looking at; making an account active is a separate keypress and control, because a click meant to read a number must never move a credential.
Tokens spent through a third-party harness draw from extra usage rather than the plan, so they appear in the charts while the limit meters ignore them. The panel says so, rather than leaving the mismatch looking like a rendering bug.
The menu gains an Accounts submenu over the same list, marking the active account and switching on selection.
What this does not cover
No real logins have been exercised. The mechanism is tested against fixtures, and the six native flows — claude, codex, pi ×2, opencode ×2 — need actual second accounts before anyone should trust them.
Only claude, codex, pi and opencode have slots. omp should use its own
--profilerather than a copy of it, crush and grok are unstarted, gemini's credential storage is unverified, and copilot keeps its credential in the OS keyring that Omarchy ships, so it needs a keyring slot kind rather than a swapped directory.