Loading...
Git-focused statusline showing branch, dirty status, ahead/behind indicators, and stash count alongside Claude session info
#!/usr/bin/env bash
# Git-Focused Statusline for Claude Code
# Emphasizes git status with visual indicators
# Read JSON from stdin
read -r input
# Extract Claude session data
model=$(echo "$input" | jq -r '.model // "unknown"' | sed 's/claude-//')
tokens=$(echo "$input" | jq -r '.session.totalTokens // 0')
workdir=$(echo "$input" | jq -r '.workspace.path // "."')
# Get git information from workspace
cd "$workdir" 2>/dev/null || cd .
if git rev-parse --git-dir > /dev/null 2>&1; then
# Get branch name
branch=$(git symbolic-ref --short HEAD 2>/dev/null || echo "(detached)")
# Check if working directory is clean
if [ -z "$(git status --porcelain)" ]; then
status_icon="✓"
status_color="\033[32m" # Green
else
status_icon="✗"
status_color="\033[33m" # Yellow
fi
# Check ahead/behind status
ahead_behind=$(git rev-list --left-right --count HEAD...@{upstream} 2>/dev/null)
if [ -n "$ahead_behind" ]; then
ahead=$(echo "$ahead_behind" | cut -f1)
behind=$(echo "$ahead_behind" | cut -f2)
if [ "$ahead" -gt 0 ]; then
tracking="↑$ahead"
fi
if [ "$behind" -gt 0 ]; then
tracking="${tracking}↓$behind"
fi
fi
# Check stash count
stash_count=$(git stash list 2>/dev/null | wc -l | tr -d ' ')
if [ "$stash_count" -gt 0 ]; then
stash_info=" ⚑$stash_count"
fi
git_info=" ${status_color}${branch}${tracking}${stash_info} ${status_icon}\033[0m"
else
git_info=""
fi
# Build statusline
echo -e "\033[36m${model}\033[0m │ \033[35m${tokens}\033[0m${git_info}"
{
"format": "bash",
"position": "left",
"colorScheme": "git-status",
"refreshInterval": 1000
}Git branch not showing or shows '(detached)'
Ensure you're on a proper branch: git checkout main. Detached HEAD state is normal when checking out specific commits.
Ahead/behind indicators (↑↓) not appearing
This requires an upstream branch to be set. Run: git branch --set-upstream-to=origin/main main (adjust branch name as needed).
Status always shows dirty (✗) even after commit
Check git status for untracked files or changes. The statusline reflects actual git state. Run git status -s to see what's detected.
Unicode icons showing as boxes
Install a Nerd Font or ensure terminal has Unicode support. Test with: echo ' ✓ ✗ ↑ ↓ ⚑'
Loading reviews...