Skip to content

Instantly share code, notes, and snippets.

@rightson
Created March 30, 2026 23:33
Show Gist options
  • Select an option

  • Save rightson/251ff3201e7df27f14763a12cbc9a735 to your computer and use it in GitHub Desktop.

Select an option

Save rightson/251ff3201e7df27f14763a12cbc9a735 to your computer and use it in GitHub Desktop.
~/.claude/statusline.sh
#!/bin/bash
# Claude Code Status Line β€” single jq call, no loops
# Format: 🌿 <branch> | πŸ“ <folder> | <Model> [β–ˆβ–ˆβ–ˆβ–ˆβ–‘β–‘β–‘β–‘] ~XX% | πŸ“ˆ 5h XX% | 🏷 vX.X.X
# Single jq: parse all fields + build colored bar, tab-separated
IFS=$'\t' read -r MODEL CWD PCT RATE_5H VERSION BAR RL_COLOR < <(
jq -rj '
def bar:
(.context_window.used_percentage // 0 | floor) as $pct |
($pct * 20 / 100 | if . > 20 then 20 elif . < 0 then 0 else . end | floor) as $filled |
(if $pct < 20 then "\u001b[32m"
elif $pct < 40 then "\u001b[36m"
elif $pct < 60 then "\u001b[33m"
elif $pct < 80 then "\u001b[31m"
else "\u001b[35m"
end) as $color |
$color + ($filled * "β–ˆ") + "\u001b[90m" + ((20 - $filled) * "β–‘") + "\u001b[0m";
def rl_color:
(.rate_limits.five_hour.used_percentage // 0 | floor) as $r |
if $r >= 80 then "\u001b[31m"
elif $r >= 50 then "\u001b[33m"
else "\u001b[32m"
end;
[
(.model.display_name // "?"),
(.cwd // ""),
(.context_window.used_percentage // 0 | floor | tostring),
(.rate_limits.five_hour.used_percentage // 0 | floor | tostring),
(.version // "?"),
bar,
rl_color
] | join("\t") + "\n"
'
)
# Git branch (cached 5s, single file)
CACHE="/tmp/.claude-sl-cache"
NOW=${EPOCHSECONDS:-$(printf '%(%s)T' -1 2>/dev/null || date +%s)}
if [[ -f "$CACHE" ]]; then
IFS=$'\t' read -r CACHED_TIME CACHED_DIR BRANCH < "$CACHE"
if (( NOW - CACHED_TIME > 5 )) || [[ "$CACHED_DIR" != "$CWD" ]]; then
BRANCH=$(git -C "$CWD" rev-parse --abbrev-ref HEAD 2>/dev/null || echo "?")
printf '%s\t%s\t%s' "$NOW" "$CWD" "$BRANCH" > "$CACHE"
fi
else
BRANCH=$(git -C "$CWD" rev-parse --abbrev-ref HEAD 2>/dev/null || echo "?")
printf '%s\t%s\t%s' "$NOW" "$CWD" "$BRANCH" > "$CACHE"
fi
printf '🌿 %s | πŸ“ %s | %s [%b] ~%s%% | πŸ“ˆ %b5h %s%%\033[0m | 🏷 v%s\n' \
"$BRANCH" "${CWD##*/}" "$MODEL" "$BAR" "$PCT" "$RL_COLOR" "$RATE_5H" "$VERSION"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment