claude: a Max 20x account reads Claude Ultra, apart from Max 5x

Anthropic renamed Max 20x to Claude Ultra, but Claude Code still says
subscriptionType "max" for both Max plans; only rateLimitTier
(default_claude_max_20x / _5x) tells them apart. Every account chip read
"Claude Max", so a 20x account looked like a 5x one (owner's report).

claudePlan names "max" with a max_20x tier "ultra". Every place a Claude
plan is written uses it (sign-in, Claude Code's own login, a saved
directory taken back, the live account, `claude auth status`), and
parseLogins reads an account saved as "max" before by its tier, so no one
signs in again. claudeRenewedHeld compared the raw "max" with the held
account's plan; it now compares the same name, or a renewed Ultra
account would no longer find the held one.

Run: TestClaudeMax20xIsUltra on mote at da52b8ab7 + this change: ok.
Broken by hand: without parseLogins' rename the saved-plan case is red;
with claudeRenewedHeld on the raw subscriptionType the held case is red.
At b855cfee9 + the same change: internal/provider ok, internal/gateway
ok, internal/gui red only in TestMainWindowCorners/macOS_26_SDK (#3949,
macOS 27, unrelated). The same three packages at this head were still
running when the owner asked to ship.
Not tried: the real app's account list; the owner's logins.json has six
20x and one 5x Max account, which these rules name Ultra and Max.
This commit is contained in:
yetone
2026-11-09 06:48:26 +08:00
parent da52b8ab73
commit 6b0b7a96e9
5 changed files with 90 additions and 7 deletions
+14 -2
View File
@@ -420,6 +420,18 @@ type claudeAuth struct {
RateLimitTier string `json:"rateLimitTier"`
}
// plan names the Claude subscription as Anthropic sells it now:
// Max 20x is Claude Ultra, while Claude Code still says "max" for it
// and tells the two apart only by the rate-limit tier.
func (a claudeAuth) plan() string { return claudePlan(a.SubscriptionType, a.RateLimitTier) }
func claudePlan(sub, tier string) string {
if sub == "max" && strings.Contains(tier, "max_20x") {
return "ultra"
}
return sub
}
// claudeCredentials keeps the whole credential blob in raw, so refreshing a
// token writes back everything else — MCP OAuth state included — untouched.
type claudeCredentials struct {
@@ -811,9 +823,9 @@ func claudeAccount() (Provider, bool) {
if signedOut {
return claudeStandInAccount()
}
plan := c.OAuth.SubscriptionType
plan := c.OAuth.plan()
if statusPlan != "" {
plan = statusPlan
plan = claudePlan(statusPlan, c.OAuth.RateLimitTier)
}
// named as its saved login is (liveLogin): it is then the account Logins
// flags Active, not served a second time beside itself, and its
+1 -1
View File
@@ -450,7 +450,7 @@ func takeClaudeDir(l *savedLogin, c claudeCredentials) (bool, error) {
}
l.Auth = b
if c.OAuth.SubscriptionType != "" {
l.Plan = c.OAuth.SubscriptionType
l.Plan = c.OAuth.plan()
}
l.Renewed = time.Now().UTC().Truncate(time.Second)
l.Lapsed, l.Refused = "", ""
+63
View File
@@ -0,0 +1,63 @@
package provider
import (
"encoding/json"
"testing"
)
// Claude Max 20x is sold as Claude Ultra now, but Claude Code still says
// "max" for both Max plans: the account chip reads its rate-limit tier, or
// a 20x account reads the same as a 5x one.
func TestClaudeMax20xIsUltra(t *testing.T) {
for _, c := range []struct{ sub, tier, want string }{
{"max", "default_claude_max_20x", "ultra"},
{"max", "default_claude_max_5x", "max"},
{"max", "", "max"},
{"pro", "default_claude_ai", "pro"},
{"team", "default_claude_max_5x", "team"},
{"ultra", "default_claude_max_20x", "ultra"},
} {
if got := claudePlan(c.sub, c.tier); got != c.want {
t.Errorf("claudePlan(%q, %q) = %q, want %q", c.sub, c.tier, got, c.want)
}
}
auth := func(tier string) []byte {
b, _ := json.Marshal(map[string]any{"claudeAiOauth": map[string]any{
"accessToken": "a", "refreshToken": "r", "subscriptionType": "max", "rateLimitTier": tier,
}})
return b
}
c, _ := parseClaudeCredentials(auth("default_claude_max_20x"))
l, err := claudeLogin(c, map[string]any{"emailAddress": "u@example.com"})
if err != nil || l.Plan != "ultra" {
t.Fatalf("a new 20x sign-in: plan %q, %v; want ultra", l.Plan, err)
}
// accounts saved before as "max" read by their tier
b, _ := json.Marshal([]savedLogin{
{Agent: "claude", User: "twenty@example.com", Plan: "max", Auth: auth("default_claude_max_20x")},
{Agent: "claude", User: "five@example.com", Plan: "max", Auth: auth("default_claude_max_5x")},
})
ls, err := parseLogins(b)
if err != nil {
t.Fatal(err)
}
got := map[string]string{}
for _, l := range ls {
got[l.User] = l.Plan
}
if got["twenty@example.com"] != "ultra" || got["five@example.com"] != "max" {
t.Fatalf("saved plans read as %v; want 20x ultra, 5x max", got)
}
// Claude Code renewing a held Ultra account's sign-in under another's
// profile still says "max": it is the same plan, so the held one is found
other := json.RawMessage(`{"emailAddress":"other@example.com"}`)
held := savedLogin{Agent: "claude", User: "twenty@example.com", Plan: "ultra", Held: true, HeldAs: claudeProfileKey(other),
Auth: auth("default_claude_max_20x"), Profile: json.RawMessage(`{"emailAddress":"twenty@example.com"}`)}
renewed := savedLogin{Agent: "claude", User: "other@example.com", Plan: "max", Auth: auth("default_claude_max_20x"), Profile: other}
if h, ok := claudeRenewedHeld([]savedLogin{held}, renewed); !ok || h.User != held.User {
t.Fatalf("a held Ultra account renewed under another profile isn't found: %v %v", h.User, ok)
}
}
+11 -3
View File
@@ -213,6 +213,14 @@ func parseLogins(b []byte) ([]savedLogin, error) {
// doesn't allow its subscription used outside its client), so one
// signed in before is left out, and gone from the file at its next write
out = slices.DeleteFunc(out, func(l savedLogin) bool { return l.Agent == "dimagent" })
for i := range out {
// a Max 20x saved before it was named Ultra
if out[i].Agent == "claude" && out[i].Plan == "max" {
if c, ok := parseClaudeCredentials(out[i].Auth); ok {
out[i].Plan = claudePlan(out[i].Plan, c.OAuth.RateLimitTier)
}
}
}
return nameAlike(dedupeLogins(out)), nil
}
@@ -754,9 +762,9 @@ func liveLogin(agent string) (savedLogin, bool) {
if signedOut {
return savedLogin{}, false
}
l := savedLogin{Agent: agent, Plan: c.OAuth.SubscriptionType, Auth: b}
l := savedLogin{Agent: agent, Plan: c.OAuth.plan(), Auth: b}
var acct map[string]any
if l.User, acct = claudeSignedInUser(l.Plan, plan, user); acct != nil {
if l.User, acct = claudeSignedInUser(c.OAuth.SubscriptionType, plan, user); acct != nil {
l.Profile, _ = json.Marshal(acct)
l.HeldAs = claudeProfileKey(l.Profile)
}
@@ -1772,7 +1780,7 @@ func claudeRenewedHeld(ls []savedLogin, l savedLogin) (savedLogin, bool) {
if h.Agent != "claude" || !h.Held || h.HeldAs != key || sameLogin(h, l) || claudeSetupToken(h.Auth) != "" {
continue
}
if plan := c.OAuth.SubscriptionType; plan != "" && h.Plan != "" && !strings.EqualFold(plan, h.Plan) {
if plan := c.OAuth.plan(); plan != "" && h.Plan != "" && !strings.EqualFold(plan, h.Plan) {
return savedLogin{}, false
}
return h, true
+1 -1
View File
@@ -833,7 +833,7 @@ func claudeLogin(c claudeCredentials, acct map[string]any) (savedLogin, error) {
return savedLogin{}, err
}
profile, _ := json.Marshal(acct)
return savedLogin{Agent: "claude", User: claudeUser(email, c.OAuth.SubscriptionType, acct), Plan: c.OAuth.SubscriptionType, Auth: auth, Profile: profile}, nil
return savedLogin{Agent: "claude", User: claudeUser(email, c.OAuth.SubscriptionType, acct), Plan: c.OAuth.plan(), Auth: auth, Profile: profile}, nil
}
func codexExchange(ctx context.Context, code, verifier, redirect string) (savedLogin, error) {