aboutsummaryrefslogtreecommitdiffhomepage
path: root/bin/__claude-code-statusline
blob: aca81d8b537448cc071493da0153771729f27673 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
#!/usr/bin/env bash

# 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')"
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/\~}"