#!/bin/bash # Read JSON data that Claude Code sends to stdin input=$(cat) # Extract fields using jq MODEL=$(echo "$input" | jq -r '.model.display_name') DIR=$(echo "$input" | jq -r '.workspace.current_dir') V=$(echo "$input" | jq -r '.version') # 上下文窗口大小(由 runcc.sh 根据 Provider 设置并写入 settings.json, # 默认 200000。GLM=200k, DeepSeek=1M) CC_CONTEXT_WINDOW="${CC_CONTEXT_WINDOW:-200000}" # 格式化上下文窗口: 200000→200k, 1000000→1M if [ "$CC_CONTEXT_WINDOW" -ge 1000000 ]; then CW_DISPLAY="$((CC_CONTEXT_WINDOW / 1000000))M" else CW_DISPLAY="$((CC_CONTEXT_WINDOW / 1000))k" fi # 模型名后追加上下文窗口大小(避免重复追加) if [[ "$MODEL" != *"$CW_DISPLAY"* ]]; then MODEL="${MODEL} [${CW_DISPLAY}]" fi # 计算上下文使用占比 AUTO_COMPACT_WINDOW="$CC_CONTEXT_WINDOW" PCT=$(echo "$input" | jq -r --argjson w "$AUTO_COMPACT_WINDOW" ' (( (.context_window.current_usage.input_tokens // 0) + (.context_window.current_usage.cache_creation_input_tokens // 0) + (.context_window.current_usage.cache_read_input_tokens // 0) ) * 100 / $w) | round ') BRANCH="" if command -v jj >/dev/null 2>&1 && jj repo root >/dev/null 2>&1; then BRANCH="🌿 $(jj log -r '@-' -T 'bookmarks' --no-graph 2>/dev/null)" elif git rev-parse --git-dir >/dev/null 2>&1; then BRANCH="🌿 $(git branch --show-current 2>/dev/null)" fi REMOTE="" if command -v jj >/dev/null 2>&1 && jj repo root >/dev/null 2>&1; then REMOTE="🌐 $(jj git remote list 2>/dev/null | head -1 | awk '{print $2}')" elif git rev-parse --git-dir >/dev/null 2>&1; then REMOTE="🌐 $(git remote get-url origin 2>/dev/null)" fi # DISABLE_COMPACT 提醒:无自动压缩,需手动 /compact 或 /clear COMPACT_HINT="" if [ "${DISABLE_COMPACT:-0}" = "1" ]; then COMPACT_HINT=" | ⚠无自动压缩" fi echo "版本:v$V | 模型:$MODEL | 上下文:${PCT}%${COMPACT_HINT}"