From 377dfb7bc4bf19fabdc5db803c566373d7a8c972 Mon Sep 17 00:00:00 2001 From: nsfisis Date: Mon, 22 Dec 2025 02:35:41 +0900 Subject: claude: refactor __claude-code-statusline to use .context_window.current_usage --- bin/__claude-code-statusline | 17 ++++++----------- 1 file changed, 6 insertions(+), 11 deletions(-) diff --git a/bin/__claude-code-statusline b/bin/__claude-code-statusline index 42fe3bc..d12d5d0 100755 --- a/bin/__claude-code-statusline +++ b/bin/__claude-code-statusline @@ -4,19 +4,14 @@ input="$(cat)" -transcript_path="$(echo "$input" | jq -r '.transcript_path')" cwd="$(echo "$input" | jq -r '.cwd')" model="$(echo "$input" | jq -r '.model.display_name')" +# Sum consumed token counts and format it like "12.3k". +consumed_tokens="$(echo "$input" | jq -r ' + (.context_window.current_usage // {}) | + (.input_tokens // 0) + (.cache_creation_input_tokens // 0) + (.cache_read_input_tokens // 0) | + [. * 10 / 1000, 0] | max | floor / 10 | " \(.)k" +')" cost="$(echo "$input" | jq -r '.cost.total_cost_usd // 0 | . * 100 | floor / 100 | " ($\(.))"')" -if [[ -n "$transcript_path" && -f "$transcript_path" ]]; then - # Sum consumed token counts and format it like "12.3k". - consumed_tokens="$(jq -s -r ' - map(.message.usage // empty) | - last | - (.input_tokens // 0) + (.output_tokens // 0) + (.cache_creation_input_tokens // 0) + (.cache_read_input_tokens // 0) | - [. * 10 / 1000, 1] | max | floor / 10 | " \(.)k" - ' < "$transcript_path")" -fi - echo "[$model]$consumed_tokens$cost ${cwd/#$HOME/\~}" -- cgit v1.2.3-70-g09d2