feat(report): add comprehensive token usage analytics and reporting (#56)#57
Merged
feat(report): add comprehensive token usage analytics and reporting (#56)#57
Conversation
Implement a new 'context-stats report' subcommand that generates comprehensive token usage analytics across all Claude Code projects. Features: - Aggregate token consumption by project, session, and subagent - Generate markdown reports with grand totals and per-project breakdowns - Support date filtering with --since-days parameter - Track input, output, cache creation, and cache read tokens separately - Display top sessions and subagent usage per project - Configurable output file path with timestamp default New modules: - analytics.py: Data loading and aggregation from ~/.claude/projects/ - cli/report.py: Report generation and markdown formatting Updates: - context_stats.py: Add report action dispatch, update CLI help text - tests: Add comprehensive unit tests for report generation Closes #56
…ng and output path
…ode, improve session_id extraction
…ing treated as session_id
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.
Closes #56
Summary
Adds a new
context-stats reportsubcommand that generates comprehensive token usage analytics across all Claude Code projects. Users can now analyze token consumption patterns with project-level, session-level, and subagent-level breakdowns.Features
--since-daysparameter to limit scopeImplementation
New modules:
src/claude_statusline/analytics.py(287 lines) — Project data discovery and aggregation~/.claude/projects/~/.claude/statusline/src/claude_statusline/cli/report.py(202 lines) — Report generation and formattingUpdates:
src/claude_statusline/cli/context_stats.py— Add report action dispatch_KNOWN_ACTIONSto include "report"_normalize_argv()to handle report as session-ID-optional actionmain()Tests:
tests/python/test_report.py— Unit tests for report generationTest Results
All 347 existing tests pass + 2 new tests:
Usage Examples
Architecture
explaincommand~/.claude/projects/→ state files → aggregation → markdownAcceptance Criteria
~/.claude/projects/with proper encoding handling--since-days