Skip to content

Instantly share code, notes, and snippets.

@sergical
Created November 25, 2025 15:05
Show Gist options
  • Select an option

  • Save sergical/ecc40519bcf1a5498349b3b2dfd90b14 to your computer and use it in GitHub Desktop.

Select an option

Save sergical/ecc40519bcf1a5498349b3b2dfd90b14 to your computer and use it in GitHub Desktop.
Claude Code Status line with git + ccusage
#!/bin/bash
# Read JSON input from Claude Code
input=$(cat)
# Parse basic info using jq
current_dir=$(echo "$input" | jq -r '.workspace.current_dir')
lines=$(echo "$input" | jq -r '"\(.cost.total_lines_added // 0)/\(.cost.total_lines_removed // 0)"')
# Get git branch
cd "$current_dir" 2>/dev/null
git_branch=$(git rev-parse --abbrev-ref HEAD 2>/dev/null || echo 'no-git')
# Build left side: directory | git | lines (no duplicates with ccusage)
left=$(printf "\033[35m%s\033[0m\033[2m | \033[33m%s\033[0m\033[2m | \033[32mLines: +%s\033[0m" \
"$(basename "$current_dir")" "$git_branch" "$lines")
# Get ccusage statusline (context usage info) by piping the same input
if command -v bun &> /dev/null; then
ccusage_output=$(echo "$input" | bun x ccusage statusline 2>/dev/null)
elif command -v npx &> /dev/null; then
ccusage_output=$(echo "$input" | npx -y ccusage statusline 2>/dev/null)
fi
# Combine both
if [[ -n "$ccusage_output" ]]; then
echo -e "${left} | ${ccusage_output}"
else
echo -e "${left}"
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment