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:
@@ -77,7 +77,8 @@ func (c *Chat) ClaudeAccounts(ctx context.Context, sessionID, directory, operati
|
||||
}
|
||||
email, org, plan, ok := store.Identity()
|
||||
if ok {
|
||||
list.Usage = c.switchAccount(ctx, configDir, accountKeyFor(email, org), plan)
|
||||
account := accountIdentity{key: accountKeyFor(email, org), plan: plan, email: strings.TrimSpace(email), organization: strings.TrimSpace(org)}
|
||||
list.Usage = c.switchAccount(ctx, configDir, account)
|
||||
log.Printf("claude account: %s switched to a saved account", configDir)
|
||||
}
|
||||
return list, nil
|
||||
@@ -85,15 +86,17 @@ func (c *Chat) ClaudeAccounts(ctx context.Context, sessionID, directory, operati
|
||||
return protocol.ClaudeAccountList{}, errors.New("unknown Claude account operation " + operation)
|
||||
}
|
||||
|
||||
// switchAccount records that configDir now signs in as key: its quota report
|
||||
// is marked switched (an empty one when nothing is known yet), and every open
|
||||
// session on that Claude home takes the new key and republishes its usage.
|
||||
func (c *Chat) switchAccount(ctx context.Context, configDir, key, plan string) *protocol.ChatAccountUsage {
|
||||
// switchAccount records that configDir now signs in as account: its quota
|
||||
// report is marked switched (an empty one when nothing is known yet), and
|
||||
// every open session on that Claude home takes the new account and
|
||||
// republishes its usage, which names it.
|
||||
func (c *Chat) switchAccount(ctx context.Context, configDir string, account accountIdentity) *protocol.ChatAccountUsage {
|
||||
key := account.key
|
||||
now := time.Now().UnixMilli()
|
||||
c.quotaMu.Lock()
|
||||
usage := c.quotas[key].Clone()
|
||||
if usage == nil {
|
||||
usage = &protocol.ChatAccountUsage{Harness: quotaHarness, Source: "account_switch", Plan: plan, AsOf: now}
|
||||
usage = &protocol.ChatAccountUsage{Harness: quotaHarness, Source: "account_switch", Plan: account.plan, AsOf: now}
|
||||
}
|
||||
usage.SwitchedAt = now
|
||||
if c.quotas == nil {
|
||||
@@ -116,9 +119,29 @@ func (c *Chat) switchAccount(ctx context.Context, configDir, key, plan string) *
|
||||
continue
|
||||
}
|
||||
s.mu.Lock()
|
||||
s.account = accountIdentity{key: key, plan: plan}
|
||||
s.account = account
|
||||
s.mu.Unlock()
|
||||
s.republishUsage()
|
||||
}
|
||||
return usage.Clone()
|
||||
return c.accountUsage(account)
|
||||
}
|
||||
|
||||
// accountUsage returns a copy of the latest quota for an account, naming the
|
||||
// account. With no quota known yet it names the account alone; it is nil when
|
||||
// neither is known (an API key login reports no email).
|
||||
func (c *Chat) accountUsage(account accountIdentity) *protocol.ChatAccountUsage {
|
||||
var usage *protocol.ChatAccountUsage
|
||||
if account.key != "" {
|
||||
c.quotaMu.Lock()
|
||||
usage = c.quotas[account.key].Clone()
|
||||
c.quotaMu.Unlock()
|
||||
}
|
||||
if account.email == "" {
|
||||
return usage
|
||||
}
|
||||
if usage == nil {
|
||||
usage = &protocol.ChatAccountUsage{Harness: quotaHarness, Source: "initialize", Plan: account.plan}
|
||||
}
|
||||
usage.Email, usage.Organization = account.email, account.organization
|
||||
return usage
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user