Skip to content

Commit 2e4dee7

Browse files
committed
feat(claude): scale context bar to auto-compact trigger
Account for Claude Code's auto-compact buffer (13K) by calculating percentage against effective capacity instead of raw context_window_size. 100% = auto-compact fires.
1 parent c5ba0b6 commit 2e4dee7

File tree

1 file changed

+6
-7
lines changed

1 file changed

+6
-7
lines changed

claude/statusline-command.sh

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -128,12 +128,12 @@ if [[ -n "$model_name" ]] && [[ "$model_name" != "null" ]]; then
128128
fi
129129

130130
# Context window with gradient bar
131-
usage=$(echo "$input" | jq '.context_window.current_usage')
132-
if [[ "$usage" != "null" ]]; then
133-
current=$(echo "$usage" | jq '.input_tokens + .cache_creation_input_tokens + .cache_read_input_tokens')
134-
size=$(echo "$input" | jq '.context_window.context_window_size')
135-
if [[ "$size" -gt 0 ]]; then
136-
pct=$((current * 100 / size))
131+
# Auto-compact buffer (13K) from Claude Code source
132+
_ctx_tokens=$(echo "$input" | jq -r '.context_window.current_usage | .input_tokens + .cache_creation_input_tokens + .cache_read_input_tokens')
133+
_ctx_size=$(echo "$input" | jq -r '.context_window.context_window_size')
134+
_ctx_effective=$(( _ctx_size - 13000 ))
135+
pct=$(( _ctx_tokens * 100 / _ctx_effective )) 2>/dev/null
136+
if [[ -n "$pct" && "$pct" -gt 0 ]] 2>/dev/null; then
137137

138138
# Heatmap colors for positions 0-9 (green → yellow → red)
139139
# True color RGB values interpolated by position
@@ -230,7 +230,6 @@ if [[ "$usage" != "null" ]]; then
230230
pct_color=$(heatmap_color $last_pos)
231231

232232
segments+=("${output} ${pct_color}${pct}%${reset}")
233-
fi
234233
fi
235234

236235
# Session cost & duration

0 commit comments

Comments
 (0)