Created
November 25, 2025 15:05
-
-
Save sergical/ecc40519bcf1a5498349b3b2dfd90b14 to your computer and use it in GitHub Desktop.
Claude Code Status line with git + ccusage
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/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