Created
January 26, 2026 18:38
-
-
Save chunlea/d1ab3c402a3bc901385cbe0dd695b532 to your computer and use it in GitHub Desktop.
Claude Code Status Line - Enhanced Edition
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 | |
| # Claude Code Status Line - Enhanced Edition | |
| # Optimized: single jq call, colored progress bar, compressed path | |
| # Read JSON input from stdin | |
| input=$(cat) | |
| # Extract all fields in one jq call for performance | |
| eval "$(echo "$input" | jq -r ' | |
| @sh "model_name=\(.model.display_name // "unknown")", | |
| @sh "current_dir=\(.workspace.current_dir // ".")", | |
| @sh "context_percent=\(.context_window.used_percentage // 0 | floor)", | |
| @sh "session_cost=\(.cost.total_cost_usd // 0)", | |
| @sh "duration_ms=\(.cost.total_duration_ms // 0)", | |
| @sh "output_style=\(.output_style.name // "default")" | |
| ' | tr '\n' ' ')" | |
| # Compress path: ~/workspace/vibecoding/interviewer -> ~/w/v/interviewer | |
| compress_path() { | |
| local path="$1" | |
| path="${path/#$HOME/~}" | |
| echo "$path" | awk -F'/' '{ | |
| if (NF <= 2) { print; next } | |
| result = "" | |
| for (i = 1; i < NF; i++) { | |
| if ($i == "" || $i == "~") { result = result $i "/" } | |
| else { result = result substr($i, 1, 1) "/" } | |
| } | |
| print result $NF | |
| }' | |
| } | |
| # Format duration: ms -> human readable | |
| format_duration() { | |
| local ms=$1 | |
| if [ "$ms" -ge 60000 ]; then | |
| echo "$((ms / 60000))m$((ms % 60000 / 1000))s" | |
| elif [ "$ms" -ge 1000 ]; then | |
| echo "$((ms / 1000))s" | |
| else | |
| echo "${ms}ms" | |
| fi | |
| } | |
| short_path=$(compress_path "$current_dir") | |
| duration_fmt=$(format_duration "$duration_ms") | |
| # Colors | |
| RED='\033[0;31m' | |
| GREEN='\033[0;32m' | |
| BLUE='\033[0;34m' | |
| YELLOW='\033[0;33m' | |
| CYAN='\033[0;36m' | |
| MAGENTA='\033[0;35m' | |
| GRAY='\033[0;90m' | |
| NC='\033[0m' | |
| # Build colored progress bar (15 chars wide) | |
| bar_width=15 | |
| filled=$((context_percent * bar_width / 100)) | |
| empty=$((bar_width - filled)) | |
| # Color based on usage: green < 50%, yellow 50-80%, red > 80% | |
| if [ "$context_percent" -ge 80 ]; then | |
| bar_color=$RED | |
| elif [ "$context_percent" -ge 50 ]; then | |
| bar_color=$YELLOW | |
| else | |
| bar_color=$GREEN | |
| fi | |
| bar="${bar_color}" | |
| for ((i=0; i<filled; i++)); do bar+="█"; done | |
| bar+="${GRAY}" | |
| for ((i=0; i<empty; i++)); do bar+="░"; done | |
| bar+="${NC}" | |
| # Git info | |
| cd "$current_dir" 2>/dev/null || cd / | |
| git_info="" | |
| if git rev-parse --is-inside-work-tree >/dev/null 2>&1; then | |
| branch=$(git branch --show-current 2>/dev/null || echo "detached") | |
| status_output=$(git status --porcelain 2>/dev/null) | |
| if [ -n "$status_output" ]; then | |
| total_files=$(echo "$status_output" | wc -l | xargs) | |
| line_stats=$(git diff --numstat HEAD 2>/dev/null | awk '{added+=$1; removed+=$2} END {print added+0, removed+0}') | |
| added=$(echo $line_stats | cut -d' ' -f1) | |
| removed=$(echo $line_stats | cut -d' ' -f2) | |
| git_info="${YELLOW}${branch}${NC} ${GRAY}${total_files}f${NC}" | |
| [ "$added" -gt 0 ] && git_info+=" ${GREEN}+${added}${NC}" | |
| [ "$removed" -gt 0 ] && git_info+=" ${RED}-${removed}${NC}" | |
| else | |
| git_info="${YELLOW}${branch}${NC}" | |
| fi | |
| fi | |
| # Format cost | |
| cost_info="" | |
| if [ "$(echo "$session_cost > 0" | bc -l)" = "1" ]; then | |
| cost_fmt=$(printf "%.4f" "$session_cost") | |
| cost_info="${GRAY}\$${cost_fmt}${NC}" | |
| fi | |
| # Output style (skip if default or empty) | |
| style_info="" | |
| output_style_lower=$(echo "$output_style" | tr '[:upper:]' '[:lower:]') | |
| if [ -n "$output_style" ] && [ "$output_style_lower" != "default" ] && [ "$output_style" != "null" ] && [ "$output_style" != "" ]; then | |
| style_info="${MAGENTA}${output_style}${NC}" | |
| fi | |
| # Build status line | |
| sep="${GRAY}│${NC}" | |
| output="${BLUE}${short_path}${NC} ${sep} ${CYAN}${model_name}${NC}" | |
| [ -n "$style_info" ] && output+=" ${sep} ${style_info}" | |
| output+=" ${sep} ${bar} ${context_percent}%" | |
| [ -n "$git_info" ] && output+=" ${sep} ${git_info}" | |
| output+=" ${sep} ${GRAY}${duration_fmt}${NC}" | |
| [ -n "$cost_info" ] && output+=" ${sep} ${cost_info}" | |
| echo -e "$output" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment