Skip to content

Instantly share code, notes, and snippets.

@maxzuo
Last active August 13, 2026 21:28
Show Gist options
  • Select an option

  • Save maxzuo/a58403ad01968bf7c09ba898a7155800 to your computer and use it in GitHub Desktop.

Select an option

Save maxzuo/a58403ad01968bf7c09ba898a7155800 to your computer and use it in GitHub Desktop.
claude code statusline

Claude Code Statusline

A custom statusline for Claude Code that displays:

  • Folder name (dim cyan) — the current workspace directory
  • Git branch (dim yellow) — shown only inside a git repo
  • Model name (dim magenta) — e.g. Opus 5
  • Context usage (dim white) — ctx 3% (32.3k) with percentage and token count
  • Rate limits (green → yellow → red) — limit: (42%|68%) for 5-hour and 7-day windows, color-coded by severity

Installation

# Download the script
curl -sL https://gist.githubusercontent.com/maxzuo/a58403ad01968bf7c09ba898a7155800/raw/statusline-command.sh \
  > ~/.claude/statusline-command.sh && chmod +x ~/.claude/statusline-command.sh

Then add this to your ~/.claude/settings.json:

{
  "statusLine": {
    "type": "command",
    "command": "bash ~/.claude/statusline-command.sh"
  }
}

Requirements

  • bash
  • jq (for parsing the JSON context payload)
#!/bin/bash
# Claude Code status line: folder, git branch, model, context usage
input=$(cat)
cwd=$(printf '%s' "$input" | jq -r '.workspace.current_dir // .cwd // empty')
[ -n "$cwd" ] || cwd=$PWD
folder=$(basename "$cwd")
branch=$(git -C "$cwd" --no-optional-locks branch --show-current 2>/dev/null)
model=$(printf '%s' "$input" | jq -r '.model.display_name // empty')
effort=$(printf '%s' "$input" | jq -r '.effort.level // empty')
# "3% (32.3k)" — omitted entirely if the payload carries no context info.
# NB: current_usage is an object of token subtotals; total_input_tokens is the scalar.
ctx=$(printf '%s' "$input" | jq -r '
.context_window // {}
| select(.used_percentage != null or .total_input_tokens != null)
| [ (if .used_percentage != null then "\(.used_percentage | round)%" else empty end),
(if .total_input_tokens != null then
"(\(if .total_input_tokens >= 1000 then "\(.total_input_tokens / 100 | round / 10)k"
else "\(.total_input_tokens)" end))"
else empty end) ]
| join(" ")
')
# folder (dim cyan)
printf '\033[2;36m%s\033[0m' "$folder"
# git branch (dim yellow), only if present
if [ -n "$branch" ]; then
printf ' \033[2;33m(%s)\033[0m' "$branch"
fi
# separator + model (dim magenta), with effort level in parens when present
if [ -n "$model" ]; then
if [ -n "$effort" ]; then
printf ' \033[2m|\033[0m \033[2;35m%s\033[0m \033[2;35m(%s)\033[0m' "$model" "$effort"
else
printf ' \033[2m|\033[0m \033[2;35m%s\033[0m' "$model"
fi
fi
# separator + context usage (dim white)
if [ -n "$ctx" ]; then
printf ' \033[2m|\033[0m \033[2mctx %s\033[0m' "$ctx"
fi
# rate limits: "[42%|68%]" (no prefix) — percentages colored green→yellow→red by usage
pct_color() { awk '{if ($1 <= 50) print 32; else if ($1 <= 80) print 33; else print 31}' <<< "$1"; }
f_pct=$(printf '%s' "$input" | jq -r '.rate_limits.five_hour.used_percentage // empty')
s_pct=$(printf '%s' "$input" | jq -r '.rate_limits.seven_day.used_percentage // empty')
if [ -n "$f_pct" ] || [ -n "$s_pct" ]; then
f_color=$(pct_color "$f_pct")
s_color=$(pct_color "$s_pct")
printf ' \033[2m|\033[0m \033[2m[\033[0m'
[ -n "$f_pct" ] && printf '\033[2;%dm%.0f%%\033[0m' "$f_color" "$f_pct" || printf '--%'
printf '\033[2m|\033[0m'
[ -n "$s_pct" ] && printf '\033[2;%dm%.0f%%\033[0m' "$s_color" "$s_pct" || printf '--%'
printf '\033[2m]\033[0m'
fi
printf '\n'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment