Zhang Jiahao 23c7037b57 Add session-end-log hook with per-session token tally
既有 Stop 钩子 token-stats-hook 记的是跨会话累计快照, 无法区分"这次会话
用了多少"; session-end-log 在 SessionEnd 时按 session_id 解析本次 transcript
做单会话统计, 产出一行可回溯的索引写入 ~/.claude/log.md, 方便事后盘点
哪场会话烧了哪些 token。Python 写零依赖, Ubuntu 自带 python3 免构建。
2026-04-21 00:58:00 +08:00
2026-04-21 00:52:39 +08:00

claudeplus

Claude Code 自定义命令集合。

安装

git clone https://git.deepknow.site/Knowit/claudeplus.git
mkdir -p ~/.claude/commands
cp claudeplus/commands/* ~/.claude/commands/

重启 Claude Code 后即可使用。

安装 Stop Hooktoken 用量自动备份)

cp claudeplus/hooks/token-stats-hook/token-stats-hook-bin ~/.claude/token-stats-hook-bin
chmod +x ~/.claude/token-stats-hook-bin

~/.claude/settings.json 中加入以下配置(如已有其他 hooks 注意合并):

{
  "hooks": {
    "Stop": [
      {
        "hooks": [
          {
            "type": "command",
            "command": "~/.claude/token-stats-hook-bin 2>/dev/null || true"
          }
        ]
      }
    ]
  }
}

重启 Claude Code 后,每次会话结束时会自动将 token 用量追加到 ~/.claude/token-stats-backup.jsonl

模块列表

模块 路径 说明
命令集 commands/ Claude Code 自定义斜杠命令
Stop Hook hooks/token-stats-hook/ 会话结束时自动备份 token 用量Go 二进制)
全局 CLAUDE.md CLAUDE.md 通用行为准则,减少常见 LLM 编码失误

安装全局 CLAUDE.md

cp claudeplus/CLAUDE.md ~/.claude/CLAUDE.md

放置在 ~/.claude/CLAUDE.md 后会对所有项目生效,可与项目内的 CLAUDE.md 合并使用。


命令列表

/token-stats [username|all]

统计本机 Claude token 用量,按日期分组展示。建议在 root 用户下使用,否则只能统计当前用户的数据。

/token-stats           # 当前用户
/token-stats charles   # 指定用户
/token-stats all       # 所有用户(含 root
Description
No description provided
Readme 1.5 MiB
v0.1.0 Latest
2026-04-20 21:33:17 +08:00
Languages
Python 50.1%
Go 49.9%