ClaudeMeter icon indicating copy to clipboard operation
ClaudeMeter copied to clipboard

feat(multi-account): track multiple Claude.ai accounts in parallel

Open jeanfw opened this issue 6 months ago • 0 comments

Summary

Replaces the single-account model with a list of ClaudeAccount entries, each with its own keychain slot, disk cache file, and NSStatusItem. Useful when you have more than one Claude plan to keep an eye on — for example a personal account and a separate client account.

What changes

  • New ClaudeAccount model (id: UUID, label, organizationId). The label is user-facing; the id is the stable key for keychain and cache.
  • AppSettings drops cachedOrganizationId in favour of accounts: [ClaudeAccount]. A custom Codable initialiser performs the migration: a saved blob with cached_organization_id and no accounts is decoded into a single account labelled Default.
  • AppModel stores per-account fetch state in accountStates: [UUID: AccountUsageState] and exposes refreshUsage(accountId:), refreshAllUsage(), addAccount(label:sessionKey:), updateSessionKey(accountId:_:), renameAccount(_:label:), removeAccount(_:).
  • CacheRepository and UsageService are now keyed by account UUID. The public ~/.claudemeter/usage.json export is written for the primary (first) account only, preserving compatibility with existing statusline scripts.
  • MenuBarManager reconciles one NSStatusItem per account (plus a setup item when no account is configured). Each status item gets its own popover scoped to that account; when more than one account exists each icon is prefixed by the account's first letter so they're distinguishable at a glance.
  • SetupWizardView now collects a label in addition to the session key. SettingsView gains an Accounts section with add / rename / replace-session-key / remove actions.
  • Keychain migration: on first bootstrap after upgrade, if the legacy default keychain slot exists and the first account's UUID slot is empty, the key is copied across and the legacy slot is deleted. Idempotent on subsequent launches.
  • Tests in AppModelTests, UsageServiceTests, SettingsRepositoryTests and the TestDoubles are updated to match the new API; a new test exercises the legacy-cached_organization_id migration path.

What stays the same

  • Refresh interval, notification thresholds, icon styles, Sonnet toggle, launch-at-login — all untouched.
  • The 5-hour / weekly / Sonnet API contract.
  • The public ~/.claudemeter/usage.json schema (only the primary account is written).

Test plan

  • [ ] Fresh install: setup wizard asks for a label + session key. App appears with one menu bar item for that account.
  • [ ] Upgrade from 1.3.0 (with cached_organization_id set in UserDefaults and default session key in Keychain): one account named Default appears, usage loads, keychain default slot is gone, the new UUID slot is populated.
  • [ ] Settings → Accounts → Add Account: enter a label + session key. A second menu bar item appears with the first letter of the new label.
  • [ ] Both menu bar items refresh independently and show correct percentages; opening one popover only shows that account's data.
  • [ ] Settings → Edit Account: rename — the menu bar accessibility label and popover header update.
  • [ ] Settings → Edit Account: paste a new session key — it validates and replaces the keychain entry without losing the account id.
  • [ ] Settings → Remove Account: the menu bar item disappears, the keychain entry is deleted, and the cache file under ~/Library/Application Support/com.claudemeter/usage_<uuid>.json is purged.
  • [ ] All accounts removed: the setup wizard menu bar item reappears.
  • [ ] Existing tests still pass after the test-double API update.

🤖 Generated with Claude Code

jeanfw avatar May 10 '26 20:05 jeanfw