feat(cli): add /usage command to display session token usage

Introduced a new command "/usage" in the CLI to show cumulative token usage for the current session. This includes details on prompt tokens, completion tokens, total tokens, API calls, and context state. Updated command documentation to reflect this addition. Enhanced the AIAgent class to track token usage throughout the session.
This commit is contained in:
teknium1 2026-03-01 00:23:19 -08:00
parent 30efc263ff
commit 177be32b7f
3 changed files with 50 additions and 0 deletions

View file

@ -535,6 +535,12 @@ class AIAgent:
)
self.compression_enabled = compression_enabled
self._user_turn_count = 0
# Cumulative token usage for the session
self.session_prompt_tokens = 0
self.session_completion_tokens = 0
self.session_total_tokens = 0
self.session_api_calls = 0
if not self.quiet_mode:
if compression_enabled:
@ -3105,6 +3111,11 @@ class AIAgent:
"total_tokens": total_tokens,
}
self.context_compressor.update_from_response(usage_dict)
self.session_prompt_tokens += prompt_tokens
self.session_completion_tokens += completion_tokens
self.session_total_tokens += total_tokens
self.session_api_calls += 1
if self.verbose_logging:
logging.debug(f"Token usage: prompt={usage_dict['prompt_tokens']:,}, completion={usage_dict['completion_tokens']:,}, total={usage_dict['total_tokens']:,}")