Created
April 15, 2026 00:35
-
-
Save mshaaban0/0a601ac487630309c7900b8a7b5abf18 to your computer and use it in GitHub Desktop.
Claude Code statusline script - shows model, git branch, folder, context usage, and rate limits
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 | |
| input=$(cat) | |
| # Model | |
| MODEL=$(echo "$input" | jq -r '.model.display_name // .model.id // .model.name // empty') | |
| [ -z "$MODEL" ] && MODEL="Claude" | |
| # Directory — prefer cwd from JSON, fall back to shell cwd | |
| CWD=$(echo "$input" | jq -r '.workspace.current_dir // .cwd // empty') | |
| [ -z "$CWD" ] && CWD=$(pwd) | |
| # Show only the current folder name | |
| DIR=$(basename "$CWD") | |
| # Git branch (skip optional index.lock to avoid race conditions) | |
| GIT_BRANCH="" | |
| if git -C "$CWD" rev-parse --is-inside-work-tree --no-optional-locks 2>/dev/null | grep -q true; then | |
| GIT_BRANCH=$(git -C "$CWD" symbolic-ref --short HEAD 2>/dev/null \ | |
| || git -C "$CWD" rev-parse --short HEAD 2>/dev/null) | |
| fi | |
| # Context window usage | |
| CTX=$(echo "$input" | jq -r '.context_window.used_percentage // empty') | |
| CTX_STR="" | |
| [ -n "$CTX" ] && CTX_STR="ctx: $(printf '%.0f' "$CTX")%" | |
| # Rate limits (absent for API key users) | |
| FIVE_H=$(echo "$input" | jq -r '.rate_limits.five_hour.used_percentage // empty') | |
| WEEK=$(echo "$input" | jq -r '.rate_limits.seven_day.used_percentage // empty') | |
| LIMITS="" | |
| [ -n "$FIVE_H" ] && LIMITS="5h: $(printf '%.0f' "$FIVE_H")%" | |
| [ -n "$WEEK" ] && LIMITS="${LIMITS:+$LIMITS | }7d: $(printf '%.0f' "$WEEK")%" | |
| # Assemble segments, joining non-empty ones with " | " | |
| SEGMENTS="[$MODEL]" | |
| [ -n "$GIT_BRANCH" ] && SEGMENTS="$SEGMENTS | $GIT_BRANCH" | |
| SEGMENTS="$SEGMENTS | $DIR" | |
| [ -n "$CTX_STR" ] && SEGMENTS="$SEGMENTS | $CTX_STR" | |
| [ -n "$LIMITS" ] && SEGMENTS="$SEGMENTS | $LIMITS" | |
| echo "$SEGMENTS" |
Author
mshaaban0
commented
Apr 15, 2026
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment