Created
March 25, 2026 11:15
-
-
Save MrModest/133626b0174938be9bb825fbc71da073 to your computer and use it in GitHub Desktop.
Status line below Claude Code CLI prompt input
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 | |
| # Claude Code status line — inspired by the af-magic oh-my-zsh theme | |
| input=$(cat) | |
| cwd=$(echo "$input" | jq -r '.workspace.current_dir // .cwd // empty') | |
| model=$(echo "$input" | jq -r '.model.display_name // empty') | |
| used=$(echo "$input" | jq -r '.context_window.used_percentage // empty') | |
| # Shorten path: replace $HOME with ~, then keep last 3 components for deep paths | |
| if [ -n "$cwd" ]; then | |
| home="$HOME" | |
| short_path="${cwd/#$home/\~}" | |
| # Count path components (split by /) | |
| depth=$(echo "$short_path" | tr -cd '/' | wc -c | tr -d ' ') | |
| if [ "$depth" -ge 4 ]; then | |
| parent=$(echo "$short_path" | rev | cut -d'/' -f1-3 | rev) | |
| first=$(echo "$short_path" | cut -d'/' -f1) | |
| short_path="${first}/…/${parent}" | |
| fi | |
| fi | |
| # Git branch + diff stats (skip optional lock) | |
| git_info="" | |
| if 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) | |
| if [ -n "$git_branch" ]; then | |
| diff_stat=$(git -C "$cwd" diff --shortstat 2>/dev/null) | |
| added=$(echo "$diff_stat" | grep -oE '[0-9]+ insertion' | grep -oE '[0-9]+') | |
| removed=$(echo "$diff_stat" | grep -oE '[0-9]+ deletion' | grep -oE '[0-9]+') | |
| diff_info="" | |
| if [ -n "$added" ] || [ -n "$removed" ]; then | |
| diff_info=" (+${added:-0} -${removed:-0})" | |
| fi | |
| git_info="git:${git_branch}${diff_info}" | |
| fi | |
| fi | |
| # LiteLLM budget (cached for 60s) | |
| litellm_info="" | |
| cache_file="/tmp/.claude-litellm-cache" | |
| cache_ttl=60 | |
| now=$(date +%s) | |
| if [ -f "$cache_file" ]; then | |
| cache_age=$(( now - $(stat -f '%m' "$cache_file" 2>/dev/null || echo 0) )) | |
| else | |
| cache_age=$((cache_ttl + 1)) | |
| fi | |
| if [ "$cache_age" -gt "$cache_ttl" ]; then | |
| litellm_json=$(dp-devinfra litellm usage -o json 2>/dev/null) | |
| if [ -n "$litellm_json" ]; then | |
| echo "$litellm_json" > "$cache_file" | |
| fi | |
| else | |
| litellm_json=$(cat "$cache_file" 2>/dev/null) | |
| fi | |
| if [ -n "$litellm_json" ]; then | |
| spend=$(echo "$litellm_json" | jq -r '.spend // empty') | |
| budget=$(echo "$litellm_json" | jq -r '.totalBudget // empty') | |
| if [ -n "$spend" ] && [ -n "$budget" ]; then | |
| litellm_info="Usage: $(printf '%.1f' "$spend")/$(printf '%.0f' "$budget")" | |
| fi | |
| fi | |
| # ANSI colors (use $'...' for real escape bytes) | |
| blue=$'\033[34m' | |
| green=$'\033[32m' | |
| cyan=$'\033[36m' | |
| yellow=$'\033[33m' | |
| red=$'\033[31m' | |
| magenta=$'\033[35m' | |
| dim=$'\033[2m' | |
| reset=$'\033[0m' | |
| # Build output parts with colors | |
| parts=() | |
| [ -n "$short_path" ] && parts+=("${blue}${short_path}${reset}") | |
| if [ -n "$git_branch" ]; then | |
| colored_git="${green}git:${git_branch}${reset}" | |
| if [ -n "$added" ] || [ -n "$removed" ]; then | |
| colored_git+=" (${green}+${added:-0}${reset} ${red}-${removed:-0}${reset})" | |
| fi | |
| parts+=("$colored_git") | |
| fi | |
| [ -n "$model" ] && parts+=("${cyan}${model}${reset}") | |
| if [ -n "$used" ]; then | |
| pct=$(printf '%.0f' "$used") | |
| if [ "$pct" -ge 80 ]; then | |
| ctx_color=$red | |
| elif [ "$pct" -ge 50 ]; then | |
| ctx_color=$yellow | |
| else | |
| ctx_color=$green | |
| fi | |
| parts+=("${ctx_color}ctx:${pct}%${reset}") | |
| fi | |
| [ -n "$litellm_info" ] && parts+=("${magenta}${litellm_info}${reset}") | |
| sep="${dim} · ${reset}" | |
| output="" | |
| for i in "${!parts[@]}"; do | |
| [ "$i" -gt 0 ] && output+="$sep" | |
| output+="${parts[$i]}" | |
| done | |
| printf '%s' "$output" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment