diff options
| author | nsfisis <nsfisis@gmail.com> | 2025-08-11 10:40:19 +0900 |
|---|---|---|
| committer | nsfisis <nsfisis@gmail.com> | 2025-08-11 10:40:19 +0900 |
| commit | 1ff07ef989625b47acfaf09a1c9d2d94ff81187c (patch) | |
| tree | 82e8b7398cb24ba0c0d7d771a43d6b7c71b100f9 | |
| parent | 7c0d5febf1eb5712789877942caca6c8734f514a (diff) | |
| download | dotfiles-1ff07ef989625b47acfaf09a1c9d2d94ff81187c.tar.gz dotfiles-1ff07ef989625b47acfaf09a1c9d2d94ff81187c.tar.zst dotfiles-1ff07ef989625b47acfaf09a1c9d2d94ff81187c.zip | |
claude: show token consumption in status line
| -rwxr-xr-x | bin/__claude-code-statusline | 13 |
1 files changed, 12 insertions, 1 deletions
diff --git a/bin/__claude-code-statusline b/bin/__claude-code-statusline index 2004db6..4e1efaa 100755 --- a/bin/__claude-code-statusline +++ b/bin/__claude-code-statusline @@ -3,7 +3,18 @@ # https://docs.anthropic.com/en/docs/claude-code/statusline input="$(cat)" +transcript_path="$(echo "$input" | jq -r '.transcript_path')" cwd="$(echo "$input" | jq -r '.cwd')" model="$(echo "$input" | jq -r '.model.display_name')" -echo "[$model] ${cwd/#$HOME/\~}" +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 ${cwd/#$HOME/\~}" |
