Files
claudeplus/hooks/token-stats-hook/README.md

40 lines
800 B
Markdown
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.
# token-stats-hook
Claude Code Stop hook每次会话结束时自动将 token 用量快照追加到 `~/.claude/token-stats-backup.jsonl`
用 Go 编写,编译为二进制,启动时间 <5ms。
## 安装
```bash
cd hooks/token-stats-hook
go build -o ~/.claude/token-stats-hook-bin .
```
然后在 `~/.claude/settings.json` 中加入:
```json
{
"hooks": {
"Stop": [
{
"hooks": [
{
"type": "command",
"command": "~/.claude/token-stats-hook-bin 2>/dev/null || true"
}
]
}
]
}
}
```
## 备份格式
每行一条 JSON 记录:
```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}
```