From e3a1c500fd2d506ccd1be2b0d22a3b76fcfcac03 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=92=D0=B8=D1=82=D0=B0=D0=BB=D0=B8=D0=B9=20=D0=9D=D0=B8?= =?UTF-8?q?=D0=BA=D0=B8=D1=82=D0=B5=D0=BD=D0=BA=D0=BE?= Date: Wed, 7 Oct 2026 12:46:18 +0700 Subject: [PATCH] fix(statusline): keep last ctx value while a Z.ai request is running Z.ai (ai-glm, ai-eltex) streams message_start with input_tokens=0 and sends the real usage only in the final message_delta, so while a request runs Claude Code passes used_percentage=0 and ctx: dropped to 0%. Keep the last non-zero value per session_id in ~/.cache/ai-setup/ctx_last_ and show it instead of the zero. /clear starts a new session id, so it still shows 0 there. Co-Authored-By: Claude Opus 5.5 --- home-configs/claude/statusline-command.sh | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) 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"