[PR #3832] feat: implement stats command #10774

Closed
opened 2026-02-16 18:15:31 -05:00 by yindo · 0 comments
Owner

Original Pull Request: https://github.com/anomalyco/opencode/pull/3832

State: closed
Merged: Yes


Description

Closes #1634

Implements the /stats command to aggregate token usage and costs across all sessions.

Usage

opencode stats --days 7

What it shows

  • Overview: Session count, total messages, time range
  • Costs & Tokens: Total cost, cost per day, input/output tokens, cache reads/writes
  • Tool Usage: Breakdown of which tools were used most frequently

Implementation

  • Fetches all sessions and projects
  • Processes in batches of 20 to avoid memory overhead
  • Filters by date range with --days flag (default: 7 days)
  • Works with existing storage, no schema changes needed
  • Shows warning for >100 sessions

Performance

Tested on M4 Pro, 24GB RAM:

  • 14 sessions, ~1.5k messages = ~1.3s

Unsure how it scales with 100+ or 1000+ sessions.

Feedback welcome if anyone's willing to test at scale.

Screenshots

Screenshot 2025-11-03 at 20 40 23 Screenshot 2025-11-03 at 20 40 37
**Original Pull Request:** https://github.com/anomalyco/opencode/pull/3832 **State:** closed **Merged:** Yes --- ## Description Closes #1634 Implements the `/stats` command to aggregate token usage and costs across all sessions. ## Usage ```bash opencode stats --days 7 ``` ## What it shows - **Overview**: Session count, total messages, time range - **Costs & Tokens**: Total cost, cost per day, input/output tokens, cache reads/writes - **Tool Usage**: Breakdown of which tools were used most frequently ## Implementation - Fetches all sessions and projects - Processes in batches of 20 to avoid memory overhead - Filters by date range with `--days` flag (default: 7 days) - Works with existing storage, no schema changes needed - Shows warning for >100 sessions ## Performance Tested on M4 Pro, 24GB RAM: - 14 sessions, ~1.5k messages = ~1.3s Unsure how it scales with 100+ or 1000+ sessions. Feedback welcome if anyone's willing to test at scale. ## Screenshots <img width="627" height="614" alt="Screenshot 2025-11-03 at 20 40 23" src="https://github.com/user-attachments/assets/4dbc70fd-7a65-43cc-ba5c-2d077fb15e81" /> <img width="629" height="664" alt="Screenshot 2025-11-03 at 20 40 37" src="https://github.com/user-attachments/assets/e904f20e-99e6-4229-bd84-6f28d8eb2a2b" />
yindo added the pull-request label 2026-02-16 18:15:31 -05:00
yindo closed this issue 2026-02-16 18:15:31 -05:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: anomalyco/opencode#10774