feat: add config/claude/statusline-command.sh
This commit is contained in:
parent
492362fa31
commit
b0fc627d0a
1 changed files with 64 additions and 0 deletions
64
config/claude/statusline-command.sh
Executable file
64
config/claude/statusline-command.sh
Executable file
|
|
@ -0,0 +1,64 @@
|
|||
#!/usr/bin/env bash
|
||||
# Claude Code statusline: token usage display
|
||||
# Receives JSON via stdin from Claude Code
|
||||
|
||||
input=$(cat)
|
||||
|
||||
# Model info
|
||||
model=$(echo "$input" | jq -r '.model.display_name // empty')
|
||||
|
||||
# Working directory (basename)
|
||||
cwd=$(echo "$input" | jq -r '.workspace.current_dir // .cwd // empty')
|
||||
dir=$(basename "$cwd")
|
||||
|
||||
# Context window usage
|
||||
ctx_size=$(echo "$input" | jq -r '.context_window.context_window_size // empty')
|
||||
used_pct=$(echo "$input" | jq -r '.context_window.used_percentage // empty')
|
||||
|
||||
# Compute current context tokens as ctx_size * used_pct / 100
|
||||
ctx_used=""
|
||||
if [ -n "$ctx_size" ] && [ -n "$used_pct" ]; then
|
||||
ctx_used=$(awk -v s="$ctx_size" -v p="$used_pct" 'BEGIN { printf "%d", s * p / 100 }')
|
||||
fi
|
||||
|
||||
# Output tokens from the most recent assistant turn
|
||||
output_tokens=$(echo "$input" | jq -r '.context_window.current_usage.output_tokens // empty')
|
||||
|
||||
# Format integer tokens: nk if >= 1000, otherwise raw int. Pure bash, no bc.
|
||||
fmt_k() {
|
||||
local n=$1
|
||||
if [ "$n" -ge 1000 ]; then
|
||||
printf "%dk" "$(( (n + 500) / 1000 ))"
|
||||
else
|
||||
printf "%d" "$n"
|
||||
fi
|
||||
}
|
||||
|
||||
parts=()
|
||||
|
||||
[ -n "$dir" ] && parts+=("$dir")
|
||||
[ -n "$model" ] && parts+=("$model")
|
||||
|
||||
if [ -n "$ctx_used" ] && [ -n "$ctx_size" ]; then
|
||||
parts+=("ctx:$(fmt_k "$ctx_used")/$(fmt_k "$ctx_size")")
|
||||
fi
|
||||
|
||||
if [ -n "$used_pct" ]; then
|
||||
parts+=("${used_pct}% used")
|
||||
fi
|
||||
|
||||
if [ -n "$output_tokens" ] && [ "$output_tokens" -gt 0 ]; then
|
||||
parts+=("out:$(fmt_k "$output_tokens")")
|
||||
fi
|
||||
|
||||
# Join with " | "
|
||||
result=""
|
||||
for i in "${!parts[@]}"; do
|
||||
if [ "$i" -eq 0 ]; then
|
||||
result="${parts[$i]}"
|
||||
else
|
||||
result="$result | ${parts[$i]}"
|
||||
fi
|
||||
done
|
||||
|
||||
echo "$result"
|
||||
Loading…
Add table
Add a link
Reference in a new issue