From dcd99802f7208519acf9dcb3d9434f55b12e5a4a Mon Sep 17 00:00:00 2001 From: clover caruso Date: Fri, 14 Aug 2026 14:37:39 -0700 Subject: [PATCH] clover: claude code status line --- users/clover/home.nix | 6 ++ users/clover/scripts/claude-statusline.sh | 78 +++++++++++++++++++++++ 2 files changed, 84 insertions(+) create mode 100755 users/clover/scripts/claude-statusline.sh diff --git a/users/clover/home.nix b/users/clover/home.nix index bd54ff6e799c1611b646495fdd23239ad530f6a0..6d1a0c19e208909290d12007804cada33b38b030 100644 --- a/users/clover/home.nix +++ b/users/clover/home.nix @@ -8,6 +8,7 @@ let hostServer = false; agentsFile = "${config.home.homeDirectory}/config/users/clover/AGENTS.md"; simpleBrowserBridge = "${config.home.homeDirectory}/config/files/vscode-simple-browser-bridge"; + claudeStatusline = "${config.home.homeDirectory}/config/users/clover/scripts/claude-statusline.sh"; in { home = { @@ -51,6 +52,11 @@ in # of opencode's global AGENTS.md); point it at the same file. home.file.".claude/CLAUDE.md".source = config.lib.file.mkOutOfStoreSymlink agentsFile; + # Referenced by the `statusLine.command` entry in ~/.claude/settings.json, + # which claude code rewrites itself and so stays unmanaged. + home.file.".claude/statusline-command.sh".source = + config.lib.file.mkOutOfStoreSymlink claudeStatusline; + # Companion extension for the `open-in-vscode-browser` shim. Symlinked # (rather than copied) so edits to the source are live after a window reload. # macOS-only: the shim targets /usr/bin/open. diff --git a/users/clover/scripts/claude-statusline.sh b/users/clover/scripts/claude-statusline.sh new file mode 100755 index 0000000000000000000000000000000000000000..d7ff928c52aead2b132be711b0a4875170806455 --- /dev/null +++ b/users/clover/scripts/claude-statusline.sh @@ -0,0 +1,78 @@ +#!/bin/bash +# Four segments: model, thinking/effort, context used %, rate-limit remaining. +# Meters ramp cool -> hot (blue, cyan, green, yellow, red) as each stat grows big. +input=$(cat) + +sep_color=240 +model_color=176 +thinking_color=108 + +color_for_pct() { + local pct="${1%.*}" + if (( pct >= 85 )); then echo 203 + elif (( pct >= 70 )); then echo 214 + elif (( pct >= 50 )); then echo 114 + elif (( pct >= 25 )); then echo 80 + else echo 111 + fi +} + +humanize() { + local n=$1 + if (( n >= 1000000 )); then + printf '%s' "$(awk -v n="$n" 'BEGIN{printf "%.1fM", n/1000000}' | sed 's/\.0M/M/')" + elif (( n >= 1000 )); then + printf '%dk' $(( n / 1000 )) + else + printf '%d' "$n" + fi +} + +model=$(printf '%s' "$input" | jq -r '.model.display_name // ""') +model_short=$(grep -oE 'Opus|Sonnet|Haiku' <<<"$model" | head -1) +[[ -z "$model_short" ]] && model_short="$model" + +effort=$(printf '%s' "$input" | jq -r '.effort.level // ""') +if [[ -n "$effort" ]]; then + thinking="$(tr '[:lower:]' '[:upper:]' <<<"${effort:0:1}")${effort:1}" +elif [[ "$(printf '%s' "$input" | jq -r '.thinking.enabled // false')" == "true" ]]; then + thinking="On" +else + thinking="Off" +fi + +segments=("$(printf "\033[38;5;%sm%s\033[0m" "$model_color" "$model_short")" "$(printf "\033[38;5;%sm%s\033[0m" "$thinking_color" "$thinking")") + +ctx_pct=$(printf '%s' "$input" | jq -r '.context_window.used_percentage // empty') +if [[ -n "$ctx_pct" ]]; then + read -r ctx_used ctx_size < <(printf '%s' "$input" | jq -r '.context_window | "\(.total_input_tokens // 0) \(.context_window_size // 0)"') + c=$(color_for_pct "$ctx_pct") + if (( ctx_size > 0 )); then + segments+=("$(printf "\033[38;5;%sm%.0f%% ctx (%s/%s)\033[0m" "$c" "$ctx_pct" "$(humanize "$ctx_used")" "$(humanize "$ctx_size")")") + else + segments+=("$(printf "\033[38;5;%sm%.0f%% ctx\033[0m" "$c" "$ctx_pct")") + fi +fi + +five=$(printf '%s' "$input" | jq -r '.rate_limits.five_hour.used_percentage // empty') +week=$(printf '%s' "$input" | jq -r '.rate_limits.seven_day.used_percentage // empty') +if [[ -n "$five" || -n "$week" ]]; then + limits="" + if [[ -n "$five" ]]; then + c=$(color_for_pct "$five") + limits+=$(printf "\033[38;5;%sm%.0f%% 5h\033[0m" "$c" "$(( 100 - ${five%.*} ))") + fi + if [[ -n "$week" ]]; then + [[ -n "$limits" ]] && limits+=$(printf " \033[38;5;%sm/\033[0m " "$sep_color") + c=$(color_for_pct "$week") + limits+=$(printf "\033[38;5;%sm%.0f%% 7d\033[0m" "$c" "$(( 100 - ${week%.*} ))") + fi + segments+=("$limits") +fi + +sep=$(printf " \033[38;5;%smĀ·\033[0m " "$sep_color") +line="${segments[0]}" +for ((i = 1; i < ${#segments[@]}; i++)); do + line+="${sep}${segments[i]}" +done +printf '%s\n' "$line" -- 2.54.0