Last active
May 7, 2026 16:43
-
-
Save landon9720/b982ee58222133e3f3addcacf292b3ce to your computer and use it in GitHub Desktop.
Claude Code status line — abbreviated cwd, git worktree:branch, +adds/-dels vs main, model, effort, ctx%, 5h%
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 | |
| # Receives JSON on stdin | |
| input=$(cat) | |
| cwd=$(echo "$input" | jq -r '.workspace.current_dir // .cwd // ""') | |
| model=$(echo "$input" | jq -r '.model.display_name // ""') | |
| used_pct=$(echo "$input" | jq -r '.context_window.used_percentage // empty') | |
| five_hr=$(echo "$input" | jq -r '.rate_limits.five_hour.used_percentage // empty') | |
| effort=$(echo "$input" | jq -r '.effort.level // empty') | |
| if [ -z "$effort" ] && [ -f "$HOME/.claude/settings.json" ]; then | |
| effort=$(jq -r '.effortLevel // empty' "$HOME/.claude/settings.json" 2>/dev/null) | |
| fi | |
| abs_cwd="${cwd/#\~/$HOME}" | |
| # Abbreviate: keep root (~ or /) and last component full; squash middle dirs to 1 char (2 for dotfiles). | |
| abbrev_path() { | |
| local p=${1/#$HOME/\~} | |
| local IFS='/' | |
| local -a parts | |
| read -r -a parts <<< "$p" | |
| local last=$((${#parts[@]} - 1)) | |
| local out="" i part | |
| for i in "${!parts[@]}"; do | |
| part=${parts[$i]} | |
| if [ "$i" -eq 0 ] || [ "$i" -eq "$last" ]; then | |
| out+="$part" | |
| elif [ -n "$part" ]; then | |
| if [[ "$part" == .* ]]; then out+="${part:0:2}"; else out+="${part:0:1}"; fi | |
| fi | |
| [ "$i" -lt "$last" ] && out+="/" | |
| done | |
| printf '%s' "$out" | |
| } | |
| cwd_display=$(abbrev_path "$cwd") | |
| # Git: worktree basename + branch | |
| git_branch="" | |
| git_worktree="" | |
| pr_added="" | |
| pr_removed="" | |
| if git -C "$abs_cwd" --no-optional-locks rev-parse --is-inside-work-tree >/dev/null 2>&1; then | |
| git_branch=$(git -C "$abs_cwd" --no-optional-locks symbolic-ref --short HEAD 2>/dev/null \ | |
| || git -C "$abs_cwd" --no-optional-locks rev-parse --short HEAD 2>/dev/null) | |
| toplevel=$(git -C "$abs_cwd" --no-optional-locks rev-parse --show-toplevel 2>/dev/null) | |
| [ -n "$toplevel" ] && git_worktree=$(basename "$toplevel") | |
| # PR diff stats vs merge-base with main/master | |
| base="" | |
| for cand in main master; do | |
| if git -C "$abs_cwd" --no-optional-locks rev-parse --verify --quiet "$cand" >/dev/null 2>&1; then | |
| base="$cand"; break | |
| fi | |
| if git -C "$abs_cwd" --no-optional-locks rev-parse --verify --quiet "origin/$cand" >/dev/null 2>&1; then | |
| base="origin/$cand"; break | |
| fi | |
| done | |
| if [ -n "$base" ] && [ "$git_branch" != "$base" ] && [ "$git_branch" != "${base#origin/}" ]; then | |
| merge_base=$(git -C "$abs_cwd" --no-optional-locks merge-base "$base" HEAD 2>/dev/null) | |
| if [ -n "$merge_base" ]; then | |
| shortstat=$(git -C "$abs_cwd" --no-optional-locks diff --shortstat "$merge_base" 2>/dev/null) | |
| pr_added=$(echo "$shortstat" | grep -oE '[0-9]+ insertion' | grep -oE '[0-9]+') | |
| pr_removed=$(echo "$shortstat" | grep -oE '[0-9]+ deletion' | grep -oE '[0-9]+') | |
| fi | |
| fi | |
| fi | |
| CYAN='\033[0;36m' | |
| YELLOW='\033[0;33m' | |
| GREEN='\033[0;32m' | |
| MAGENTA='\033[0;35m' | |
| RED='\033[0;31m' | |
| DIM='\033[2m' | |
| BOLD='\033[1m' | |
| RESET='\033[0m' | |
| effort_color() { | |
| case "$1" in | |
| high) printf "%b" "$BOLD$RED" ;; | |
| medium) printf "%b" "$YELLOW" ;; | |
| low) printf "%b" "$CYAN" ;; | |
| *) printf "%b" "$DIM" ;; | |
| esac | |
| } | |
| pct_color() { | |
| local n | |
| n=$(printf '%.0f' "$1") | |
| if [ "$n" -ge 90 ]; then printf "%b" "$BOLD$RED" | |
| elif [ "$n" -ge 75 ]; then printf "%b" "$RED" | |
| elif [ "$n" -ge 50 ]; then printf "%b" "$YELLOW" | |
| elif [ "$n" -ge 25 ]; then printf "%b" "$GREEN" | |
| else printf "%b" "$CYAN" | |
| fi | |
| } | |
| parts=() | |
| parts+=("$(printf "${YELLOW}%s${RESET}" "$cwd_display")") | |
| if [ -n "$git_worktree" ] || [ -n "$git_branch" ]; then | |
| parts+=("$(printf "${CYAN}%s${DIM}:${RESET}${GREEN}%s${RESET}" "$git_worktree" "$git_branch")") | |
| fi | |
| if [ -n "$pr_added" ] || [ -n "$pr_removed" ]; then | |
| parts+=("$(printf "${GREEN}+%s${RESET}${DIM}/${RESET}${RED}-%s${RESET}" "${pr_added:-0}" "${pr_removed:-0}")") | |
| fi | |
| if [ -n "$model" ]; then | |
| parts+=("$(printf "${MAGENTA}[%s]${RESET}" "$model")") | |
| fi | |
| if [ -n "$effort" ]; then | |
| ec=$(effort_color "$effort") | |
| parts+=("$(printf "${DIM}effort:${RESET}${ec}%s${RESET}" "$effort")") | |
| fi | |
| if [ -n "$used_pct" ]; then | |
| color=$(pct_color "$used_pct") | |
| parts+=("$(printf "${DIM}ctx:${RESET}${color}%.0f%%${RESET}" "$used_pct")") | |
| fi | |
| if [ -n "$five_hr" ]; then | |
| color=$(pct_color "$five_hr") | |
| parts+=("$(printf "${DIM}5h:${RESET}${color}%.0f%%${RESET}" "$five_hr")") | |
| fi | |
| printf "%s" "${parts[*]}" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment