A status line for Claude Code that displays real-time context window usage with a color-coded progress bar. Shows the current model, total window size, and how many tokens remain before autocompact triggers.
[Claude 4.5 Sonnet · 200K] ####------ 92K/140K left
- Green
####------— safe (< 70% used) - Yellow
#######---— warning (70–89% used) - Red
#########-— critical (≥ 90% used)
Works on macOS, Linux, and Windows (via Git Bash or WSL).
The script intentionally uses POSIX-portable constructs:
printfinstead ofecho -e(which behaves differently across shells)jqfor JSON parsing (available on all platforms)- Standard
awkandtrfor text formatting - No Bash-specific features beyond basic arithmetic
jqmust be installed (brew install jq/apt install jq/choco install jq)
Copy statusline.sh to ~/.claude/scripts/ and make it executable:
mkdir -p ~/.claude/scripts
cp statusline.sh ~/.claude/scripts/statusline.sh
chmod +x ~/.claude/scripts/statusline.shAdd the following to your ~/.claude/settings.json (or project-level .claude/settings.json):
{
// (optional) Set the autocompact threshold — default is 90%.
// The progress bar and "left" counter are based on this percentage of the total window.
"env": {
"CLAUDE_AUTOCOMPACT_PCT_OVERRIDE": "70" // ← change to your preferred %
},
// Add this block to enable the status line
"statusLine": {
"type": "command",
"command": "$HOME/.claude/scripts/statusline.sh"
}
}If your
settings.jsonalready has other keys, just merge the"env"and"statusLine"sections into the existing object.
- Claude Code pipes a JSON payload to the script's stdin on every turn
- The script reads
model,context_window_size, and current token usage from the JSON - It calculates usage against the effective limit (
window × autocompact %) - Outputs a single formatted line with model info, a 10-char progress bar, and remaining tokens
Fix: token count now uses pre-calculated used_percentage from Claude Code instead of manual calculation (input + cache tokens). This aligns the status line with the native auto-compaction indicator.