Skip to main content

cc_token_usage/
cli.rs

1use clap::{Parser, Subcommand, ValueEnum};
2use std::path::PathBuf;
3
4#[derive(Debug, Clone, ValueEnum)]
5pub enum OutputFormat {
6    Text,
7    Html,
8    Json,
9}
10
11#[derive(Debug, Clone, ValueEnum)]
12pub enum GroupBy {
13    Day,
14    Month,
15}
16
17#[derive(Parser, Debug)]
18#[command(
19    name = "cc-token-usage",
20    version,
21    about = "Analyze Claude Code session token usage, costs, and efficiency"
22)]
23pub struct Cli {
24    /// Output format (default: both text + html)
25    #[arg(long, value_enum, global = true)]
26    pub format: Option<OutputFormat>,
27
28    /// Write output to a file instead of stdout
29    #[arg(long, global = true)]
30    pub output: Option<PathBuf>,
31
32    /// Path to Claude home directory (default: ~/.claude)
33    #[arg(long, global = true)]
34    pub claude_home: Option<PathBuf>,
35
36    /// Monthly subscription price in USD for cost calculations
37    #[arg(long, global = true)]
38    pub subscription_price: Option<f64>,
39
40    /// Path to config file
41    #[arg(long, global = true)]
42    pub config: Option<PathBuf>,
43
44    #[command(subcommand)]
45    pub command: Option<Command>,
46}
47
48#[derive(Subcommand, Debug)]
49pub enum Command {
50    /// Show overall usage overview across all projects
51    Overview,
52
53    /// Analyze token usage for a specific project
54    Project {
55        /// Project name to analyze
56        #[arg(long, allow_hyphen_values = true)]
57        name: Option<String>,
58
59        /// Show top N sessions by token usage
60        #[arg(long, default_value_t = 10)]
61        top: usize,
62    },
63
64    /// Analyze a specific session
65    Session {
66        /// Session ID to analyze
67        id: Option<String>,
68
69        /// Analyze the latest session instead of specifying an ID
70        #[arg(long)]
71        latest: bool,
72    },
73
74    /// Validate token counting accuracy against raw JSONL data
75    Validate {
76        /// Validate a specific session ID (optional, validates all if omitted)
77        id: Option<String>,
78
79        /// Show only failed checks
80        #[arg(long)]
81        failures_only: bool,
82    },
83
84    /// Check for updates and self-update the binary
85    Update {
86        /// Only check for a new version, don't download
87        #[arg(long)]
88        check: bool,
89    },
90
91    /// Show usage trends over time
92    Trend {
93        /// Number of days to include (0 = all history)
94        #[arg(long, default_value_t = 0)]
95        days: u32,
96
97        /// Group by: day or month
98        #[arg(long, value_enum, default_value_t = GroupBy::Day)]
99        group_by: GroupBy,
100    },
101
102    /// Generate a "Wrapped" annual summary of your Claude Code usage
103    Wrapped {
104        /// Year to summarize (default: current year)
105        #[arg(long)]
106        year: Option<i32>,
107    },
108
109    /// Show a GitHub-style activity heatmap in the terminal
110    Heatmap {
111        /// Number of days to show (0 = all history, default 365)
112        #[arg(long, default_value_t = 365)]
113        days: u32,
114    },
115}