Skip to content

feat: Claude subscription quota mode (toggle vs cost view)#15

Open
jsgerman-oss wants to merge 4 commits into
tmck-code:mainfrom
jsgerman-oss:feat/claude-quota-mode
Open

feat: Claude subscription quota mode (toggle vs cost view)#15
jsgerman-oss wants to merge 4 commits into
tmck-code:mainfrom
jsgerman-oss:feat/claude-quota-mode

Conversation

@jsgerman-oss
Copy link
Copy Markdown

Summary

  • Adds a ClaudeQuota dataclass that approximates subscription quota usage from local session/day token totals against hardcoded plan ceilings (pro / max5 / max20).
  • YAS_CLAUDE_MODE=quota replaces the two cost rows with a single quota gauge row; cost (default) preserves the existing behaviour unchanged.
  • YAS_CLAUDE_PLAN selects the ceiling set; YAS_CLAUDE_5H_CAP_TOKENS / YAS_CLAUDE_WEEKLY_CAP_TOKENS allow per-operator tuning.
  • Gauge mirrors the Codex row layout and colour thresholds (60% warn / 85% alert); uses a distinct Nerd Font icon so both rows are visually distinguishable when shown together.

Why approximation?

Anthropic does not expose live quota data through the transcript API the way Codex rollouts do. Ceilings are heuristic estimates based on the "5x / 20x of Pro" framing. Users should tune via env vars if defaults disagree with observed experience.

Dependency note

This branch builds on top of PR #14 (Codex rate-limit gauge). It is currently opened against main — if #14 merges first this PR can be re-targeted to main directly. If #14 is not yet merged, re-target this PR to feat/codex-rate-limit-gauge once that branch is pushed to the upstream fork.

Test plan

  • 27 new tests in test/test_claude_quota.py: plan ceiling lookup, env-var override, pct math, clamping, colour thresholds, width-mode renders (wide/medium/narrow)
  • All 45 quota + codex tests pass: python -m pytest test/test_claude_quota.py test/test_codex_rate_limits.py -q
  • No regressions: 471 passed / 26 failed (26 pre-existing on the base branch, unchanged)
  • YAS_CLAUDE_MODE=quota YAS_CLAUDE_PLAN=max20 python3 ~/.claude/statusline_command.py < session.json renders the gauge row
  • YAS_CLAUDE_MODE=cost (or unset) renders the existing cost rows unchanged
  • Both Claude quota and Codex gauge rows visible simultaneously

Adds a third row beneath the Claude cost rows showing Codex Pro
rate-limit window consumption (flat-rate, not dollars).

- CodexRateLimits dataclass: loads from ~/.codex/sessions rollouts,
  reverse-scans JSONL for last token_count event, overridable via
  YAS_CODEX_SESSIONS_DIR env var
- Renderer.codex_pct_colour(): green <60%, yellow 60-85%, red >=85%
- Renderer.codex_rate_row(): width-responsive —
    wide: icon  5h bar NN%  |  7d bar NN%  |  plan [stale Xh]
    medium: icon  5h NN%  ·  7d NN%
    narrow: icon  5h NN%
  Stale indicator when newest event is older than 1h.
  No-data state renders 'no codex data' in dim grey.
- Wired into build_wide() as a content row after the two Claude
  cost lines (session and day)
- 18 new unit tests covering load, empty dirs, stale detection,
  color thresholds, and all three width modes
…uota)

Add ClaudeQuota dataclass + PLAN_CEILINGS heuristics for pro/max5/max20.
Renderer gains claude_quota_row() with wide/medium/narrow width modes and
the same 60%/85% colour thresholds as the Codex gauge.

Toggle: YAS_CLAUDE_MODE=cost (default, unchanged) | quota (gauge replaces
cost rows). YAS_CLAUDE_PLAN selects the ceiling set; env-var overrides
allow per-operator tuning when the heuristic defaults disagree with reality.

27 new tests in test/test_claude_quota.py; 0 regressions (26 pre-existing
failures on feat/codex-rate-limit-gauge base unchanged).

risk: low — additive only; cost mode is the default; no schema changes
The hardcoded SOFT_LIMIT=150_000 is the auto-compact warning zone for
legacy 200K Claude models. On 1M-context Opus it caused the headline %
to exceed 100 and the bar to overflow at only ~15% real usage.

Add _effective_soft_limit(ctx) that returns max(150K, ctx_size * 0.75),
preserving the legacy 150K floor for 200K-and-below models while
letting 1M-context sessions fill the bar proportionally to actual
consumption.

Closes gridwars_run-prw.
…-bars

Follow-up to ec8be25. The same overflow bug as the primary context gauge
also affected three cost-row mini-bar fill computations in build_wide,
build_medium, and build_narrow — each used bare SOFT_LIMIT instead of
_effective_soft_limit(ctx). On 1M-context Opus the mini-bars went full-red
the moment session totals crossed 150K (~15% of actual window).

Closes gridwars_run-po4.
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