#11901: feat: enhance /total_usage command with time units, model breakdown and interactive UI
docs
gateway
size: M
Cluster:
Usage Cost Enhancements
This PR significantly improves the /total_usage command: 1. Time Unit Support: Added support for flexible units like 5h (hours) and 30d (days).
2. Model Breakdown: Implemented data aggregation by model, showing token counts, cost, and session counts for each specific LLM used.
3. Interactive UI: Added a Telegram button menu for easy range selection.
4. Visual Polish: Improved dashboard-style formatting with proper column alignment using monospace fonts and cache hit analysis.
5. Core Improvements: Enhanced loadCostUsageSummary in infra to support precise startMs/endMs time ranges.
<!-- greptile_comment -->
<h2>Greptile Overview</h2>
<h3>Greptile Summary</h3>
This PR adds a new `/total_usage` chat command with an interactive Telegram button menu, time-range parsing (hours/days/all), and optional “by-model” breakdown. It also extends `loadCostUsageSummary` to aggregate usage/cost totals by model across session transcripts and returns those model aggregates in the summary payload.
The main merge blocker is in the new `/total_usage` handler: when there are no model entries in the selected window, the code still computes column widths/padding using `Math.max(...[])`, which leads to `padEnd(-Infinity)` and a runtime crash in the “no usage” case.
<h3>Confidence Score: 4/5</h3>
- Mostly safe to merge, but fix a runtime crash in /total_usage when there is no usage data in the selected range.
- Core aggregation logic in infra is straightforward and additive, but the new command handler has a deterministic crash path when `summary.models` is empty (no records) due to `Math.max(...[])` feeding into `padEnd(-Infinity)`. After that is addressed, remaining issues are minor polish.
- src/auto-reply/reply/commands-session.ts
<!-- greptile_other_comments_section -->
<!-- /greptile_comment -->
Most Similar PRs
#13215: fix: pass agentId to loadCostUsageSummary in /usage cost command
by veast · 2026-02-10
74.9%
#22701: fix(reply): make usage footer reflect full turn usage and avoid tra...
by artwalker · 2026-02-21
74.1%
#15126: fix(status): avoid false 100% context usage when totals mirror context
by AlexAnys · 2026-02-13
73.8%
#8477: TUI: persist session token totals when usage metadata is missing
by LarHope · 2026-02-04
73.3%
#13889: feat: Slack channel cache, session cost alerts & checkpoint/recover...
by trevorgordon981 · 2026-02-11
72.9%
#14488: Fix Telegram default account listing and CLI cache-write usage mapping
by abdulbb · 2026-02-12
72.3%
#9012: fix(memory): resilient flush for large sessions [AI-assisted]
by cheenu1092-oss · 2026-02-04
72.0%
#8522: feat(control-ui): Add Model Requests panel for real-time API monito...
by GiantAxeWhy · 2026-02-04
71.8%
#13841: fix: use last attempt prompt tokens for session total instead of ac...
by 1kuna · 2026-02-11
71.8%
#7913: fix: fixed gemini-cli usage not working for preview models
by RomanHotsiy · 2026-02-03
71.7%