Skip to content

Commit 60ec2ae

Browse files
committed
fix(cli): wire /tokens and /cache as aliases for /stats; implement /stats
Dogfood found that /tokens and /cache had spec entries (resume_supported: true) but no parse arms in the command parser, resulting in: 'Unknown slash command: /tokens — Did you mean /tokens' (the suggestion engine found the spec entry but parsing always failed) Fix three things: 1. Add 'tokens' | 'cache' as aliases for 'stats' in the parse match so the commands actually resolve to SlashCommand::Stats 2. Implement SlashCommand::Stats in the REPL dispatch — previously fell through to 'Command registered but not yet implemented'. Now shows cumulative token usage for the session. 3. Implement SlashCommand::Stats in run_resume_command — previously returned 'unsupported resumed slash command'. Now emits: text: Cost / Input tokens / Output tokens / Cache create / Cache read json: {kind:stats, input_tokens, output_tokens, cache_*, total_tokens} 159 CLI tests pass, fmt clean.
1 parent 5f6f453 commit 60ec2ae

2 files changed

Lines changed: 21 additions & 3 deletions

File tree

rust/crates/commands/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1340,7 +1340,7 @@ pub fn validate_slash_command_input(
13401340
validate_no_args(command, &args)?;
13411341
SlashCommand::Upgrade
13421342
}
1343-
"stats" => {
1343+
"stats" | "tokens" | "cache" => {
13441344
validate_no_args(command, &args)?;
13451345
SlashCommand::Stats
13461346
}

rust/crates/rusty-claude-cli/src/main.rs

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2811,6 +2811,21 @@ fn run_resume_command(
28112811
message: Some(render_doctor_report()?.render()),
28122812
json: None,
28132813
}),
2814+
SlashCommand::Stats => {
2815+
let usage = UsageTracker::from_session(session).cumulative_usage();
2816+
Ok(ResumeCommandOutcome {
2817+
session: session.clone(),
2818+
message: Some(format_cost_report(usage)),
2819+
json: Some(serde_json::json!({
2820+
"kind": "stats",
2821+
"input_tokens": usage.input_tokens,
2822+
"output_tokens": usage.output_tokens,
2823+
"cache_creation_input_tokens": usage.cache_creation_input_tokens,
2824+
"cache_read_input_tokens": usage.cache_read_input_tokens,
2825+
"total_tokens": usage.total_tokens(),
2826+
})),
2827+
})
2828+
}
28142829
SlashCommand::History { count } => {
28152830
let limit = parse_history_count(count.as_deref())
28162831
.map_err(|error| -> Box<dyn std::error::Error> { error.into() })?;
@@ -2847,7 +2862,6 @@ fn run_resume_command(
28472862
| SlashCommand::Logout
28482863
| SlashCommand::Vim
28492864
| SlashCommand::Upgrade
2850-
| SlashCommand::Stats
28512865
| SlashCommand::Share
28522866
| SlashCommand::Feedback
28532867
| SlashCommand::Files
@@ -3847,11 +3861,15 @@ impl LiveCli {
38473861
self.print_prompt_history(count.as_deref());
38483862
false
38493863
}
3864+
SlashCommand::Stats => {
3865+
let usage = UsageTracker::from_session(self.runtime.session()).cumulative_usage();
3866+
println!("{}", format_cost_report(usage));
3867+
false
3868+
}
38503869
SlashCommand::Login
38513870
| SlashCommand::Logout
38523871
| SlashCommand::Vim
38533872
| SlashCommand::Upgrade
3854-
| SlashCommand::Stats
38553873
| SlashCommand::Share
38563874
| SlashCommand::Feedback
38573875
| SlashCommand::Files

0 commit comments

Comments
 (0)