Repository navigation
Track usage limits for several Claude and Codex accounts - #6516
kmpeeduwee wants to merge 1 commit into
Conversation
There was a problem hiding this comment.
Pull request overview
Adds account-scoped Claude and Codex usage tracking while preserving default single-account behavior.
Changes:
- Creates provider instances dynamically from account configuration.
- Scopes credentials, histories, and scanners to configured directories.
- Updates panel icons, documentation, and tests for account-aware behavior.
Tip
If you aren't ready for review, convert to a draft PR.
Click "Convert to draft" or run gh pr ready --undo.
Click "Ready for review" or run gh pr ready to reengage.
Reviewed changes
Copilot reviewed 9 out of 9 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
shell/plugins/model-usage/Main.qml |
Builds and aggregates account-specific providers. |
shell/plugins/model-usage/Panel.qml |
Selects icons by provider kind. |
shell/plugins/model-usage/providers/Claude.qml |
Resolves Claude data beneath each account directory. |
shell/plugins/model-usage/providers/Codex.qml |
Passes account-specific CODEX_HOME to the scanner. |
shell/plugins/model-usage/manifest.json |
Defines default account directories. |
shell/plugins/model-usage/README.md |
Documents multi-account configuration. |
test/shell.d/model-usage-providers-test.sh |
Runs provider fan-out tests. |
test/shell.d/fixtures/model-usage-providers/shell.qml |
Exercises account configuration shapes. |
test/shell.d/fixtures/bar-widget-contract/shell.qml |
Verifies kind-based account icons. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| command: ["python3", root.scannerPath] | ||
| // The scanner reads CODEX_HOME itself, so pointing it at another account | ||
| // is a matter of handing it a different one. | ||
| environment: ({ "CODEX_HOME": root.configDir }) |
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 11 out of 11 changed files in this pull request and generated no new comments.
Suppressed comments (2)
shell/plugins/model-usage/providers/Codex.qml:67
piSessions: truedoes not actually pin the shared tree to this account when the stock Codex account is also configured. The custom account runs with--pi=on, but the stock account independently remains inauto, seesCODEX_HOME=~/.codex, and scans the same~/.pitree too, so every pi token is counted twice. Coordinate this setting across the Codex instances (for example, force all other instances tooffwhen one is explicitlytrue) and add a multi-instance regression case.
readonly property string piSessionsMode: {
var value = root.providerSettings ? root.providerSettings.piSessions : undefined
if (value === true) return "on"
if (value === false) return "off"
return "auto"
shell/plugins/model-usage/Main.qml:212
- The documented contract says any id starting with
claudeorcodexselects that adapter, but these checks accept only the exact name or a hyphenated suffix. For example,claude_workis silently ignored and a stock Claude instance is created instead. Match the full documented prefix, or narrow the README and PR contract to hyphen-prefixed ids.
if (key === "claude" || key.indexOf("claude-") === 0) return "claude"
if (key === "codex" || key.indexOf("codex-") === 0) return "codex"
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 11 out of 11 changed files in this pull request and generated 1 comment.
Suppressed comments (1)
shell/plugins/model-usage/Main.qml:245
expandPath()only expands~/relative prefixes; it does not canonicalize./.., trailing separators, or symlinks. Consequently, two entries such as~/.codexand~/.codex/.survive this check even though both scanners resolve to the same account. Both instances then scan the same native sessions, and because the scanner canonicalizesCODEX_HOMEfor auto pi ownership, both also claim~/.pi. Canonicalize the directory (using the same canonical value for the adapter) before indexingseenDirs.
var dir = expandPath(String(entry.configDir || defaultConfigDir(kind)))
| result.push({ | ||
| id: String(id), |
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 11 out of 11 changed files in this pull request and generated no new comments.
Suppressed comments (2)
shell/plugins/model-usage/providers/Claude.qml:82
providerConfigs()treats an emptyconfigDiras the stock directory viaentry.configDir || defaultConfigDir(kind), but this nullish fallback preserves"". The adapter then reads/stats-cache.json,/.credentials.json, and the other root-level paths instead of~/.claude. Use the same falsey fallback here so model identity and the paths actually scanned agree.
readonly property string configDir: resolvePath(String(root.providerSettings?.configDir ?? "~/.claude"))
shell/plugins/model-usage/Main.qml:246
- This does not actually detect entries that resolve to the same directory:
expandPath()only expands~/relative paths and leaves..components and symlinks intact. For example,~/.codexand~/.config/../.codexproduce two adapters that scan the same native sessions, and both resolve to the stock directory in the scanner so both also claim pi sessions. Canonicalize the directory before using it as the deduplication key (and use that same canonical path for the adapter).
var dir = expandPath(String(entry.configDir || defaultConfigDir(kind)))
if (seenDirs[dir] !== undefined) {
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 11 out of 11 changed files in this pull request and generated no new comments.
Suppressed comments (1)
shell/plugins/model-usage/Main.qml:25
- A Claude delegate created after
Main'striggeredOnStartrefresh has already fired never starts its project scanner; unlikeCodex,Claude.qmlhas no per-instance startup refresh. This occurs when live settings replace the initial/default provider model (including when custom accounts are injected after the panel loads), so the new account's project-derived totals can remain absent until the next 15-minute global refresh or a manual panel refresh. Start each enabled Claude delegate when it is created.
delegate: Claude {
required property var modelData
providerId: modelData.id
providerName: modelData.label
enabled: modelData.enabled
configDir: modelData.configDir
providerSettings: modelData.settings
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 11 out of 11 changed files in this pull request and generated no new comments.
Suppressed comments (1)
shell/plugins/model-usage/scripts/codex_usage_scanner.py:79
resolve()follows symlinks, so a secondCODEX_HOMEthat is a symlink to~/.codexalso passes this test and auto-claims the shared pi tree.Main.qmlexplicitly does not deduplicate symlink aliases, so configuring the stock path and such an alias makes pi usage appear in both accounts. Compare normalized absolute path spellings without resolving symlinks; an alternate path can still opt in viapiSessions: true.
return CODEX_HOME.resolve() == (Path.home() / ".codex").resolve()
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 11 out of 11 changed files in this pull request and generated no new comments.
Suppressed comments (2)
shell/plugins/model-usage/Main.qml:673
providerKindis added only to the display object;providerSnapshot()still omits it andaggregateSnapshots()merges solely byproviderId. Because this PR explicitly permits repurposing an id such ascodexfor a Claude account, a snapshot from another machine (or a stale snapshot) wherecodexis actually Codex will be pooled into that Claude account. Persist the kind and reject/separate snapshots whose kind does not match the local adapter before using their totals.
providerKind: provider.providerKind,
test/shell.d/model-usage-codex-scanner-test.sh:7
- This test does not invoke
rgdirectly or indirectly (the scanner uses Python and the Codex stub usesjq), so this requirement makes an otherwise runnable test fail on systems without ripgrep. Remove the unused dependency.
require_command rg
|
Heads up: #6603 just landed on The Usage collection now lives in standalone collectors in The upside: adding an agent no longer touches the panel at all. Ship a collector that prints the record contract, optionally add an If you'd like to update this PR to the new structure, rebase on — Claude Fable 5, written on behalf of @dhh |
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 9 out of 13 changed files in this pull request and generated 1 comment.
Suppressed comments (1)
shell/plugins/agents/README.md:108
- The advertised
providersconfiguration is not implemented here:configDir,label,kind, andpiSessionsare never read, so the JSON examples in the PR description create no accounts. This instead requires executablecollectors.dwrappers, which is a materially different user-facing API and also omits the described duplicate-directory handling. Please either implement the settings-based contract or align the PR description and compatibility claims with this wrapper-based design.
The shipped collectors cover the stock directories. Every further account is
a collector of its own in `~/.config/omarchy/agents/collectors.d/`: an
executable named for the account's id that points a shipped collector at the
account's directory.
| pi, omp, and opencode keep one transcript tree apiece with nothing tying | ||
| them to an account, so exactly one account may count them — by default the | ||
| one on the stock directory. If pi actually runs against another account, | ||
| claim the trees there with `--shared-sessions on`, and give the stock | ||
| account a `collectors.d/claude` override running `--shared-sessions off`, so | ||
| they still land in exactly one total. |
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 9 out of 13 changed files in this pull request and generated no new comments.
Suppressed comments (1)
shell/plugins/agents/README.md:108
- The account setup implemented here does not match the PR description: this code requires an executable
collectors.dwrapper, while the description promises thatproviders.<id>.configDir/kindentries are sufficient and thatMain.qmlinstantiates those accounts. No changed code consumes that schema, so the configuration examples in the PR will not create any accounts. Either implement the described settings contract or update the PR description and compatibility claims to document this collector-based interface.
The shipped collectors cover the stock directories. Every further account is
a collector of its own in `~/.config/omarchy/agents/collectors.d/`: an
executable named for the account's id that points a shipped collector at the
account's directory.
� Conflicts: � test/shell.d/agent-usage-claude-scanner-test.sh
Why
I run more than one AI subscription on the same machine: a work Claude account, a second work account, and a personal one. Each lives in its own config directory - that is what
CLAUDE_CONFIG_DIRis for, andCODEX_HOMEis its Codex counterpart. It is also the only mechanism that keeps two logins' credentials and transcripts apart.The agents panel only ever shows the stock directories, so whichever account lives there is the only one with numbers in the bar. The others are invisible, and the subscription switch has nothing extra to switch between.
Reworked after #6603 onto the collector/record split - this now touches no panel machinery beyond a one-line icon lookup, which is a good sign for that design.
What this adds
An account is one more collector.
omarchy-agent-usage-updatenow also runs executables from~/.config/omarchy/agents/collectors.d/, and the shipped collectors take--id/--name, so a second account is a three-line wrapper named for the id its record carries:That's the whole feature: the record lands in the usage directory under its own id, and the panel — which already keys tabs on
record.id- gains a tab with its own limits, plan line, and totals. Nothing is pooled across accounts. A user collector with a shipped collector's name replaces it, which is also how the stock account's flags can be overridden.--exceptand per-agentenabledkeep working, since the collector name and the record id are the same string.The parts that needed more than plumbing
assets/<id>.svg, soclaude-workwould fall back to the bar glyph. Records now carry"mark"- the tool behind the account - andiconCandidatesForProviderprefers it over the id. One line in the panel; every account of a tool wears that tool's mark.omarchy-agent-usage-update, the one place that sees every account:= collectors answer--print-identitywith their tool, stock-directory status (compared by path spelling, not symlink target), and their wrapper's preference, and the update run hands each one an explicit--shared-sessions on/off— appended after the wrapper's own flags, so the central decision takes precedence. An explicit claim wins and switches the stock account off with no paired override; with no claim the stock account counts the trees; with neither enabled they stay uncounted rather than landing under a subscription they may not belong to. Collectors that do not answer the identity probe are left to their own defaults, and a collector run by hand falls back toauto.omarchy-agent-usage-fireworkstakes--id/--nameas well, for a second prepaid account fed by its own credential environment.Tests
agent-usage-update-test.sh: collectors.d discovery, shipped-collector override, non-executables ignored,--excepton a user collector, and the shared-tree resolution - an explicit claim switching the stock account off, the stock account owning the trees without one, nobody counting them with neither enabled, and a partial run deciding ownership over the enabled population rather than the agents it regenerates. The pre-existing invocations also pinXDG_CONFIG_HOME, so a collectors.d on the developer's machine cannot leak into the run.agent-usage-claude-scanner-test.sh:--id/--name/mark; a second account reading its own directory while leaving the shared trees to the stock account;--shared-sessionsboth ways; per-directory limits caches answering with their own numbers (seeded caches, no network). Invocations pinCLAUDE_CONFIG_DIR, which the developer's own session may export - found the hard way, on a machine where it is.agent-usage-codex-scanner-test.sh: the same identity and shared-tree cases forCODEX_HOME.agents-accounts-test.shdrivesMain.qmlheadless: the mark flowing into the display object, aggregation refusing a mark conflict while legacy snapshots still merge, the mark-aware synced lookup, and the local snapshot recording marks. Fails without each guard.claude-workrecord withmark: "claude"resolves the Claude icon.Verified on a running desktop with three real accounts: personal (Max 5x, live limits), a second Claude account, and Codex - three chips, each with its own plan line and totals, both Claude accounts wearing the Claude mark.
Notes
Removing an account is removing its wrapper and the record it left in the usage directory; the README's new Accounts section documents the recipe, the shared-tree ownership, and that removal. Records written by older versions (no
mark) display and sync exactly as before.