Skip to content

Instantly share code, notes, and snippets.

@hkristen
Created May 11, 2026 08:53
Show Gist options
  • Select an option

  • Save hkristen/f732acf52731393b6048c13f016a21d9 to your computer and use it in GitHub Desktop.

Select an option

Save hkristen/f732acf52731393b6048c13f016a21d9 to your computer and use it in GitHub Desktop.
Claude Code statusline command — shows git branch, model, context %, message count, and conda env
#!/bin/bash
input="$(cat)"
cwd=$(echo "$input" | grep -o '"cwd":"[^"]*"' | head -1 | cut -d'"' -f4)
model=$(echo "$input" | grep -o '"display_name":"[^"]*"' | head -1 | cut -d'"' -f4)
ctx_pct=$(echo "$input" | grep -o '"used_percentage":[0-9.]*' | head -1 | cut -d: -f2)
transcript_path=$(echo "$input" | grep -o '"transcript_path":"[^"]*"' | head -1 | cut -d'"' -f4)
# Git branch
git_branch=""
if [ -n "$cwd" ] && git -C "$cwd" rev-parse --is-inside-work-tree >/dev/null 2>&1; 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 with color coding
ctx_str=""
if [ -n "$ctx_pct" ]; then
ctx_int=${ctx_pct%.*}
if [ "$ctx_int" -ge 80 ]; then
ctx_str=" \e[31m${ctx_pct}%\e[0m"
elif [ "$ctx_int" -ge 50 ]; then
ctx_str=" \e[33m${ctx_pct}%\e[0m"
else
ctx_str=" \e[32m${ctx_pct}%\e[0m"
fi
fi
# Message count from transcript
msg_count=""
if [ -n "$transcript_path" ] && [ -f "$transcript_path" ]; then
count=$(grep -c '"role":\s*"' "$transcript_path" 2>/dev/null || echo "0")
msg_count=" \e[37m${count}msg\e[0m"
fi
# Conda env
conda_env=""
if [ -n "$CONDA_DEFAULT_ENV" ]; then
conda_env="\e[36m${CONDA_DEFAULT_ENV}\e[0m "
fi
echo -e "${conda_env}\e[35m${git_branch}\e[0m \e[38;5;214m${model}\e[0m${ctx_str}${msg_count}"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment