ClaudeMeter
ClaudeMeter copied to clipboard
feat(multi-account): track multiple Claude.ai accounts in parallel
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
ClaudeAccountmodel (id: UUID,label,organizationId). The label is user-facing; the id is the stable key for keychain and cache. AppSettingsdropscachedOrganizationIdin favour ofaccounts: [ClaudeAccount]. A customCodableinitialiser performs the migration: a saved blob withcached_organization_idand noaccountsis decoded into a single account labelledDefault.AppModelstores per-account fetch state inaccountStates: [UUID: AccountUsageState]and exposesrefreshUsage(accountId:),refreshAllUsage(),addAccount(label:sessionKey:),updateSessionKey(accountId:_:),renameAccount(_:label:),removeAccount(_:).CacheRepositoryandUsageServiceare now keyed by account UUID. The public~/.claudemeter/usage.jsonexport is written for the primary (first) account only, preserving compatibility with existing statusline scripts.MenuBarManagerreconciles oneNSStatusItemper 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.SetupWizardViewnow collects a label in addition to the session key.SettingsViewgains an Accounts section with add / rename / replace-session-key / remove actions.- Keychain migration: on first bootstrap after upgrade, if the legacy
defaultkeychain 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,SettingsRepositoryTestsand theTestDoublesare updated to match the new API; a new test exercises the legacy-cached_organization_idmigration 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.jsonschema (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_idset in UserDefaults anddefaultsession key in Keychain): one account namedDefaultappears, usage loads, keychaindefaultslot 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>.jsonis 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