Skip to content

Instantly share code, notes, and snippets.

@42LM
Created August 2, 2026 05:46
Show Gist options
  • Select an option

  • Save 42LM/bf775c195416b4e007d57a0d48c9db3b to your computer and use it in GitHub Desktop.

Select an option

Save 42LM/bf775c195416b4e007d57a0d48c9db3b to your computer and use it in GitHub Desktop.
claude cli status line
{
"statusLine": {
"type": "command",
"command": "bash /Users/Username/.claude/statusline-command.sh"
}
}
#!/usr/bin/env bash
# Claude Code statusLine command
#
# - in = fresh input tokens
# - out = output tokens
# - cr = cache read tokens
# - cw = cache write tokens
# - /N = context window size
# - ctx% = usage % (color coded)[9:04 PM]
#
# Line 1: ~/path Model total:N
# Line 2: in:N out:N cr:N cw:N /N ctx:[████░░] N%
# Line 3: session:N%[bar] resets <date> week:N%[bar] resets <date> [credits:N]
input=$(cat)
cwd=$(echo "$input" | jq -r '.workspace.current_dir // .cwd // ""')
cwd="${cwd/#$HOME/~}"
model=$(echo "$input" | jq -r '.model.display_name // ""')
used=$(echo "$input" | jq -r '.context_window.used_percentage // empty')
ctx_size=$(echo "$input" | jq -r '.context_window.context_window_size // empty')
total_tok=$(echo "$input" | jq -r '.context_window.total_input_tokens // empty')
in_tok=$(echo "$input" | jq -r '.context_window.current_usage.input_tokens // empty')
out_tok=$(echo "$input" | jq -r '.context_window.current_usage.output_tokens // empty')
cache_write=$(echo "$input" | jq -r '.context_window.current_usage.cache_creation_input_tokens // empty')
cache_read=$(echo "$input" | jq -r '.context_window.current_usage.cache_read_input_tokens // empty')
RESET="\033[0m"
BLUE="\033[34m"
MAGENTA="\033[35m"
WHITE="\033[97m"
GREEN="\033[32m"
DIM="\033[2m"
CYAN="\033[36m"
YELLOW="\033[33m"
CTX_GREEN="\033[32m"
CTX_YELLOW="\033[33m"
CTX_RED="\033[31m"
make_bar() {
local pct=$1 width=${2:-8}
local filled=$(( pct * width / 100 ))
local empty=$(( width - filled ))
local bar=""
for ((i=0; i<filled; i++)); do bar+="█"; done
for ((i=0; i<empty; i++)); do bar+="░"; done
echo "$bar"
}
pct_color() {
local pct=$1
if [ "$pct" -ge 80 ]; then echo "$CTX_RED"
elif [ "$pct" -ge 60 ]; then echo "$CTX_YELLOW"
else echo "$CTX_GREEN"
fi
}
# ── Line 1 ────────────────────────────────────────────────────────────────────
line1="${BLUE}${cwd}${RESET}"
[ -n "$model" ] && line1="${line1} ${MAGENTA}${model}${RESET}"
[ -n "$total_tok" ] && line1="${line1} ${WHITE}total:${total_tok}${RESET}"
# ── Line 2 ────────────────────────────────────────────────────────────────────
line2=""
[ -n "$in_tok" ] && line2="${line2} ${WHITE}in:${in_tok}${RESET}"
[ -n "$out_tok" ] && line2="${line2} ${GREEN}out:${out_tok}${RESET}"
[ -n "$cache_read" ] && line2="${line2} ${DIM}cr:${cache_read}${RESET}"
[ -n "$cache_write" ] && line2="${line2} ${DIM}cw:${cache_write}${RESET}"
[ -n "$ctx_size" ] && line2="${line2} ${DIM}/${ctx_size}${RESET}"
if [ -n "$used" ]; then
used_int=$(printf '%.0f' "$used")
ctx_color=$(pct_color "$used_int")
bar=$(make_bar "$used_int" 10)
line2="${line2} ${ctx_color}ctx:[${bar}] ${used_int}%%${RESET}"
fi
# ── Line 3: /usage (cached, background-refresh when stale) ────────────────────
USAGE_CACHE="/tmp/claude_usage_cache"
line3=""
if [ -f "$USAGE_CACHE" ]; then
if ! find "$USAGE_CACHE" -mmin -5 -print -quit 2>/dev/null | grep -q .; then
(claude /usage > "$USAGE_CACHE" 2>/dev/null &)
fi
usage_data=$(cat "$USAGE_CACHE")
else
usage_data=$(claude /usage 2>/dev/null)
[ -n "$usage_data" ] && printf '%s' "$usage_data" > "$USAGE_CACHE"
fi
if [ -n "$usage_data" ]; then
session_line=$(echo "$usage_data" | grep -i "current session:")
week_line=$(echo "$usage_data" | grep -i "current week")
credits_line=$(echo "$usage_data" | grep -i "credit")
if [ -n "$session_line" ]; then
spct=$(echo "$session_line" | grep -oE '[0-9]+' | head -1)
sreset=$(echo "$session_line" | sed 's/.*resets //' | sed 's/ (.*)//')
if [ -n "$spct" ]; then
scolor=$(pct_color "$spct")
sbar=$(make_bar "$spct" 8)
line3="${line3}${scolor}session:${spct}%%[${sbar}]${RESET} ${DIM}resets ${sreset}${RESET}"
fi
fi
if [ -n "$week_line" ]; then
wpct=$(echo "$week_line" | grep -oE '[0-9]+' | head -1)
wreset=$(echo "$week_line" | sed 's/.*resets //' | sed 's/ (.*)//')
if [ -n "$wpct" ]; then
wcolor=$(pct_color "$wpct")
wbar=$(make_bar "$wpct" 8)
[ -n "$line3" ] && line3="${line3} "
line3="${line3}${wcolor}week:${wpct}%%[${wbar}]${RESET} ${DIM}resets ${wreset}${RESET}"
fi
fi
if [ -n "$credits_line" ]; then
credits=$(echo "$credits_line" | grep -oE '\$?[0-9]+(\.[0-9]+)?' | head -1)
[ -n "$credits" ] && line3="${line3} ${CYAN}credits:${credits}${RESET}"
fi
fi
printf "${line1}\n${line2}\n${line3}\n"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment