/ .claude / scripts / statusline.sh
statusline.sh
 1  #!/usr/bin/env bash
 2  
 3  command -v jq >/dev/null || exit 0
 4  
 5  input=$(cat)
 6  
 7  cwd=$(echo "$input" | jq -r '.workspace.current_dir')
 8  dir=$(basename "$cwd")
 9  model=$(echo "$input" | jq -r '.model.display_name // empty')
10  
11  cd "$cwd" 2>/dev/null || cd /
12  branch=$(git rev-parse --abbrev-ref HEAD 2>/dev/null)
13  dirty=""
14  if [ -n "$branch" ]; then
15    # Check for staged or unstaged changes to tracked files
16    git diff --quiet 2>/dev/null && git diff --cached --quiet 2>/dev/null || dirty="*"
17    # Check for untracked files (if not already dirty)
18    [ -z "$dirty" ] && [ -n "$(git ls-files --others --exclude-standard 2>/dev/null | head -1)" ] && dirty="*"
19  fi
20  
21  used=$(echo "$input" | jq -r '.context_window.used_percentage // empty')
22  five=$(echo "$input" | jq -r '.rate_limits.five_hour.used_percentage // empty')
23  
24  output="$dir"
25  [ -n "$branch" ] && output="$output ($branch$dirty)"
26  [ -n "$model" ] && output="$output | $model"
27  [ -n "$used" ] && output="$output | ctx $(printf "%.0f" "$used")%"
28  [ -n "$five" ] && output="$output | 5h $(printf "%.0f" "$five")%"
29  
30  echo "$output"