kensenzhao: two Claude accounts, each with its own proxy (accountProxies,
#1807). With B signed in, `magpie quota` read B's usage through A's
proxy, while a saved account's read went through its own.
The cause: magpie named the account Claude Code is signed in to from
~/.claude.json's profile. After a switch, a Claude Code started on the
account before writes that account's profile, so the sign-in was B's
while the profile still named A. liveLogin and claudeAccount then called
A the signed-in account. Logins flagged A as active, /usage ran with
ViaLogin(A), which is A's proxy, using B's credentials, and B's
reading was shown on A's card. claudeSignInOfAnother already kept this
crossing out of the saved records (netfishx), but not out of the live
name.
Now liveLogin and claudeAccount correct the profile's name by the
sign-in (claudeSignInOwner). When the profile's account doesn't hold
Claude Code's credential and exactly one other saved account does, that
one is the account signed in. claudeSignInOfAnother and the new owner
share claudeHolders. Everything that names the live account follows:
Active, /usage and its card, settings.json's proxy env, warm-up, model
test and the bridge.
Audit of the other usage readers: every per-account read goes through
loginQuota's ViaLogin(l.User), and the saved Claude read through
ViaLogin at the run. Codex names its live account from auth.json's own
tokens, so it can't cross this way. Grok's reading and Kiro's API-key
reading still use the provider's proxy (noted in 3dc8f00f0), and a
Claude Code in WSL is handed no *_PROXY. Both are left as they are.
Run: TestClaudeUsageGoesThroughTheSignedInAccountsProxy (new) fails
with the correction reverted by hand: pro is active, /usage runs
through 127.0.0.1:7897, and the reading is on pro's card. It passes with
the correction. It clears the kept readings before and after: without that,
TestRefreshSavedClaudeUsage, which runs after it, found max's reading left
over. Both pass together at -count=3. On the rebased head (on d9a050cc1):
go test -tags nogui ./internal/provider, ./internal/gateway (1178s, under
other sessions' load; an earlier run at -timeout 20m ran out mid-suite,
with nothing hung) and ./internal/cli pass. gofmt -l is clean, and GOOS=linux
and GOOS=windows go vet -tags nogui ./internal/provider pass. Rebased again
onto dbcf791e4: ./internal/provider in full, the gateway's
Claude|AccountProxy|KeyProxy tests, gofmt and both vets pass. Before the fix, the reporter's case was reproduced
with the same test, and real Claude Code 2.1.296 was checked to take the
proxy from its env and not from settings.json under --setting-sources "".
Not tried with real accounts behind real proxies.