diff --git a/home-configs/claude/statusline-command.sh b/home-configs/claude/statusline-command.sh index 624fde0..f4963e5 100755 --- a/home-configs/claude/statusline-command.sh +++ b/home-configs/claude/statusline-command.sh @@ -268,6 +268,24 @@ else fi fi +# Z.ai (ai-glm, ai-eltex) отдаёт usage только в конце ответа, в начале потока +# input_tokens=0, поэтому пока идёт запрос, Claude Code присылает used_percentage=0. +# Держим последнее ненулевое значение этой сессии. +session_id=$(echo "$input" | jq -r '.session_id // empty') +if [ -n "$session_id" ]; then + ctx_cache="$HOME/.cache/ai-setup/ctx_last_${session_id}" + if [ -n "$ctx_pct" ] && [ "$(printf '%.0f' "$ctx_pct")" -gt 0 ]; then + if [ ! -f "$ctx_cache" ]; then + mkdir -p "$HOME/.cache/ai-setup" + # Раз за сессию чистим кэш старых сессий + find "$HOME/.cache/ai-setup" -name 'ctx_last_*' -mtime +7 -delete 2>/dev/null + fi + echo "$ctx_pct" > "$ctx_cache" + elif [ -f "$ctx_cache" ]; then + ctx_pct=$(cat "$ctx_cache") + fi +fi + # ctx:0% при старте новой сессии (нет данных от API) [ -z "$ctx_pct" ] && ctx_pct="0"