8000 feat(collector): detect Claude plans from the login credential for 0.10.0 by InfinityPacer · Pull Request #41 · InfinityPacer/meterleaf · GitHub
[go: up one dir, main page]

Skip to content

feat(collector): detect Claude plans from the login credential for 0.10.0 - #41

Merged
InfinityPacer merged 4 commits into
mainfrom
feat/claude-plan-detection
Oct 20, 2026
Merged

InfinityPacer merged 4 commits into
mainfrom
feat/claude-plan-detection

Conversation

@InfinityPacer
Copy link
Copy Markdown
Owner

问题

Claude Code 2.1.3xx 起不再把 organizationType 和 organizationRateLimitTier 写进 ~/.claude.json,只留下 billingType 和 seatTier(例如 team_tier_1),套餐档位只存在登录凭据里。采集器仍按旧字段识别,所以新登录的 Pro 与 Team 账户套餐为空,界面显示「账户类型未知」。

另一个隐患是,套餐从未知变成已知时,服务端会当作一次套餐变化,额度预估从识别时刻重新起算,本周期已有读数被丢掉。比如用到 20% 时才识别出套餐,预估会变差。

改动

  • 采集器经系统 security 命令读取钥匙串条目「Claude Code-credentials」(其他系统读 .credentials.json),只取 subscriptionType 和 rateLimitTier,令牌不解析、不保存、不上传。不运行 Claude Code 命令,也不发网络请求。
  • 能识别 Pro、Max 5x、Max 20x 和 Team Premium(team 加 default_claude_max_5x)。读不到凭据时,用 seatTier 识别 Team Standard 和 Team Premium,并沿用此前记录的套餐。
  • Claude Code 切换账户时先写凭据、后写 .claude.json,所以采集器只采用连续两轮都对同一账户读到的同一套餐,避免把新账户的套餐记到旧账户上。
  • 有订阅计费方式、但缺少组织类型时,账户认定为订阅账户。
  • 服务端用 planRelation 区分同一套餐的改名、细化和真实变化。只有两个不同的已知套餐才算变化。从未知补成已知,或旧标识换成新标识(旧版把 Team Premium 记为 max-5x),都只改写最后一次观测的标签,保留其时间。
  • 账户菜单新增「设置套餐」,只对 Claude 账户显示。手动套餐覆盖展示,只填补未知的套餐观测;合并账户按目标的设置补全;保存后立即刷新报表。
  • 更新 docs/collector.md(读取范围和凭据说明)、docs/reporting.md(徽标档位、手动设置、套餐变化规则),以及 CHANGELOG。版本 0.10.0,数据库结构版本未变,升级无需备份。

验证

  • bun test tests 462 通过;bun run build、所改文件 Prettier 和 git diff --check 通过。
  • 回归测试覆盖以下场景,均在旧代码上失败、修复后通过。
    • 用到 20% 后补上套餐、手动设置套餐,以及 max-5x 改名为 team-premium 时,预估前后完全一致。
    • 以未知结尾的旧历史恢复连续区间。
    • 合并账户补全手动套餐。
  • 另有测试覆盖切换账户的两种写入顺序、凭据只取套餐字段、钥匙串条目名与 Claude Code 一致。
  • 在维护者的 Mac 上实测,凭据返回 team 加 default_claude_max_5x,scan 显示 team-premium。
  • 端到端验证用了一个临时本地服务端,采集器推送真实数据后,服务端返回 team-premium 和订阅账户。Playwright 在桌面 1440 和手机 390 宽度下打开「设置套餐」,改为 Max 20x 后徽标随之变化,再恢复自动识别,没有页面报错。
  • 独立审查两轮,发现均已修复并补测试。
  • 截图含维护者真实用量,未附上。

已知限制

  • 新登录的账户约一分钟后才显示凭据里的套餐。
  • CLAUDE_CONFIG_DIR 为相对路径时,钥匙串条目名可能对不上,套餐会退回到席位档位或手动设置。
  • 桌面账户行显示「Team Premium」时,默认名「Claude Code」会省略为「Claude…」。

🤖 Generated with Claude Code

InfinityPacer and others added 4 commits October 20, 2026 17:36
Claude Code 2.1.3xx no longer writes organizationType or
organizationRateLimitTier to ~/.claude.json, so new logins reported no
plan and an unknown account kind. The collector now reads only
subscriptionType and rateLimitTier from the local login credential
(Keychain via /usr/bin/security, or .credentials.json), confirms the
logged-in account did not change during the read, and keeps the last
known plan when the credential is unavailable. seatTier identifies Team
Standard and Team Premium as a fallback.

Plan history now treats only two different known plans as a change.
Filling in an unknown plan relabels the existing observation, so the
quota estimate keeps every reading of the current cycle. Users can set a
Claude account's plan from the account menu; the setting only fills
unknown observations and bumps the ledger revision.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Older collectors recorded Team Premium as max-5x and Team or Enterprise
by their raw organization type. Plan history now compares plans through
planRelation, so renames and refinements relabel the last observation
instead of opening a boundary, and a type-only credential no longer
overrides a more specific legacy tier. Legacy histories that end in an
unknown observation resume their earlier plan or record a real change
at the current time.

The collector adopts a credential plan only after two consecutive rounds
see the same account and plan, since Claude Code writes the credential
before .claude.json when switching accounts. The keychain service suffix
hashes the raw CLAUDE_CONFIG_DIR value like Claude Code does. Manual
plans apply only to Claude accounts, also fill histories of accounts
merged into the target, and refresh the report right after saving.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…ic plans

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@InfinityPacer
InfinityPacer merged commit af9cb84 into main Oct 20, 2026
2 checks passed
@InfinityPacer
InfinityPacer deleted the feat/claude-plan-detection branch October 20, 2026 10:01
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.

1 participant

0