Last active
July 19, 2026 03:17
-
-
Save hidao80/b315382b1a426b5a725c1b2179a05538 to your computer and use it in GitHub Desktop.
A Bash script to modify the status line for the Claude Code CLI.
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 | |
| # Dependencies: awk, jq | |
| # Displayed as follows: `Sonnet 5 [high] ▸ current_dir ▸ ○○○○○○○○○○ 6% 62.16k` | |
| input=$(cat) | |
| # Model name | |
| model=$(echo "$input" | jq -r '.model.display_name // "unknown"') | |
| # Reasoning level (only if effort is present) | |
| effort=$(echo "$input" | jq -r '.effort.level // empty') | |
| if [ -n "$effort" ]; then | |
| model_effort="$model [$effort]" | |
| else | |
| model_effort="$model" | |
| fi | |
| # Repo name (workspace.repo.name -> fallback to basename of current_dir) | |
| repo_name=$(echo "$input" | jq -r '.workspace.repo.name // empty') | |
| if [ -z "$repo_name" ]; then | |
| cwd=$(echo "$input" | jq -r '.workspace.current_dir // empty') | |
| repo_name=$(basename "$cwd" 2>/dev/null) | |
| fi | |
| # Git branch | |
| cwd=$(echo "$input" | jq -r '.workspace.current_dir // empty') | |
| branch=$(git -C "$cwd" --no-optional-locks rev-parse --abbrev-ref HEAD 2>/dev/null) | |
| # Assemble line 1 | |
| line1="$model_effort" | |
| if [ -n "$repo_name" ] || [ -n "$branch" ]; then | |
| repo_branch="" | |
| [ -n "$repo_name" ] && repo_branch="$repo_name" | |
| [ -n "$branch" ] && repo_branch="$repo_branch ⎇ $branch" | |
| line1="$line1 ▸ $repo_branch" | |
| fi | |
| # Context gauge | |
| used_pct=$(echo "$input" | jq -r '.context_window.used_percentage // empty') | |
| if [ -n "$used_pct" ]; then | |
| pct_int=$(printf '%.0f' "$used_pct" 2>/dev/null || echo 0) | |
| filled=$(( pct_int / 10 )) | |
| [ "$filled" -gt 10 ] 2>/dev/null && filled=10 | |
| [ "$filled" -lt 0 ] 2>/dev/null && filled=0 | |
| gauge="" | |
| for i in $(seq 1 10); do | |
| if [ "$i" -le "$filled" ]; then | |
| gauge="${gauge}●" | |
| else | |
| gauge="${gauge}○" | |
| fi | |
| done | |
| ctx_part="$gauge $(printf '%.0f' "$used_pct")%" | |
| else | |
| ctx_part="○○○○○○○○○○ --%" | |
| fi | |
| # Token usage (uses total_input_tokens) | |
| tokens=$(echo "$input" | jq -r '.context_window.total_input_tokens // empty') | |
| tok_part="" | |
| if [ -n "$tokens" ] && [ "$tokens" != "null" ]; then | |
| if awk "BEGIN{exit !($tokens >= 1000000)}" 2>/dev/null; then | |
| tok_part=$(awk "BEGIN{printf \"%.2fm\", $tokens/1000000}") | |
| elif awk "BEGIN{exit !($tokens >= 1000)}" 2>/dev/null; then | |
| tok_part=$(awk "BEGIN{printf \"%.2fk\", $tokens/1000}") | |
| else | |
| tok_part="${tokens}" | |
| fi | |
| fi | |
| # Assemble remaining elements | |
| line2="$ctx_part" | |
| [ -n "$tok_part" ] && line2="$line2 $tok_part" | |
| # Combine into single line | |
| printf '%s ▸ %s' "$line1" "$line2" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment