Skip to content

Instantly share code, notes, and snippets.

@Saissaken
Created January 14, 2026 17:38
Show Gist options
  • Select an option

  • Save Saissaken/c169d570c95e621faf6b5ae2a332a5f1 to your computer and use it in GitHub Desktop.

Select an option

Save Saissaken/c169d570c95e621faf6b5ae2a332a5f1 to your computer and use it in GitHub Desktop.
Custom Claude statusline: `repo-name main 5 +195 -31 Opus 4.5 115k/200k (57%)`
#!/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"
@Saissaken
Copy link
Author

image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment