Files
skills-win/claude-brain/scripts/check_models.sh
T
2026-10-15 01:59:40 +08:00

55 lines
2.1 KiB
Bash
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
#!/usr/bin/env bash
# 核实 claude-brain 运行中每个子 agent 实际使用的模型。
# 原理:Claude Code 把每个 subagent 的转录写在
# ~/.claude/projects/<项目slug>/<会话ID>/subagents/agent-<id>.jsonl
# 每条模型回复都带 "model":"claude-xxx" 字段;逐文件统计即可知道实际生效的模型,
# 以及是否中途切换过(一个文件里出现多种模型即为切换)。
#
# 用法:
# check_models.sh # 扫描当前项目目录下最近 24h 内活跃的会话
# check_models.sh <会话ID> # 只看指定会话
# check_models.sh --hours 6 # 改时间窗
# 项目 slug 由当前工作目录推导(E:\a\b -> E--a-b),与 Claude Code 规则一致。
hours=24
session=""
while [ $# -gt 0 ]; do
case "$1" in
--hours) hours="$2"; shift 2 ;;
*) session="$1"; shift ;;
esac
done
cwd="$(pwd -W 2>/dev/null || pwd)"
# Claude Code 的 slug 规则:盘符冒号、路径分隔符、下划线都变成 '-'(E:\a_b\c -> E--a-b-c)
slug="$(printf '%s' "$cwd" | sed -e 's#[:/\\_]#-#g')"
proj="$HOME/.claude/projects/$slug"
if [ ! -d "$proj" ]; then
echo "找不到项目转录目录: $proj" >&2
echo "请在 claude-brain 运行时所在的工程根目录执行本脚本。" >&2
exit 1
fi
mins=$((hours * 60))
if [ -n "$session" ]; then
files=$(find "$proj/$session/subagents" -name 'agent-*.jsonl' 2>/dev/null)
else
files=$(find "$proj" -path '*/subagents/agent-*.jsonl' -mmin "-$mins" 2>/dev/null)
fi
if [ -z "$files" ]; then
echo "没有找到子 agent 转录(窗口 ${hours}h,目录 $proj)。"
exit 0
fi
printf '%-28s %-10s %s\n' "agent" "回复数" "实际模型(出现次数)"
for f in $files; do
id=$(basename "$f" .jsonl | sed 's/^agent-//')
stats=$(grep -o '"model":"claude-[a-z0-9-]*"' "$f" | sed 's/"model":"//;s/"$//' | sort | uniq -c | awk '{printf "%s x%s ", $2, $1}')
n=$(grep -c '"model":"claude-' "$f")
flag=""
kinds=$(printf '%s' "$stats" | grep -o 'claude-[a-z0-9-]*' | sort -u | wc -l)
[ "$kinds" -gt 1 ] && flag=" <-- 中途切换过模型"
printf '%-28s %-10s %s%s\n' "$id" "$n" "$stats" "$flag"
done