Skip to main content

Overview

The rtk gain command provides comprehensive analytics for tracking your token savings across time periods. View summary statistics, analyze trends with daily/weekly/monthly breakdowns, and export data for external dashboards. Database Location: ~/.local/share/rtk/history.db
Retention Policy: 90 days automatic cleanup
Scope: Global across all projects, worktrees, and Claude sessions
For programmatic access to tracking data (Rust API, CI/CD integration, custom dashboards), see Tracking Architecture.

Quick Reference

Command Options

Temporal Flags

flag
Day-by-day breakdown showing all recorded days with full metrics
flag
Week-by-week breakdown aggregated by Sunday-Saturday weeks
flag
Month-by-month breakdown aggregated by calendar month
flag
Show all time breakdowns (daily + weekly + monthly) combined

Classic Flags

flag
ASCII graph of last 30 days of savings
flag
Recent 10 commands with timestamps and savings percentages
flag
Monthly quota analysis comparing savings to subscription tier limits
string
default:"20x"
Quota tier: pro, 5x, or 20x (default: 20x)

Export Formats

string
default:"text"
Output format: text (terminal display), json (APIs), or csv (Excel/analysis)

Output Examples

Default Summary View

Metrics explained:
  • Commands: Number of rtk commands executed
  • Input: Estimated tokens from raw command output
  • Output: Actual tokens after rtk filtering
  • Saved: Input - Output (tokens prevented from reaching LLM)
  • Save%: Percentage reduction (Saved / Input) × 100
  • Time: Total execution time across all runs
  • Impact: Visual bar showing relative token savings

Daily Breakdown

Weekly Breakdown

Week definition: Sunday to Saturday (ISO week starting Sunday at 00:00)

Monthly Breakdown

Month format: YYYY-MM (calendar month)

JSON Export

Use cases:
  • API integration
  • Custom dashboards
  • Automated reporting
  • Data pipeline ingestion

CSV Export

Use cases:
  • Excel analysis
  • Python/R data science
  • Google Sheets dashboards
  • Matplotlib/seaborn plotting

Understanding Token Savings

Token Estimation

RTK estimates tokens using text.len() / 4 (4 characters per token average). Accuracy: ±10% compared to actual LLM tokenization (sufficient for trends).

Savings Calculation

Typical Savings by Command

| Command | Typical Savings | Mechanism | |---------|----------------|-----------|| | rtk git status | 77-93% | Compact stat format | | rtk vitest run | 94-99% | Show failures only | | rtk lint | 84% | Group by rule | | rtk tsc | 83% | Group by file/error code | | rtk pnpm list | 70-90% | Compact dependencies | | rtk grep | 70% | Truncate + group |

Analysis Workflows

Weekly Progress Tracking

Monthly Cost Analysis

Data Science Analysis

Excel Analysis

  1. Export CSV: rtk gain --all --format csv > rtk-data.csv
  2. Open in Excel
  3. Create pivot tables:
    • Daily trends (line chart)
    • Weekly totals (bar chart)
    • Savings % distribution (histogram)

Dashboard Creation

Database Management

Inspect Raw Data

Backup & Restore

Cleanup

Integration Examples

GitHub Actions CI/CD

Slack Bot

Troubleshooting

No data showing

Export fails

Incorrect statistics

Token estimation is a heuristic. For precise measurements:

Best Practices

  1. Regular Exports: rtk gain --all --format json > monthly-$(date +%Y%m).json
  2. Trend Analysis: Compare week-over-week savings to identify optimization opportunities
  3. Command Profiling: Use --history to see which commands save the most
  4. Backup Before Cleanup: Always backup before manual database operations
  5. CI Integration: Track savings across team in shared dashboards

See Also

Discover Command

Find missed savings opportunities by scanning Claude Code session history

Tracking Architecture

SQLite-based tracking system and programmatic access API