Skip to content

scandnavik/tok-use

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 

Repository files navigation

tok-use

Claude Code 本機用量總帳。掃 ~/.claude/projects 底下所有 .jsonl 對話紀錄, 回溯加總 token 用量,印出一張跟常見 OpenTelemetry 截圖同款版面的表, 本機既有對話紀錄即可重建,不需要開 OTEL,現在就有結果

內容

路徑 用途
tools/token-report.py 掃描 + 加總 + 出表的腳本(純 Python 標準庫,跨平台)
commands/用量報表.md Claude Code slash command 定義(/用量報表,0 LLM token)

安裝

  1. tools/token-report.py 放到本機任一位置。
  2. commands/用量報表.md 放到 ~/.claude/commands/
  3. 改路徑commands/用量報表.md 內寫死了腳本絕對路徑 (python3 "C:/Users/User/tools/token-report.py" $ARGUMENTS)。 換機器要改成你自己的路徑;路徑用正斜線,Bash tool 在 Windows 才不會吃掉反斜線。

用法

直接跑腳本:

python3 token-report.py                              # 全部歷史
python3 token-report.py --since 2026-04-17
python3 token-report.py --since 2026-04-17 --until 2026-05-19

或在 Claude Code 裡:/用量報表(可帶 --since / --until)。

欄位對照(與常見截圖 1:1,算法相同)

欄位 定義
Input tokens 未快取輸入 + 快取讀取(cache_read)
Output tokens output_tokens 加總
Cache-read tokens cache_read_input_tokens 加總
Cache-write tokens cache_creation_input_tokens 加總
Uncached input tokens input_tokens 加總(真正全價的新輸入)
Requests 去重後的 API 回應筆數
Reasoning tokens JSONL 不含此欄,需開 OpenTelemetry 才有,否則顯示
Sessions (transcripts) 取代截圖的 Shutdown metric segments(後者是 OTEL 程序結束 flush 的段數,無 OTEL 無意義)

去重

同一則 API 回應在 session 續接 / 分支時會被複製寫進多個檔。 依 message.idrequestIduuid 去重,避免重複計算。

更新(單向鏡像)

活檔(~/.claude/commands/用量報表.md~/tools/token-report.py)是唯一真相來源; 本 repo 是鏡像備份。改完活檔後跑:

python 同步.py            # cp 活檔 → repo → commit → push
python 同步.py --no-push  # 只 cp + commit

單向(活檔 → repo),永不反向、永不刪檔;無變更時不產生空 commit。 活檔若不存在會中止且不動 repo(不以缺檔覆蓋鏡像)。

注意

  • 數字是你本機真實用量,跟別人截圖的數字本來就不同。
  • 訂閱方案(Max)下,這些數字只代表「用量強度」,不會逐 token 計費; 只有 API 按量計費才直接對應金額。

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages