From 36e0309bc99bae3fd1b4663c6b6bfd915190b14e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matej=20Jane=C5=BEi=C4=8D?= Date: Fri, 17 Apr 2026 08:53:29 +0200 Subject: [PATCH] feat(claude): add statusline --- .gitignore | 1 + claude/settings.json | 8 ++++-- claude/statusline-command.sh | 52 ++++++++++++++++++++++++++++++++++++ 3 files changed, 59 insertions(+), 2 deletions(-) create mode 100644 claude/statusline-command.sh diff --git a/.gitignore b/.gitignore index 09d961b..2e5cfc4 100644 --- a/.gitignore +++ b/.gitignore @@ -122,3 +122,4 @@ mako/* claude/* !claude/CLAUDE.md !claude/settings.json +!claude/statusline-command.sh diff --git a/claude/settings.json b/claude/settings.json index b664933..276faf4 100644 --- a/claude/settings.json +++ b/claude/settings.json @@ -7,8 +7,12 @@ ] }, "hooks": {}, - "voiceEnabled": true, + "statusLine": { + "type": "command", + "command": "sh \"${CLAUDE_CONFIG_DIR:-$HOME/.claude}/statusline-command.sh\"" + }, + "effortLevel": "xhigh", "skipDangerousModePermissionPrompt": true, - "effortLevel": "high", + "voiceEnabled": true, "mcpServers": {} } diff --git a/claude/statusline-command.sh b/claude/statusline-command.sh new file mode 100644 index 0000000..e0b9b05 --- /dev/null +++ b/claude/statusline-command.sh @@ -0,0 +1,52 @@ +#!/bin/sh +input=$(cat) + +model=$(echo "$input" | jq -r '.model.display_name // empty') +total_in=$(echo "$input" | jq -r '.context_window.total_input_tokens // 0') +total_out=$(echo "$input" | jq -r '.context_window.total_output_tokens // 0') +ctx=$(echo "$input" | jq -r '.context_window.used_percentage // empty') +five_hr=$(echo "$input" | jq -r '.rate_limits.five_hour.used_percentage // empty') +five_hr_reset=$(echo "$input" | jq -r '.rate_limits.five_hour.resets_at // empty') +seven_day=$(echo "$input" | jq -r '.rate_limits.seven_day.used_percentage // empty') +seven_day_reset=$(echo "$input" | jq -r '.rate_limits.seven_day.resets_at // empty') + +# format seconds until reset as human-readable +fmt_remaining() { + now=$(date +%s) + diff=$(( $1 - now )) + [ "$diff" -le 0 ] && return + h=$(( diff / 3600 )) + m=$(( (diff % 3600) / 60 )) + if [ "$h" -gt 0 ]; then + printf '%dh%dm' "$h" "$m" + else + printf '%dm' "$m" + fi +} + +parts="" + +[ -n "$model" ] && parts="$model" + +if [ -n "$total_in" ] && [ "$total_in" != "0" ]; then + total=$((total_in + total_out)) + parts="${parts:+$parts | }tokens:${total}" +fi + +if [ -n "$ctx" ]; then + parts="${parts:+$parts | }ctx:$(printf '%.0f' "$ctx")%" +fi + +if [ -n "$five_hr" ]; then + five_hr_ttl="" + [ -n "$five_hr_reset" ] && five_hr_ttl=$(fmt_remaining "$five_hr_reset") + parts="${parts:+$parts | }5h:$(printf '%.0f' "$five_hr")%${five_hr_ttl:+($five_hr_ttl)}" +fi + +if [ -n "$seven_day" ]; then + seven_day_ttl="" + [ -n "$seven_day_reset" ] && seven_day_ttl=$(fmt_remaining "$seven_day_reset") + parts="${parts:+$parts | }7d:$(printf '%.0f' "$seven_day")%${seven_day_ttl:+($seven_day_ttl)}" +fi + +[ -n "$parts" ] && printf '%s' "$parts"