Last active
September 10, 2026 16:32
-
-
Save cdolek/b793ad430f8163852aa80bd8df1192e4 to your computer and use it in GitHub Desktop.
Claude Code statusline
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/bin/bash | |
| # Read JSON input from stdin | |
| input=$(cat) | |
| MODEL=$(echo "$input" | jq -r '.model.display_name') | |
| EFFORT=$(echo "$input" | jq -r '.effort.level // empty') | |
| DIR=$(echo "$input" | jq -r '.workspace.current_dir') | |
| COST=$(echo "$input" | jq -r '.cost.total_cost_usd // 0') | |
| TOTAL=$(echo "$input" | jq -r '.context_window.context_window_size // 0') | |
| DURATION_MS=$(echo "$input" | jq -r '.cost.total_duration_ms // 0') | |
| OVER_200K=$(echo "$input" | jq -r '.exceeds_200k_tokens // false') | |
| # Exact current-context token count. total_input_tokens already includes cache | |
| # reads and writes. Falls back to used_percentage on Claude Code < 2.1.132, | |
| # where these fields are cumulative session totals rather than context state. | |
| USED=$(echo "$input" | jq -r ' | |
| if (.context_window.total_input_tokens // null) != null then | |
| (.context_window.total_input_tokens + (.context_window.total_output_tokens // 0)) | |
| else | |
| ((.context_window.used_percentage // 0) * (.context_window.context_window_size // 0) / 100) | |
| end | floor') | |
| # Derive the percentage from exact tokens so it stays accurate on a 1M window, | |
| # where one percent is 10K tokens. | |
| if [ "$TOTAL" -gt 0 ]; then | |
| PCT=$(awk "BEGIN {p = int(($USED * 100 / $TOTAL) + 0.5); if (p > 100) p = 100; print p}") | |
| else | |
| PCT=0 | |
| fi | |
| # Compact token count: 310K, 1M, 1.5M | |
| fmt_tokens() { | |
| if [ "$1" -ge 1000000 ]; then | |
| awk "BEGIN {v = $1 / 1000000; if (v == int(v)) printf \"%dM\", v; else printf \"%.1fM\", v}" | |
| else | |
| echo "$(($1 / 1000))K" | |
| fi | |
| } | |
| USED_FMT=$(fmt_tokens "$USED") | |
| TOTAL_FMT=$(fmt_tokens "$TOTAL") | |
| CYAN='\033[36m'; GREEN='\033[32m'; YELLOW='\033[33m'; RED='\033[31m'; RESET='\033[0m' | |
| # Pick bar color based on context usage | |
| if [ "$PCT" -ge 90 ]; then BAR_COLOR="$RED" | |
| elif [ "$PCT" -ge 70 ]; then BAR_COLOR="$YELLOW" | |
| else BAR_COLOR="$GREEN"; fi | |
| FILLED=$((PCT / 10)); EMPTY=$((10 - FILLED)) | |
| BAR=$(printf "%${FILLED}s" | tr ' ' 'β')$(printf "%${EMPTY}s" | tr ' ' 'β') | |
| # Long-context pricing warning. Crossing 200K total tokens moves the session to | |
| # premium rates, which only exist on extended-context models. The window check | |
| # suppresses the flag on a 200K model, where output tokens can tip the total | |
| # past 200K just before auto-compaction without any pricing change. | |
| if [ "$OVER_200K" = "true" ] && [ "$TOTAL" -gt 200000 ]; then | |
| WARN_EMOJI=" π°" | |
| else | |
| WARN_EMOJI="" | |
| fi | |
| MINS=$((DURATION_MS / 60000)); SECS=$(((DURATION_MS % 60000) / 1000)) | |
| BRANCH="" | |
| REMOTE="" | |
| if [ -n "$DIR" ]; then | |
| BRANCH=$(cd "$DIR" 2>/dev/null && git -c gc.auto=0 branch --show-current 2>/dev/null) | |
| REMOTE=$(cd "$DIR" 2>/dev/null && git remote get-url origin 2>/dev/null \ | |
| | sed -e 's#git@\([^:]*\):#https://\1/#' -e 's#\.git$##') | |
| fi | |
| [ -n "$BRANCH" ] && BRANCH=" | πΏ $BRANCH" | |
| [ -n "$EFFORT" ] && MODEL="$MODEL | $EFFORT" | |
| if [ -n "$REMOTE" ]; then | |
| # Clickable link version (OSC 8): directory name links to the origin remote | |
| # Format: [MODEL] π LINKED_DIR BRANCH | |
| printf "%b[%s]%b π \e]8;;%s\a%s\e]8;;\a%s\n" \ | |
| "$CYAN" "$MODEL" "$RESET" "$REMOTE" "${DIR##*/}" "$BRANCH" | |
| else | |
| # Standard version, no remote to link to | |
| printf "%b[%s]%b π %s%s\n" "$CYAN" "$MODEL" "$RESET" "${DIR##*/}" "$BRANCH" | |
| fi | |
| COST_FMT=$(printf '$%.2f' "$COST") | |
| printf "%b%s%b %s%% (%s/%s)%s | %b%s%b | β±οΈ %sm %ss\n" \ | |
| "$BAR_COLOR" "$BAR" "$RESET" "$PCT" "$USED_FMT" "$TOTAL_FMT" "$WARN_EMOJI" \ | |
| "$YELLOW" "$COST_FMT" "$RESET" "$MINS" "$SECS" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment