Chat: show the active Claude account in the send tooltip, menu and limit banner

usage.account now carries the email and organization of the account
Claude Code is signed in to (from its initialize account, or the saved
account just switched to), sent at process start and after a switch.
The app shows it as the send tooltip's usage prefix, the Claude account
menu subtitle, the usage-limit banner's status line and the info sheet.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-11-30 16:33:46 +00:00
parent e80f18969c
commit 0dc805ae0e
22 changed files with 386 additions and 62 deletions
+15 -3
View File
@@ -87,9 +87,14 @@ func TestMergeRateLimitCarriesExtraUsage(t *testing.T) {
func TestDecodeAccountIdentity(t *testing.T) {
got := decodeAccountIdentity(json.RawMessage(`{"email":"a@example.invalid","organization":"Org","subscriptionType":"max","apiProvider":"firstParty"}`))
if got.key == "" || got.plan != "max" {
if got.key == "" || got.plan != "max" || got.email != "a@example.invalid" || got.organization != "Org" {
t.Fatalf("identity = %+v", got)
}
// An API key login names no account, so nothing is shown for it.
chat := &Chat{}
if usage := chat.accountUsage(decodeAccountIdentity(json.RawMessage(`{"apiProvider":"firstParty","apiKeySource":"ANTHROPIC_API_KEY"}`))); usage != nil {
t.Fatalf("API key usage = %+v", usage)
}
if empty := decodeAccountIdentity(json.RawMessage(`{}`)); empty.key != "" || empty.plan != "" {
t.Fatalf("empty account = %+v", empty)
}
@@ -103,10 +108,17 @@ func TestRateLimitEventReachesEverySessionOfTheAccount(t *testing.T) {
if err := chat.Prompt(context.Background(), first.ID, "hello"); err != nil {
t.Fatal(err)
}
quota := waitFrame(t, frames, "account usage", func(frame protocol.ChatEventFrame) bool {
// The process's start names the account before any quota is known.
named := waitFrame(t, frames, "account identity", func(frame protocol.ChatEventFrame) bool {
return frame.Kind == protocol.ChatEventUsage && frame.Usage != nil && frame.Usage.Account != nil
}).Usage.Account
if quota.Plan != "max" || len(quota.Windows) != 2 || quota.Windows[0].Label != "5-hour" || quota.Windows[0].UsedPercent != 42 ||
if named.Email != "fixture@example.invalid" || named.Organization != "Fixture Org" || len(named.Windows) != 0 {
t.Fatalf("account identity = %+v", named)
}
quota := waitFrame(t, frames, "account usage", func(frame protocol.ChatEventFrame) bool {
return frame.Kind == protocol.ChatEventUsage && frame.Usage != nil && frame.Usage.Account != nil && len(frame.Usage.Account.Windows) > 0
}).Usage.Account
if quota.Plan != "max" || quota.Email != "fixture@example.invalid" || len(quota.Windows) != 2 || quota.Windows[0].Label != "5-hour" || quota.Windows[0].UsedPercent != 42 ||
quota.Windows[1].Label != "Weekly" || quota.Windows[1].UsedPercent != 73.1 || quota.Windows[1].ResetsAt != 1_900_400_000_000 {
t.Fatalf("account usage = %+v", quota)
}