Created
April 13, 2026 05:13
-
-
Save AndyButland/9bde1919095491bcab03563cadeebc33 to your computer and use it in GitHub Desktop.
Status line for Claude Code
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
| #!/usr/bin/env bash | |
| input=$(cat) | |
| # Parse JSON with grep/sed since jq may not be available | |
| extract() { | |
| echo "$input" | grep -o "\"$1\":[^,}]*" | head -1 | sed 's/^"[^"]*"://; s/^[ ]*//; s/"//g; s/[ ]*$//' | |
| } | |
| cwd=$(extract "current_dir") | |
| model=$(extract "display_name") | |
| # Extract context usage (key unique to context_window section) | |
| ctx_used=$(extract "used_percentage") | |
| # Extract rate limit: look for "five_hour" then grab the used_percentage near it | |
| # Use awk to find the five_hour block and extract its used_percentage | |
| rate_used=$(echo "$input" | tr -d '\n' | grep -o '"five_hour":[^}]*}' | grep -o '"used_percentage":[^,}]*' | head -1 | sed 's/^"[^"]*"://; s/^[ ]*//; s/"//g; s/[ ]*$//') | |
| # Normalize path: collapse double backslashes to single backslashes, forward slashes to backslashes | |
| cwd=$(echo "$cwd" | sed 's#\\\\#\\#g; s#/#\\#g') | |
| # Shorten the working directory: replace $HOME with ~ | |
| if [ -n "$cwd" ]; then | |
| home="$HOME" | |
| short_cwd="${cwd/#$home/\~}" | |
| else | |
| short_cwd="" | |
| fi | |
| # Escape backslashes for printf %b (prevents \r, \n etc. being interpreted) | |
| short_cwd="${short_cwd//\\/\\\\}" | |
| # Get git branch | |
| git_branch="" | |
| if [ -n "$cwd" ] && git -C "$cwd" rev-parse --git-dir > /dev/null 2>&1; then | |
| git_branch=$(git -C "$cwd" symbolic-ref --short HEAD 2>/dev/null || git -C "$cwd" rev-parse --short HEAD 2>/dev/null) | |
| fi | |
| # Get repo version from version.json at the git root | |
| repo_version="" | |
| if [ -n "$cwd" ]; then | |
| git_root=$(git -C "$cwd" rev-parse --show-toplevel 2>/dev/null) | |
| if [ -n "$git_root" ] && [ -f "$git_root/version.json" ]; then | |
| repo_version=$(grep -o '"version":[^,}]*' "$git_root/version.json" | head -1 | sed 's/^"[^"]*"://; s/^[ ]*//; s/"//g; s/[ ]*$//') | |
| fi | |
| fi | |
| # ANSI colors | |
| cyan="\033[36m" | |
| purple="\033[35m" | |
| yellow="\033[33m" | |
| reset="\033[0m" | |
| # Context color: green(0%) -> yellow -> orange -> red(100%) in 10% steps | |
| ctx_color() { | |
| local pct=$(printf '%.0f' "$1") | |
| if [ "$pct" -le 10 ]; then echo "\033[38;5;29m" # muted green | |
| elif [ "$pct" -le 20 ]; then echo "\033[38;5;65m" # green-olive | |
| elif [ "$pct" -le 30 ]; then echo "\033[38;5;101m" # olive | |
| elif [ "$pct" -le 40 ]; then echo "\033[38;5;137m" # olive-yellow | |
| elif [ "$pct" -le 50 ]; then echo "\033[38;5;143m" # muted yellow | |
| elif [ "$pct" -le 60 ]; then echo "\033[38;5;179m" # dark yellow | |
| elif [ "$pct" -le 70 ]; then echo "\033[38;5;173m" # muted orange | |
| elif [ "$pct" -le 80 ]; then echo "\033[38;5;167m" # dark orange | |
| elif [ "$pct" -le 90 ]; then echo "\033[38;5;131m" # muted red-orange | |
| else echo "\033[38;5;124m" # dark red | |
| fi | |
| } | |
| # Build directory display | |
| dir_display="${cyan}${short_cwd}${reset}" | |
| # Build git display | |
| git_display="" | |
| if [ -n "$git_branch" ]; then | |
| git_display=" | ${purple}${git_branch}${reset}" | |
| fi | |
| # Build version display | |
| version_display="" | |
| if [ -n "$repo_version" ]; then | |
| version_display=" | ${yellow}v${repo_version}${reset}" | |
| fi | |
| # Build model + stats display: "Opus 4.6 - context: X%, rate limit: Y%" | |
| model_display="" | |
| if [ -n "$model" ] && [ "$model" != "null" ]; then | |
| model_short=$(echo "$model" | sed 's/ *([^)]*)//g') | |
| stats="" | |
| if [ -n "$ctx_used" ] && [ "$ctx_used" != "null" ]; then | |
| cc=$(ctx_color "$ctx_used") | |
| stats="context: ${cc}$(printf '%.0f' "$ctx_used")%${reset}" | |
| fi | |
| if [ -n "$rate_used" ] && [ "$rate_used" != "null" ]; then | |
| rc=$(ctx_color "$rate_used") | |
| [ -n "$stats" ] && stats="${stats}, " | |
| stats="${stats}rate limit: ${rc}$(printf '%.0f' "$rate_used")%${reset}" | |
| fi | |
| if [ -n "$stats" ]; then | |
| model_display=" | ${model_short} - ${stats}" | |
| else | |
| model_display=" | ${model_short}" | |
| fi | |
| fi | |
| printf "%b" "${dir_display}${git_display}${version_display}${model_display}" |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Renders as:
To use, save into the
.claudefolder and add tosettings.json:{ "statusLine": { "type": "command", "command": "bash /{path-to-local-claude-folder}/.claude/statusline-command.sh" } }