Skip to content

Instantly share code, notes, and snippets.

@otkrickey
Created February 21, 2026 20:17
Show Gist options
  • Select an option

  • Save otkrickey/f9561beb597d4a8b0887444dac3c0259 to your computer and use it in GitHub Desktop.

Select an option

Save otkrickey/f9561beb597d4a8b0887444dac3c0259 to your computer and use it in GitHub Desktop.
Claude Code StatusLine script — tmux session | Model | Context usage bar
#!/bin/bash
# Claude Code StatusLine for Swarm CTL
# Displays: tmux_session | Model | Context usage bar
set -euo pipefail
# Read JSON input from stdin
input=$(cat)
# Extract values using jq
model_name=$(echo "$input" | jq -r '.model.display_name // .model.id // "Claude"')
context_size=$(echo "$input" | jq -r '.context_window.context_window_size // 200000')
# Get Tmux session info (session:window.pane)
if [ -n "${TMUX:-}" ]; then
tmux_info=$(tmux display-message -p '#{session_name}:#{window_index}.#{pane_index}' 2>/dev/null || echo "tmux")
else
tmux_info="no-tmux"
fi
# Get current usage (Claude Code 2.0.70+ API)
input_tokens=$(echo "$input" | jq -r '.context_window.current_usage.input_tokens // 0')
cache_creation=$(echo "$input" | jq -r '.context_window.current_usage.cache_creation_input_tokens // 0')
cache_read=$(echo "$input" | jq -r '.context_window.current_usage.cache_read_input_tokens // 0')
# Calculate total used tokens
used_tokens=$((input_tokens + cache_creation + cache_read))
# Calculate percentage
if [ "$context_size" -gt 0 ]; then
percent=$((used_tokens * 100 / context_size))
else
percent=0
fi
# Display identifier (tmux only for first line)
display_id="$tmux_info"
# Build context bar (20 bricks)
bar_width=20
filled=$((percent * bar_width / 100))
empty=$((bar_width - filled))
# Color codes
CYAN='\033[36m'
DIM='\033[2m'
RESET='\033[0m'
YELLOW='\033[33m'
GREEN='\033[32m'
# Build bar string
bar=""
for ((i=0; i<filled; i++)); do
bar+="="
done
for ((i=0; i<empty; i++)); do
bar+="-"
done
# Format token counts (k)
used_k=$((used_tokens / 1000))
total_k=$((context_size / 1000))
# Color based on usage
if [ "$percent" -ge 85 ]; then
BAR_COLOR='\033[31m' # Red
elif [ "$percent" -ge 75 ]; then
BAR_COLOR='\033[33m' # Yellow
else
BAR_COLOR='\033[36m' # Cyan
fi
# Output: tmux_session:window.pane | Model | [====----] 25% (50k/200k)
echo -e "${GREEN}${display_id}${RESET} | ${YELLOW}${model_name}${RESET} | ${BAR_COLOR}[${bar}]${RESET} ${percent}% (${used_k}k/${total_k}k)"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment