Skip to content

Instantly share code, notes, and snippets.

@joepreludian
Last active August 5, 2026 14:27
Show Gist options
  • Select an option

  • Save joepreludian/3b218674b3d65c7625b8eb51f77a7b5d to your computer and use it in GitHub Desktop.

Select an option

Save joepreludian/3b218674b3d65c7625b8eb51f77a7b5d to your computer and use it in GitHub Desktop.
Prompt to Gitline

Claude Code status line — shareable prompt

Reverse-engineered from ~/.claude/statusline-command.sh. Paste the block below into Claude Code, either as a plain message or after /statusline.


Set up my Claude Code status line as a bash script at ~/.claude/statusline-command.sh,
and register it in ~/.claude/settings.json under the "statusLine" key as
{"type": "command", "command": "bash /Users/<me>/.claude/statusline-command.sh"}.

The script reads the session JSON from stdin and parses it with jq. Fields to read:
  .workspace.current_dir // .cwd          -> working directory
  .context_window.total_input_tokens      -> token count
  .model.display_name                     -> model name
  .context_window.used_percentage         -> context used
  .context_window.remaining_percentage    -> context left
  .rate_limits.five_hour.used_percentage  -> 5-hour limit
  .rate_limits.seven_day.used_percentage  -> weekly limit

Render six space-separated badges, each as colored ANSI background blocks with a
one-space pad inside, reset after each. Left to right:

1. TOKENS - cyan background, black text. Show "12.3k tokens" when >= 1000
   (one decimal), otherwise "456 tokens". Show "0 tokens" if missing.
2. MODEL - blue background, white text. Just the display name. Omit if empty.
3. CONTEXT - text is "ctx: 42% used / 58% left" with both percentages rounded to
   whole numbers. Background is green under 60%, yellow at 60-84%, red at 85%+,
   based on used percentage. If the data is missing, gray background, white text,
   and the text "ctx: --".
4. 5-HOUR LIMIT - "5h: 37%", same green/yellow/red thresholds on used percentage.
   Gray with "5h: --" if missing.
5. WEEKLY LIMIT - "wk: 12%", identical rules to the 5h badge.
6. GIT BRANCH - orange background (256-color 208), black text, prefixed with the
   ⎇ character. Get it with
   `git --no-optional-locks -C "$cwd" branch --show-current`, falling back to
   `rev-parse --short HEAD` on a detached HEAD. Omit the badge entirely if the
   directory is not a git repo.

Use --no-optional-locks so the status line never fights the user's git commands.
Make the script executable.

Notes for whoever receives it

  • /Users/<me>/ is a placeholder — the real settings.json needs their own absolute path, since Claude Code does not expand ~ in the statusLine command.
  • Depends on jq and awk. awk is everywhere; jq may need brew install jq.
  • Sending ~/.claude/statusline-command.sh directly is more faithful than regenerating from this prompt — it is 113 lines and self-contained.
#!/usr/bin/env bash
# Claude Code status line: token usage, model, context percentage, and rate-limit badges
input=$(cat)
cwd=$(echo "$input" | jq -r '.workspace.current_dir // .cwd // empty')
used=$(echo "$input" | jq -r '.context_window.used_percentage // empty')
remaining=$(echo "$input" | jq -r '.context_window.remaining_percentage // empty')
model=$(echo "$input" | jq -r '.model.display_name // empty')
total_tokens=$(echo "$input" | jq -r '.context_window.total_input_tokens // empty')
five_hour_pct=$(echo "$input" | jq -r '.rate_limits.five_hour.used_percentage // empty')
seven_day_pct=$(echo "$input" | jq -r '.rate_limits.seven_day.used_percentage // empty')
# ANSI color codes
RESET="\033[0m"
# Background colors
BG_GREEN="\033[42m"
BG_YELLOW="\033[43m"
BG_RED="\033[41m"
BG_BLUE="\033[44m"
BG_GRAY="\033[100m"
BG_CYAN="\033[46m"
BG_ORANGE="\033[48;5;208m"
# Foreground
FG_BLACK="\033[30m"
FG_WHITE="\033[97m"
# Format total_tokens human-readably: >= 1000 → X.Xk, else plain number
if [ -n "$total_tokens" ] && [ "$total_tokens" -gt 0 ] 2>/dev/null; then
if [ "$total_tokens" -ge 1000 ]; then
tok_label="$(awk "BEGIN { printf \"%.1fk tokens\", $total_tokens/1000 }")"
else
tok_label="${total_tokens} tokens"
fi
tok_part="$(printf "${BG_CYAN}${FG_BLACK} %s ${RESET}" "$tok_label")"
else
tok_part="$(printf "${BG_CYAN}${FG_BLACK} 0 tokens ${RESET}")"
fi
# Pick context bar color based on usage
if [ -z "$used" ]; then
ctx_bg="$BG_GRAY"
ctx_fg="$FG_WHITE"
ctx_label="ctx: --"
else
used_int=$(printf "%.0f" "$used")
remaining_int=$(printf "%.0f" "$remaining")
if [ "$used_int" -ge 85 ]; then
ctx_bg="$BG_RED"
ctx_fg="$FG_WHITE"
elif [ "$used_int" -ge 60 ]; then
ctx_bg="$BG_YELLOW"
ctx_fg="$FG_BLACK"
else
ctx_bg="$BG_GREEN"
ctx_fg="$FG_BLACK"
fi
ctx_label="ctx: ${used_int}% used / ${remaining_int}% left"
fi
# Model badge
if [ -n "$model" ]; then
model_part="$(printf "${BG_BLUE}${FG_WHITE} %s ${RESET}" "$model")"
else
model_part=""
fi
# Context badge
ctx_part="$(printf "${ctx_bg}${ctx_fg} %s ${RESET}" "$ctx_label")"
# Rate-limit badge helper: pick color by used percentage
rate_badge() {
local label="$1"
local pct_raw="$2"
if [ -z "$pct_raw" ]; then
printf "${BG_GRAY}${FG_WHITE} %s: -- ${RESET}" "$label"
else
local pct_int
pct_int=$(printf "%.0f" "$pct_raw")
local bg fg
if [ "$pct_int" -ge 85 ]; then
bg="$BG_RED"; fg="$FG_WHITE"
elif [ "$pct_int" -ge 60 ]; then
bg="$BG_YELLOW"; fg="$FG_BLACK"
else
bg="$BG_GREEN"; fg="$FG_BLACK"
fi
printf "${bg}${fg} %s: %d%% ${RESET}" "$label" "$pct_int"
fi
}
five_hour_part="$(rate_badge "5h" "$five_hour_pct")"
seven_day_part="$(rate_badge "wk" "$seven_day_pct")"
# Git branch badge (orange background)
branch=""
if [ -n "$cwd" ]; then
branch=$(git --no-optional-locks -C "$cwd" branch --show-current 2>/dev/null)
if [ -z "$branch" ]; then
branch=$(git --no-optional-locks -C "$cwd" rev-parse --short HEAD 2>/dev/null)
fi
fi
if [ -n "$branch" ]; then
branch_part="$(printf "${BG_ORANGE}${FG_BLACK} \xe2\x8e\x87 %s ${RESET}" "$branch")"
else
branch_part=""
fi
printf "%s %s %s %s %s %s" "$tok_part" "$model_part" "$ctx_part" "$five_hour_part" "$seven_day_part" "$branch_part"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment