37 lines
1.4 KiB
Bash
Executable File
37 lines
1.4 KiB
Bash
Executable File
#!/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' | sed 's/\[1m\]/[200k]/')
|
|
DIR=$(echo "$input" | jq -r '.workspace.current_dir')
|
|
V=$(echo "$input" | jq -r '.version')
|
|
|
|
# 计算上下文使用占比
|
|
# JSON 中 used_percentage 是相对模型实际窗口(如 GLM 的 1M)计算的,
|
|
# 但 /context 命令显示的是相对 auto-compact 窗口(200k)的占比。
|
|
# 因此需要用实际 token 数 / 200000 来获得正确的百分比。
|
|
AUTO_COMPACT_WINDOW=200000
|
|
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
|
|
|
|
echo "版本:v$V | 模型:$MODEL | 上下文:${PCT}%" |