Skip to content

feat: per-profile Go usage tracking for multi-account setups — fixes #63#75

Merged
ltmoerdani merged 4 commits into
ltmoerdani:mainfrom
Wallacy:fix/issue-63-multi-account
Jul 12, 2026
Merged

feat: per-profile Go usage tracking for multi-account setups — fixes #63#75
ltmoerdani merged 4 commits into
ltmoerdani:mainfrom
Wallacy:fix/issue-63-multi-account

Conversation

@Wallacy

@Wallacy Wallacy commented Jul 10, 2026

Copy link
Copy Markdown
Contributor

feat: per-profile Go usage tracking for multi-account setups — fixes #63

Goal

Allow users with multiple OpenCode Go subscriptions (e.g. work + personal)
to use separate Go accounts in the same VS Code window without the usage
panel mixing their data.

Commits

  1. feat(usage): add usageProfile module and storageKeySuffix — profile
    registry, key fingerprint, rename/delete helpers, storage isolation per
    profile, migration from legacy singleton. (3 files, +270 lines)

  2. feat(usage): multi-profile wiring in extension.ts — tracker map,
    profile creation during provider resolution, fingerprint in model IDs
    to prevent key collisions, auto-switch, QuickPick with full profile
    list, SVG title with profile name. (1 file, +285 lines)

  3. feat(docs): update docs and package.json — CHANGELOG, README with
    "Multiple Go accounts" section, new commands. (3 files, +41 lines)

What was implemented

  • Profile registry. Each API key gets a "Profile 1", "Profile 2", etc.
    label. Deterministic fingerprint (first 8 + last 8 key chars). Persisted
    in globalState.
  • Isolated storage. Each profile has its own GoUsageTracker with
    namespaced keys. Legacy data is migrated into Profile 1 on first use.
  • Auto-switch. The active profile follows the last used model. Click
    the status bar to open the QuickPick — every profile is listed, active
    one is checked, others are clickable switches.
  • No SQLite in multi-key mode. The shared opencode.db is not consulted
    when 2+ profiles exist (accuracy trade-off documented in README).
  • Commands: Rename Active Profile, Delete Profile (with list + confirmation).

Testing

95/95 unit tests pass. Tested with two OpenCode Go accounts. Profile
creation, auto-switch, QuickPick switch, rename, and delete all verified.

Wallacy added 4 commits July 10, 2026 00:12
…file isolation

usageProfile.ts: profile registry, key fingerprint, rename/delete helpers.
goUsageTracker.ts: storageKeySuffix constructor param for namespaced
storage; migrateFromSingleton() to copy legacy data into first profile.
Unit tests: 20 tests.
- Replace singleton goUsageTracker with Map<fingerprint, GoUsageTracker>
- ensureProfileSync() called during provider resolution to pre-register
  profiles at startup; also called during request recording
- Model IDs now include key fingerprint so two entries with same vendor
  don't collide in apiKeysByModelId (fixes issue ltmoerdani#63)
- Active profile auto-switches to the most recently used model
- Status bar shows active profile label in multi-profile mode
- QuickPick lists all profiles with switch support
- SVG title shows active profile name
CHANGELOG.md: unreleased section for per-profile usage tracking.
README.md: 'Multiple Go accounts' section under Usage Tracking.
package.json: renameActiveProfile and deleteProfile commands.
Per-profile trackers have namespaced storage (storageKeySuffix set) and
should not read the shared opencode.db — it has no key column, so
reading it would mix quota data from all accounts, causing the 5-hour
rolling usage to accumulate across profiles instead of resetting.

Now getSummary() and setManualSpentTargets() skip SQLite when the
tracker is namespaced, falling back to in-memory tracked entries.

Reported by @taojunnan during PR ltmoerdani#75 testing.
@ltmoerdani ltmoerdani merged commit 06b5099 into ltmoerdani:main Jul 12, 2026
2 checks passed
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.

[BUG] When I have two opencode, the usage panel display error

2 participants