Skip to content

Instantly share code, notes, and snippets.

@andkirby
Last active January 17, 2026 22:47
Show Gist options
  • Select an option

  • Save andkirby/f826e5d264368308cd9d5c4c086aa96e to your computer and use it in GitHub Desktop.

Select an option

Save andkirby/f826e5d264368308cd9d5c4c086aa96e to your computer and use it in GitHub Desktop.
Claude Code Statusline with context usage % - Includes workaround for https://github.com/anthropics/claude-code/issues/13385 (current_usage stays at 0)

Claude Code Statusline with context usage

A custom statusline for Claude Code CLI that displays time, user@host, current directory, context window percentage, and token counts.

Example Output

19:56:01 myname@mylaptop:my-project-dir (51% / 200k Β· 102k ↑ Β· 15k ↓)

Format

  • Time - Current time (red)
  • user@host:dir - User, hostname, and current directory basename
  • Context info:
    • 51% - Current context window usage percentage
    • 200k - Total context window size
    • 102k ↑ - Total input tokens sent (session cumulative)
    • 15k ↓ - Total output tokens received (session cumulative)

Color Coding

Based on context percentage:

  • ≀30%: Default color
  • 31-45%: 🟒 Green
  • 46-55%: 🟠 Orange
  • 56%+: πŸ”΄ Red

Installation

One-Line Install (Recommended)

curl -fsSL https://gist.githubusercontent.com/andkirby/f826e5d264368308cd9d5c4c086aa96e/raw/install-statusline.sh | bash

Prerequisites

# macOS
brew install jq

# Linux
sudo apt install jq  # Debian/Ubuntu
sudo yum install jq  # RHEL/CentOS

Manual Install

  1. Download the script:
curl -fsSL https://gist.githubusercontent.com/andkirby/f826e5d264368308cd9d5c4c086aa96e/raw/statusline-command.sh -o ~/.claude/statusline-command.sh
  1. Make it executable:
chmod +x ~/.claude/statusline-command.sh
  1. Add to ~/.claude/settings.json:
{
  "statusLine": {
    "type": "command",
    "command": "~/.claude/statusline-command.sh"
  }
}

Testing

Test the script manually:

echo '{"workspace":{"current_dir":"/Users/user/project"},"context_window":{"context_window_size":200000,"current_usage":{"input_tokens":70000,"cache_creation_input_tokens":1000,"cache_read_input_tokens":2000},"total_input_tokens":102000,"total_output_tokens":15000}}' | ~/.claude/statusline-command.sh

Known Issues

  • Context percentage shows 0% - Due to bug #13385, current_usage may return zeros. The script uses the correct property per the API docs, so it will work when the bug is fixed.

Customization

Modify color thresholds in statusline-command.sh:

if [ $context_percent -le 30 ]; then
    context_color='\033[0m'   # Default
elif [ $context_percent -le 45 ]; then
    context_color='\033[32m'  # Green
elif [ $context_percent -le 55 ]; then
    context_color='\033[33m'  # Orange
else
    context_color='\033[31m'  # Red
fi

Color Codes

Color Code
Red \033[31m
Green \033[32m
Orange/Yellow \033[33m
Blue \033[34m
Reset \033[0m
#!/bin/bash
set -e
GIST_URL="https://gist.githubusercontent.com/andkirby/f826e5d264368308cd9d5c4c086aa96e/raw/statusline-command.sh"
SCRIPT_PATH="$HOME/.claude/statusline-command.sh"
SETTINGS_FILE="$HOME/.claude/settings.json"
echo "Installing Claude Code Statusline..."
# Create .claude directory if it doesn't exist
mkdir -p "$HOME/.claude"
# Download the script
echo "Downloading statusline script..."
curl -fsSL "$GIST_URL" -o "$SCRIPT_PATH"
# Make it executable
chmod +x "$SCRIPT_PATH"
# Update settings.json
TMP=$(mktemp)
if [ -f "$SETTINGS_FILE" ]; then
echo "Updating settings.json..."
jq '.statusLine = {"type": "command", "command": "~/.claude/statusline-command.sh"}' "$SETTINGS_FILE" > "$TMP" && mv "$TMP" "$SETTINGS_FILE"
else
echo "Creating settings.json..."
echo '{"statusLine": {"type": "command", "command": "~/.claude/statusline-command.sh"}}' > "$SETTINGS_FILE"
fi
echo ""
echo "Statusline installed successfully!"
echo "Restart Claude Code to see it."
#!/bin/bash
# Read JSON input from stdin
input=$(cat)
# Extract basic information
time=$(date +%H:%M:%S)
user=$(whoami)
host=$(hostname -s)
current_dir=$(echo "$input" | jq -r '.workspace.current_dir' | xargs basename)
# Get context window info
size=$(echo "$input" | jq '.context_window.context_window_size')
usage=$(echo "$input" | jq '.context_window.current_usage')
total_input=$(echo "$input" | jq '.context_window.total_input_tokens // 0')
total_output=$(echo "$input" | jq '.context_window.total_output_tokens // 0')
# Debug: dump context_window to stdout
#echo "$input" | jq '.context_window' >&1
# Calculate current context usage (input + cache_creation + cache_read) for percentage
current_input=$(echo "$usage" | jq '.input_tokens + .cache_creation_input_tokens + .cache_read_input_tokens')
size_k=$((size / 1000))
# Use total tokens for arrow display
input_k=$((total_input / 1000))
output_k=$((total_output / 1000))
# Calculate percentage from current_usage
context_percent=$(printf "%.0f" "$(echo "scale=2; ($current_input * 100 / $size)" | bc 2>/dev/null || echo 0)")
# Determine context color based on percentage
# After 30% - green, After 45% - orange, After 55% - red
if [ $context_percent -le 30 ]; then
context_color='\033[0m' # default/no color
elif [ $context_percent -le 45 ]; then
context_color='\033[32m' # green
elif [ $context_percent -le 55 ]; then
context_color='\033[33m' # orange/yellow
else
context_color='\033[31m' # red
fi
# Build the status line with color formatting
# Time in red, followed by user@host:dir, then context info: (% / total Β· input ↑ Β· output ↓)
printf '\033[31m%s\033[0m %s@%s:%s %b(%d%% / %dk Β· %dk ↑ Β· %dk ↓)\033[0m' \
"$time" \
"$user" \
"$host" \
"$current_dir" \
"$context_color" \
"$context_percent" \
"$size_k" \
"$input_k" \
"$output_k"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment