Files

token-stats-hook

Claude Code Stop hook每次会话结束时自动将 token 用量快照追加到 ~/.claude/token-stats-backup.jsonl

用 Go 编写,编译为二进制,启动时间 <5ms。

安装

cd hooks/token-stats-hook
go build -o ~/.claude/token-stats-hook-bin .

然后在 ~/.claude/settings.json 中加入:

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

备份格式

每行一条 JSON 记录:

{"timestamp":"2026-04-18T02:03:11Z","date":"2026-04-18","user":"charles","input":12861,"output":176499,"cache_write":1352380,"cache_read":15525643,"actual":189360}