Skip to content

Commit f2e4dc6

Browse files
committed
chore: claude code status line 에 정확한 컨텍스트 윈도우 사이즈 표시되도록 개선
1 parent 9e9b750 commit f2e4dc6

File tree

1 file changed

+25
-3
lines changed

1 file changed

+25
-3
lines changed

.claude/statusline.sh

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,31 @@
33
input=$(cat)
44

55
model_display_name=$(echo "$input" | jq -r '.model.display_name')
6-
total_cost_usd=$(echo "$input" | jq -r '.cost.total_cost_usd // 0')
76
output_style=$(echo "$input" | jq -r '.output_style.name // "default"')
87

9-
cost_formatted=$(printf "%.4f" "$total_cost_usd" 2>/dev/null || echo "$total_cost_usd")
8+
# Context window usage
9+
context_size=$(echo "$input" | jq -r '.context_window.context_window_size // 0')
10+
current_usage=$(echo "$input" | jq '.context_window.current_usage')
1011

11-
printf "Model: \033[36m%s\033[0m | Output: \033[35m%s\033[0m | Cost: \033[32m\$%s\033[0m USD" "$model_display_name" "$output_style" "$cost_formatted"
12+
if [ "$current_usage" != "null" ] && [ "$context_size" -gt 0 ] 2>/dev/null; then
13+
input_tokens=$(echo "$current_usage" | jq -r '.input_tokens // 0')
14+
cache_creation=$(echo "$current_usage" | jq -r '.cache_creation_input_tokens // 0')
15+
cache_read=$(echo "$current_usage" | jq -r '.cache_read_input_tokens // 0')
16+
17+
used_tokens=$((input_tokens + cache_creation + cache_read))
18+
context_pct=$(awk "BEGIN {printf \"%.1f\", ($used_tokens / $context_size) * 100}")
19+
20+
# Color by usage level
21+
if (( $(echo "$context_pct >= 80" | bc -l) )); then
22+
context_color="\033[31m" # red
23+
elif (( $(echo "$context_pct >= 50" | bc -l) )); then
24+
context_color="\033[33m" # yellow
25+
else
26+
context_color="\033[32m" # green
27+
fi
28+
else
29+
context_pct="--"
30+
context_color="\033[90m" # gray
31+
fi
32+
33+
printf "Model: \033[36m%s\033[0m | Output: \033[35m%s\033[0m | Context: ${context_color}%s%%\033[0m" "$model_display_name" "$output_style" "$context_pct"

0 commit comments

Comments
 (0)