Created
July 29, 2026 23:17
-
-
Save claudiosanches/f3abe2d177eb3aa4bc68ca8c0ce9a67f 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 | |
| export LC_NUMERIC=C | |
| input=$(cat) | |
| MODEL=$(echo "$input" | jq -r '.model.display_name') | |
| DIR=$(echo "$input" | jq -r '.workspace.current_dir') | |
| COST=$(echo "$input" | jq -r '.cost.total_cost_usd // 0') | |
| PCT=$(echo "$input" | jq -r '.context_window.used_percentage // 0' | cut -d. -f1) | |
| DURATION_MS=$(echo "$input" | jq -r '.cost.total_duration_ms // 0') | |
| CTX_TOKENS=$(echo "$input" | jq -r '.context_window.total_input_tokens // 0') | |
| OUT_TOKENS=$(echo "$input" | jq -r '.context_window.total_output_tokens // 0') | |
| EFFORT=$(echo "$input" | jq -r '.effort.level // ""') | |
| TRANSCRIPT=$(echo "$input" | jq -r '.transcript_path // ""') | |
| RATE_LIMIT_SESSION_USAGE=$(echo "$input" | jq -r '.rate_limits.five_hour.used_percentage // 0 | round') | |
| RATE_LIMIT_WEEKLY_USAGE=$(echo "$input" | jq -r '.rate_limits.seven_day.used_percentage // 0 | round') | |
| RATE_LIMIT_SESSION_RESET_AT=$(echo "$input" | jq -r '.rate_limits.five_hour.resets_at // 0') | |
| RATE_LIMIT_WEEKLY_RESET_AT=$(echo "$input" | jq -r '.rate_limits.seven_day.resets_at // 0') | |
| REQS=0 | |
| if [ -f "$TRANSCRIPT" ]; then | |
| TRANSCRIPT_STATS=$(jq -sr ' | |
| [ | |
| .[] | |
| | select(.type == "assistant" and .requestId != null and .message.usage != null) | |
| | { id: .requestId, output_tokens: (.message.usage.output_tokens // 0) } | |
| ] | |
| | unique_by(.id) | |
| | { requests: length, output_tokens: (map(.output_tokens) | add // 0) } | |
| ' "$TRANSCRIPT" 2>/dev/null) | |
| if [ -n "$TRANSCRIPT_STATS" ]; then | |
| REQS=$(echo "$TRANSCRIPT_STATS" | jq -r '.requests // 0') | |
| OUT_TOKENS=$(echo "$TRANSCRIPT_STATS" | jq -r '.output_tokens // 0') | |
| fi | |
| fi | |
| fmt_n() { awk -v n="$1" 'BEGIN{ if (n>=1000000) printf "%.1fM",n/1000000; else if (n>=1000) printf "%.1fk",n/1000; else printf "%d",n }'; } | |
| fmt_duration() { | |
| local ms="$1" | |
| local total_seconds h m s | |
| total_seconds=$((ms / 1000)) | |
| h=$((total_seconds / 3600)) | |
| m=$(((total_seconds % 3600) / 60)) | |
| s=$((total_seconds % 60)) | |
| if [ "$h" -gt 0 ]; then | |
| printf "%dh %dm %ds" "$h" "$m" "$s" | |
| elif [ "$m" -gt 0 ]; then | |
| printf "%dm %ds" "$m" "$s" | |
| else | |
| printf "%ds" "$s" | |
| fi | |
| } | |
| fmt_reset() { | |
| local epoch="$1" | |
| [ -z "$epoch" ] || [ "$epoch" = "null" ] && return | |
| local now remaining h m | |
| now=$(date +%s) | |
| remaining=$((epoch - now)) | |
| [ $remaining -le 0 ] && echo "now" && return | |
| local d | |
| d=$((remaining / 86400)) | |
| h=$(((remaining % 86400) / 3600)) | |
| m=$(((remaining % 3600) / 60)) | |
| if [ $d -gt 0 ]; then printf "in %dd%dh" $d $h; elif [ $h -gt 0 ]; then printf "in %dh%02dm" $h $m; else printf "in %dm" $m; fi | |
| } | |
| 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)) | |
| printf -v FILL "%${FILLED}s" | |
| printf -v PAD "%${EMPTY}s" | |
| BAR="${FILL// /█}${PAD// /░}" | |
| DURATION=$(fmt_duration "$DURATION_MS") | |
| BRANCH="" | |
| git rev-parse --git-dir >/dev/null 2>&1 && BRANCH=" | $(git branch --show-current 2>/dev/null)" | |
| EFFORT_DISPLAY="" | |
| [ -n "$EFFORT" ] && EFFORT_DISPLAY=" ${EFFORT}" | |
| echo -e "${CYAN}[$MODEL${EFFORT_DISPLAY}]${RESET} ${DIR##*/}$BRANCH" | |
| COST_FMT=$(printf '$%.2f' "$COST") | |
| echo -e "${BAR_COLOR}${BAR}${RESET} ${PCT}% | ${YELLOW}${COST_FMT}${RESET} | ${DURATION} | $(fmt_n $CTX_TOKENS) $(fmt_n $OUT_TOKENS) | ${REQS}" | |
| SESSION_RESET=$(fmt_reset "$RATE_LIMIT_SESSION_RESET_AT") | |
| WEEKLY_RESET=$(fmt_reset "$RATE_LIMIT_WEEKLY_RESET_AT") | |
| echo -e " ${RATE_LIMIT_SESSION_USAGE}%${SESSION_RESET:+ $SESSION_RESET} | ${RATE_LIMIT_WEEKLY_USAGE}%${WEEKLY_RESET:+ $WEEKLY_RESET}" |
Author
~/.claude/statusline.sh
Obrigado, funcionou.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Basta criar um arquivo
statusline.shna pasta do Claude. Exemplo:~/.claude/statusline.sh.