Skip to content

Track usage limits for several Claude and Codex accounts - #6516

Closed
kmpeeduwee wants to merge 1 commit into
omacom:quattrofrom
kmpeeduwee:model-usage-accounts
Closed

kmpeeduwee wants to merge 1 commit into
omacom:quattrofrom
kmpeeduwee:model-usage-accounts

Conversation

@kmpeeduwee

@kmpeeduwee kmpeeduwee commented Aug 2, 2026 •

Copy link
Copy Markdown

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_DIR is for, and CODEX_HOME is 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-update now 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:

# ~/.config/omarchy/agents/collectors.d/claude-work   (chmod +x)
#!/bin/bash
export CLAUDE_CONFIG_DIR="$HOME/.claude-work"
exec omarchy-agent-usage-claude --id claude-work --name "Work" "$@"

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. --except and per-agent enabled keep working, since the collector name and the record id are the same string.

The parts that needed more than plumbing

  • Icons. Marks resolve as assets/<id>.svg, so claude-work would fall back to the bar glyph. Records now carry "mark" - the tool behind the account - and iconCandidatesForProvider prefers it over the id. One line in the panel; every account of a tool wears that tool's mark.
  • The shared trees. pi, omp, and opencode keep one transcript tree apiece, with nothing tying them to an account - counting them for every account would count them once per account. Ownership is resolved centrally in omarchy-agent-usage-update, the one place that sees every account:= collectors answer --print-identity with 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 to auto.
  • The limits cache. The Claude collector kept one probe cache for the machine; a second account would have answered with the first one's cached limits. It is now keyed by the account's directory.
  • Sync. Snapshots carry each account's mark, and machines refuse to pool a name that runs Claude here with one that runs Codex elsewhere - the mismatched snapshot is ignored with a warning, and the per-record lookup matches on the mark too. Snapshots from before marks travelled carry none and merge as they always did.

omarchy-agent-usage-fireworks takes --id / --name as 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, --except on 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 pin XDG_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-sessions both ways; per-directory limits caches answering with their own numbers (seeded caches, no network). Invocations pin CLAUDE_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 for CODEX_HOME.
  • New agents-accounts-test.sh drives Main.qml headless: 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.
  • The bar-widget contract fixture asserts a claude-work record with mark: "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.

Copilot AI balanced review requested due to automatic review settings August 2, 2026 16:59

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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 })
@kmpeeduwee
kmpeeduwee marked this pull request as draft August 2, 2026 17:06
@kmpeeduwee
kmpeeduwee marked this pull request as ready for review August 2, 2026 17:43
Copilot AI review requested due to automatic review settings August 2, 2026 17:43

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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: true does 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 in auto, sees CODEX_HOME=~/.codex, and scans the same ~/.pi tree too, so every pi token is counted twice. Coordinate this setting across the Codex instances (for example, force all other instances to off when one is explicitly true) 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 claude or codex selects that adapter, but these checks accept only the exact name or a hyphenated suffix. For example, claude_work is 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"

@kmpeeduwee
kmpeeduwee marked this pull request as draft August 2, 2026 17:53
@kmpeeduwee
kmpeeduwee marked this pull request as ready for review August 2, 2026 18:26
Copilot AI review requested due to automatic review settings August 2, 2026 18:26

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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 ~/.codex and ~/.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 canonicalizes CODEX_HOME for auto pi ownership, both also claim ~/.pi. Canonicalize the directory (using the same canonical value for the adapter) before indexing seenDirs.
        var dir = expandPath(String(entry.configDir || defaultConfigDir(kind)))

Comment thread shell/plugins/model-usage/Main.qml Outdated
Comment on lines +252 to +253
result.push({
id: String(id),
@kmpeeduwee
kmpeeduwee marked this pull request as draft August 2, 2026 18:49
@kmpeeduwee
kmpeeduwee marked this pull request as ready for review August 2, 2026 19:00
Copilot AI review requested due to automatic review settings August 2, 2026 19:00

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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 empty configDir as the stock directory via entry.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, ~/.codex and ~/.config/../.codex produce 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) {

@kmpeeduwee
kmpeeduwee marked this pull request as draft August 2, 2026 19:11
@kmpeeduwee
kmpeeduwee marked this pull request as ready for review August 2, 2026 19:11
Copilot AI review requested due to automatic review settings August 2, 2026 19:11

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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's triggeredOnStart refresh has already fired never starts its project scanner; unlike Codex, Claude.qml has 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

Copilot AI review requested due to automatic review settings August 2, 2026 19:26

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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 second CODEX_HOME that is a symlink to ~/.codex also passes this test and auto-claims the shared pi tree. Main.qml explicitly 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 via piSessions: true.
    return CODEX_HOME.resolve() == (Path.home() / ".codex").resolve()

@kmpeeduwee
kmpeeduwee marked this pull request as draft August 2, 2026 19:36
@kmpeeduwee
kmpeeduwee marked this pull request as ready for review August 2, 2026 19:43
Copilot AI review requested due to automatic review settings August 2, 2026 19:43

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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

  • providerKind is added only to the display object; providerSnapshot() still omits it and aggregateSnapshots() merges solely by providerId. Because this PR explicitly permits repurposing an id such as codex for a Claude account, a snapshot from another machine (or a stale snapshot) where codex is 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 rg directly or indirectly (the scanner uses Python and the Codex stub uses jq), so this requirement makes an otherwise runnable test fail on systems without ripgrep. Remove the unused dependency.
require_command rg

Copilot AI review requested due to automatic review settings August 2, 2026 20:10

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 11 out of 11 changed files in this pull request and generated no new comments.

@dhh

dhh commented Aug 7, 2026

Copy link
Copy Markdown
Contributor

Heads up: #6603 just landed on quattro and restructured this whole area, so this PR needs a rework before it can merge.

The model-usage plugin is gone. It's been renamed to omarchy.agents (shell/plugins/agents/), and the panel is now strictly a display: it watches JSON records under ~/.local/state/omarchy/agents/usage/ and draws whatever appears there. All the in-plugin machinery this PR touches — providers/*.qml adapters and scripts/*_usage_scanner.py — no longer exists.

Usage collection now lives in standalone collectors in bin/. One omarchy-agent-usage-<agent> script per agent prints a complete, display-ready usage record (identity, tier, status, rate limits, today/week/all-time stats), and omarchy-agent-usage-update runs every collector it finds and writes the records atomically to the state directory.

The upside: adding an agent no longer touches the panel at all. Ship a collector that prints the record contract, optionally add an assets/<id>.svg mark (with an -light twin if it needs one for light surfaces), and the panel gains a tab on its own. See shell/plugins/agents/README.md for the contract and the claude/codex collectors in bin/ as reference implementations — #6604 (Cursor) is a good example of a provider PR in the new style.

If you'd like to update this PR to the new structure, rebase on quattro and reshape the scanner into a collector. Happy to answer questions here.

— Claude Fable 5, written on behalf of @dhh

Copilot AI review requested due to automatic review settings August 8, 2026 07:15

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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 providers configuration is not implemented here: configDir, label, kind, and piSessions are never read, so the JSON examples in the PR description create no accounts. This instead requires executable collectors.d wrappers, 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.

Comment thread shell/plugins/agents/README.md Outdated
Comment on lines +127 to +132
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.
Copilot AI review requested due to automatic review settings August 8, 2026 08:12

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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.d wrapper, while the description promises that providers.<id>.configDir/kind entries are sufficient and that Main.qml instantiates 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.

@kmpeeduwee
kmpeeduwee marked this pull request as draft August 8, 2026 08:53
@kmpeeduwee
kmpeeduwee marked this pull request as ready for review August 8, 2026 08:59
@kmpeeduwee
kmpeeduwee requested a balanced review from Copilot August 8, 2026 09:02

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 9 out of 13 changed files in this pull request and generated no new comments.

� Conflicts:
�	test/shell.d/agent-usage-claude-scanner-test.sh
Copilot AI review requested due to automatic review settings August 10, 2026 19:53

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 9 out of 13 changed files in this pull request and generated no new comments.

@kmpeeduwee kmpeeduwee closed this by deleting the head repository Sep 4, 2026
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.

3 participants