#!/bin/bash # Status line for Claude Code # Format: repo-name branch-name [git-stats] context-usage% # Read JSON input input=$(cat) current_dir=$(echo "$input" | jq -r '.workspace.current_dir') # Get repository name (if in a git repo) if git -C "$current_dir" rev-parse --git-dir >/dev/null 2>&1; then # Get the remote URL and extract repo name, or fallback to directory name repo_name=$(git -C "$current_dir" config --get remote.origin.url 2>/dev/null | sed -n 's#.*/\([^.]*\)\.git#\1#p') # Fallback to directory name if no remote if [[ -z "$repo_name" ]]; then repo_name=$(basename "$(git -C "$current_dir" rev-parse --show-toplevel 2>/dev/null)") fi # Get branch name branch=$(git -C "$current_dir" symbolic-ref --short HEAD 2>/dev/null || git -C "$current_dir" rev-parse --short HEAD 2>/dev/null) # Repository name in vibrant cyan (bold) printf "\033[1;36m%s\033[0m" "$repo_name" # Branch name in soft purple/magenta printf " \033[35m%s\033[0m" "$branch" # Git stats section git_stats="" # Commits ahead/behind (skip optional locks for performance) upstream=$(git -C "$current_dir" rev-parse --abbrev-ref @{upstream} 2>/dev/null) if [[ -n "$upstream" ]]; then ahead=$(git -C "$current_dir" rev-list --count @{upstream}..HEAD 2>/dev/null) behind=$(git -C "$current_dir" rev-list --count HEAD..@{upstream} 2>/dev/null) if [[ "$ahead" -gt 0 ]]; then git_stats+=" \033[33m↑$ahead\033[0m" # Yellow for unpushed commits fi if [[ "$behind" -gt 0 ]]; then git_stats+=" \033[36m↓$behind\033[0m" # Cyan for unpulled commits fi fi # Uncommitted changes stats (staged + unstaged) modified_files=$(git -C "$current_dir" diff HEAD --name-only 2>/dev/null | wc -l | tr -d ' ') if [[ "$modified_files" -gt 0 ]]; then # Get line stats (staged + unstaged) stats=$(git -C "$current_dir" diff HEAD --numstat 2>/dev/null | awk '{added+=$1; deleted+=$2} END {print added, deleted}') added=$(echo "$stats" | cut -d' ' -f1) deleted=$(echo "$stats" | cut -d' ' -f2) # Show modified files count in white git_stats+=" \033[37m$modified_files\033[0m" # Show additions in green if > 0 if [[ -n "$added" && "$added" -gt 0 ]]; then git_stats+=" \033[32m+$added\033[0m" fi # Show deletions in red if > 0 if [[ -n "$deleted" && "$deleted" -gt 0 ]]; then git_stats+=" \033[31m-$deleted\033[0m" fi fi # Print git stats if any if [[ -n "$git_stats" ]]; then printf "%b" "$git_stats" fi fi # Model and context info model=$(echo "$input" | jq -r '.model.display_name // .model.id // "Claude"') size=$(echo "$input" | jq -r '.context_window.context_window_size // 200000') usage=$(echo "$input" | jq '.context_window.current_usage') if [[ "$usage" != "null" && "$size" != "null" && "$size" -gt 0 ]] 2>/dev/null; then input_tokens=$(echo "$usage" | jq -r '.input_tokens // 0') cache_creation=$(echo "$usage" | jq -r '.cache_creation_input_tokens // 0') cache_read=$(echo "$usage" | jq -r '.cache_read_input_tokens // 0') # Total context = all tokens in the context window current=$((input_tokens + cache_creation + cache_read)) pct=$((current * 100 / size)) # Format as Xk (e.g., 49k, 200k) current_k=$((current / 1000)) size_k=$((size / 1000)) # Model name in dim white printf " \033[38;5;245m%s\033[0m" "$model" # Color-coded tokens: green (<50%), yellow (50-80%), red (>80%) if [[ $pct -lt 50 ]]; then printf " \033[32m%dk/%dk (%d%%)\033[0m" "$current_k" "$size_k" "$pct" # Green elif [[ $pct -lt 80 ]]; then printf " \033[33m%dk/%dk (%d%%)\033[0m" "$current_k" "$size_k" "$pct" # Yellow else printf " \033[31m%dk/%dk (%d%%)\033[0m" "$current_k" "$size_k" "$pct" # Red fi fi printf "\n"