feat: add quota analysis with multi-tier support#11
feat: add quota analysis with multi-tier support#11pszymkowiak merged 1 commit intortk-ai:masterfrom
Conversation
Implements heuristic calculation of monthly quota savings percentage with support for Pro, Max 5x, and Max 20x subscription tiers. Features: - --quota flag displays monthly quota analysis - --tier <pro|5x|20x> selects subscription tier (default: 20x) - Heuristic based on ~44K tokens/5h Pro baseline - Estimates: Pro=6M, 5x=30M, 20x=120M tokens/month - Clear disclaimer about rolling 5-hour windows vs monthly caps Example output for Max 20x: Subscription tier: Max 20x ($200/mo) Estimated monthly quota: 120.0M Tokens saved (lifetime): 356.7K Quota preserved: 0.3% Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
There was a problem hiding this comment.
Pull request overview
This PR adds quota analysis functionality to the rtk gain command, allowing users to see how their token savings translate to Claude subscription quota usage across different tiers (Pro, Max 5x, Max 20x).
Changes:
- Added
--quotaflag and--tierparameter to thertk gaincommand - Implemented heuristic quota calculation using a Pro baseline of ~44K tokens/5h
- Added formatted output displaying subscription tier, estimated monthly quota, tokens saved, and quota preserved percentage
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 4 comments.
| File | Description |
|---|---|
| src/main.rs | Added quota boolean flag and tier string parameter to the Gain command enum, with tier defaulting to "20x" and requiring quota flag |
| src/gain.rs | Updated run function signature to accept quota parameters, implemented quota calculation logic with tier matching, and added formatted output section |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| if quota { | ||
| const ESTIMATED_PRO_MONTHLY: usize = 6_000_000; // ~6M tokens/month (heuristic: ~44K/5h × 6 periods/day × 30 days) | ||
|
|
||
| let (quota_tokens, tier_name) = match tier { | ||
| "pro" => (ESTIMATED_PRO_MONTHLY, "Pro ($20/mo)"), | ||
| "5x" => (ESTIMATED_PRO_MONTHLY * 5, "Max 5x ($100/mo)"), | ||
| "20x" => (ESTIMATED_PRO_MONTHLY * 20, "Max 20x ($200/mo)"), | ||
| _ => (ESTIMATED_PRO_MONTHLY, "Pro ($20/mo)"), // default fallback | ||
| }; | ||
|
|
||
| let quota_pct = (summary.total_saved as f64 / quota_tokens as f64) * 100.0; | ||
|
|
||
| println!("Monthly Quota Analysis:"); | ||
| println!("────────────────────────────────────────"); | ||
| println!("Subscription tier: {}", tier_name); | ||
| println!("Estimated monthly quota: {}", format_tokens(quota_tokens)); | ||
| println!("Tokens saved (lifetime): {}", format_tokens(summary.total_saved)); | ||
| println!("Quota preserved: {:.1}%", quota_pct); | ||
| println!(); | ||
| println!("Note: Heuristic estimate based on ~44K tokens/5h (Pro baseline)"); | ||
| println!(" Actual limits use rolling 5-hour windows, not monthly caps."); | ||
| } |
There was a problem hiding this comment.
The new quota calculation logic lacks test coverage. The repository has comprehensive test coverage (tests found in filter.rs, git.rs, grep_cmd.rs, json_cmd.rs, local_llm.rs, log_cmd.rs, ls.rs, pnpm_cmd.rs, read.rs, runner.rs, vitest_cmd.rs), but gain.rs has no tests. Consider adding unit tests to verify: 1) correct quota calculations for each tier (pro, 5x, 20x), 2) the format_tokens function works correctly with the quota values, 3) percentage calculations are accurate, and 4) edge cases like zero total_saved.
| } | ||
|
|
||
| if quota { | ||
| const ESTIMATED_PRO_MONTHLY: usize = 6_000_000; // ~6M tokens/month (heuristic: ~44K/5h × 6 periods/day × 30 days) |
There was a problem hiding this comment.
The inline comment states "~44K/5h × 6 periods/day × 30 days" but this calculation yields approximately 7.9M tokens, not 6M. Additionally, 24 hours divided by 5-hour periods equals 4.8 periods per day, not 6. The constant value of 6M appears to be based on different assumptions than what the comment describes. Consider either: 1) updating the comment to accurately reflect the calculation (e.g., "~44K/5h × 4.5 periods/day × 30 days"), or 2) clarifying that this is a conservative estimate with different assumptions.
| const ESTIMATED_PRO_MONTHLY: usize = 6_000_000; // ~6M tokens/month (heuristic: ~44K/5h × 6 periods/day × 30 days) | |
| const ESTIMATED_PRO_MONTHLY: usize = 6_000_000; // ~6M tokens/month (heuristic: ~44K/5h × 4.5 periods/day × 30 days) |
| }; | ||
|
|
||
| let quota_pct = (summary.total_saved as f64 / quota_tokens as f64) * 100.0; | ||
|
|
There was a problem hiding this comment.
The quota output should be preceded by an empty line to visually separate it from the previous section (history, graph, or command summary). Looking at lines 46, 47, and 68-69 in the same file, other sections include a blank line after them. The quota section should follow the same pattern by adding a println!(); before line 83 to maintain consistency with the existing output formatting.
| println!(); |
| #[arg(short, long)] | ||
| quota: bool, | ||
| /// Subscription tier for quota calculation: pro, 5x, 20x | ||
| #[arg(short, long, default_value = "20x", requires = "quota")] |
There was a problem hiding this comment.
The tier parameter accepts any string value but silently falls back to "pro" for invalid values (line 78). This could lead to user confusion. Consider using clap's value_parser with PossibleValue to restrict input to valid values ("pro", "5x", "20x") and provide clear error messages for invalid input. This would make the CLI more robust and user-friendly by catching errors at parse time rather than silently using a fallback.
| #[arg(short, long, default_value = "20x", requires = "quota")] | |
| #[arg( | |
| short, | |
| long, | |
| default_value = "20x", | |
| requires = "quota", | |
| value_parser = ["pro", "5x", "20x"] | |
| )] |
Updates documentation to reflect all features added in recent PRs: **Version Updates** - Update installation commands to v0.3.1 (DEB/RPM packages) **New Sections** - Add Global Flags section (-u/--ultra-compact, -v/--verbose) - Add JavaScript/TypeScript Stack section (10 new commands) **New Commands Documented** - Files: `rtk smart` (heuristic code summary) - Commands: `rtk gh` (GitHub CLI), `rtk wget`, `rtk config` - Data: `rtk gain --quota` and `--tier` flags - Containers: `rtk kubectl services` - JS/TS Stack: lint, tsc, next, prettier, vitest, playwright, prisma **Features Coverage** This update documents functionality from: - PR rtk-ai#5: Git argument parsing improvements - PR rtk-ai#6: pnpm support - PR rtk-ai#9: Modern JavaScript/TypeScript stack support - PR rtk-ai#10: GitHub CLI integration - PR rtk-ai#11: Quota analysis features - PR rtk-ai#14: Additional command improvements All commands documented are available in v0.3.1. Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
Updates documentation to reflect all features added in recent PRs: **Version Updates** - Update installation commands to v0.3.1 (DEB/RPM packages) **New Sections** - Add Global Flags section (-u/--ultra-compact, -v/--verbose) - Add JavaScript/TypeScript Stack section (10 new commands) **New Commands Documented** - Files: `rtk smart` (heuristic code summary) - Commands: `rtk gh` (GitHub CLI), `rtk wget`, `rtk config` - Data: `rtk gain --quota` and `--tier` flags - Containers: `rtk kubectl services` - JS/TS Stack: lint, tsc, next, prettier, vitest, playwright, prisma **Features Coverage** This update documents functionality from: - PR rtk-ai#5: Git argument parsing improvements - PR rtk-ai#6: pnpm support - PR rtk-ai#9: Modern JavaScript/TypeScript stack support - PR rtk-ai#10: GitHub CLI integration - PR rtk-ai#11: Quota analysis features - PR rtk-ai#14: Additional command improvements All commands documented are available in v0.3.1. Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
feat: add quota analysis with multi-tier support
Updates documentation to reflect all features added in recent PRs: **Version Updates** - Update installation commands to v0.3.1 (DEB/RPM packages) **New Sections** - Add Global Flags section (-u/--ultra-compact, -v/--verbose) - Add JavaScript/TypeScript Stack section (10 new commands) **New Commands Documented** - Files: `rtk smart` (heuristic code summary) - Commands: `rtk gh` (GitHub CLI), `rtk wget`, `rtk config` - Data: `rtk gain --quota` and `--tier` flags - Containers: `rtk kubectl services` - JS/TS Stack: lint, tsc, next, prettier, vitest, playwright, prisma **Features Coverage** This update documents functionality from: - PR rtk-ai#5: Git argument parsing improvements - PR rtk-ai#6: pnpm support - PR rtk-ai#9: Modern JavaScript/TypeScript stack support - PR rtk-ai#10: GitHub CLI integration - PR rtk-ai#11: Quota analysis features - PR rtk-ai#14: Additional command improvements All commands documented are available in v0.3.1. Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
Summary
Adds
--quotaflag tortk gaincommand to display estimated monthly quota savings across different Claude subscription tiers (Pro, Max 5x, Max 20x).This helps users understand the real-world impact of RTK's token optimizations in terms of their subscription usage.
Changes
--quotaflag tortk gaincommand--tier <pro|5x|20x>parameter for subscription tier selection (default: 20x)Example Output
Quota Estimates
Note: These are heuristic estimates for user guidance. Claude uses rolling 5-hour usage windows, not fixed monthly token quotas. Estimates based on Pro baseline of ~44K tokens/5h.
Test Plan
rtk gain --quotauses default tier (20x)rtk gain --quota --tier proshows Pro calculationsrtk gain --quota --tier 5xshows 5x calculations--graphand--historyflagsDependencies
None. Uses existing
tracking::Trackerinfrastructure.🤖 Generated with Claude Code