feat: Claude subscription quota mode (toggle vs cost view)#15
Open
jsgerman-oss wants to merge 4 commits into
Open
feat: Claude subscription quota mode (toggle vs cost view)#15jsgerman-oss wants to merge 4 commits into
jsgerman-oss wants to merge 4 commits into
Conversation
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
ClaudeQuotadataclass that approximates subscription quota usage from local session/day token totals against hardcoded plan ceilings (pro/max5/max20).YAS_CLAUDE_MODE=quotareplaces the two cost rows with a single quota gauge row;cost(default) preserves the existing behaviour unchanged.YAS_CLAUDE_PLANselects the ceiling set;YAS_CLAUDE_5H_CAP_TOKENS/YAS_CLAUDE_WEEKLY_CAP_TOKENSallow per-operator tuning.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 tomaindirectly. If #14 is not yet merged, re-target this PR tofeat/codex-rate-limit-gaugeonce that branch is pushed to the upstream fork.Test plan
test/test_claude_quota.py: plan ceiling lookup, env-var override, pct math, clamping, colour thresholds, width-mode renders (wide/medium/narrow)python -m pytest test/test_claude_quota.py test/test_codex_rate_limits.py -qYAS_CLAUDE_MODE=quota YAS_CLAUDE_PLAN=max20 python3 ~/.claude/statusline_command.py < session.jsonrenders the gauge rowYAS_CLAUDE_MODE=cost(or unset) renders the existing cost rows unchanged