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
24    #[arg(long, value_enum, default_value_t = OutputFormat::Text, global = true)]
25    pub format: 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    /// Path to conversation archive directory (default: auto-detect ~/.config/superpowers/conversation-archive)
44    #[arg(long, global = true)]
45    pub archive_dir: Option<PathBuf>,
46
47    #[command(subcommand)]
48    pub command: Option<Command>,
49}
50
51#[derive(Subcommand, Debug)]
52pub enum Command {
53    /// Show overall usage overview across all projects
54    Overview,
55
56    /// Analyze token usage for a specific project
57    Project {
58        /// Project name to analyze
59        #[arg(long)]
60        name: Option<String>,
61
62        /// Show top N sessions by token usage
63        #[arg(long, default_value_t = 10)]
64        top: usize,
65    },
66
67    /// Analyze a specific session
68    Session {
69        /// Session ID to analyze
70        id: Option<String>,
71
72        /// Analyze the latest session instead of specifying an ID
73        #[arg(long)]
74        latest: bool,
75    },
76
77    /// Validate token counting accuracy against raw JSONL data
78    Validate {
79        /// Validate a specific session ID (optional, validates all if omitted)
80        id: Option<String>,
81
82        /// Show only failed checks
83        #[arg(long)]
84        failures_only: bool,
85    },
86
87    /// Show usage trends over time
88    Trend {
89        /// Number of days to include (0 = all history)
90        #[arg(long, default_value_t = 0)]
91        days: u32,
92
93        /// Group by: day or month
94        #[arg(long, value_enum, default_value_t = GroupBy::Day)]
95        group_by: GroupBy,
96    },
97}