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