Transcript usage cost tally
Skill bokuwalily/claude-code-skills/skills/transcript-usage-cost-tally
75 battle-tested Claude Code skills from shipping 20+ apps solo — macOS, Next.js, Vercel, iOS/Expo, Cloudflare, Phaser, local AI media & more
npx -y skills add bokuwalily/claude-code-skills --skill transcript-usage-cost-tallyAssembled from the repository path, not quoted from the project. Check it against their README if it does not work.
One thing to look at
- 0 stars0 stars. Stars are a popularity signal and not a quality one, but at this level it is likely that nobody has read this closely except its author, and you would be relying on your own review.
What its author says it does
Copied from the file, not written here
Claude Code セッションごとの API トークン消費 (input/output/cache_read/cache_creation) を Stop hook で transcript JSONL から集計し、Anthropic 公式料金で USD 換算したいとき。
SKILL.md
2.5 KB, 795 tokens by cl100k_base, as published. Nobody here has run it
Procedure
- Stop hook 設置:
~/.claude/hooks/stop_cost_log.shで stdin からtranscript_pathを受け取り、JSONL を全行走査。 - usage 抽出: 各
message.usageからinput_tokens / output_tokens / cache_read_input_tokens / cache_creation_input_tokensを取得。cache_creation はephemeral_5m_input_tokensとephemeral_1h_input_tokensに分かれるので個別合算。 - model prefix で料金適用 (per million tokens):
claude-opus-*: $15 / $75 (input/output), cache_read $1.50, cache_create_5m $18.75, cache_create_1h $30claude-sonnet-4-6系: $3 / $15, cache_read $0.30, cache_create_5m $3.75, cache_create_1h $6claude-haiku-*: $1 / $5, cache_read $0.10, cache_create_5m $1.25, cache_create_1h $2
- JSONL 出力:
~/.claude/logs/cost-log.jsonlに{ts, session_id, cwd, input, output, cache_read, cache_creation, cost_usd, models}を 1 行追記。 - 集計:
~/.claude/scripts/cost-summary.shでtoday / 7d / 30dのセッション数・合計 cost を表示。statusline 用--shortモードあり。
Pitfalls
- MAX 定額プラン契約者にとって cost_usd は 実費ではなく消費量目安。混同しないよう注釈を残す。
- transcript JSONL は 1 行 1 メッセージだが
usageフィールドは assistant ターンにのみ存在。nullチェック必須。 - 同じ session 内で model 切替がある (Opus → Sonnet 等) → message 単位で model を見て料金適用。session 全体に 1 モデルを当てると過小/過大評価。
cache_read_input_tokensはinput_tokensと別カウント。二重計上しない。- 料金表は Anthropic 公式 (https://www.anthropic.com/pricing) で年次更新あり。ハードコードせずに script 冒頭の定数で集中管理。
Verification
- 既存 transcript で手動実行 → 想定オーダー ($0.1〜$10/session) の cost が出ること。
cost-log.jsonlの sum とcost-summary.sh 7dの合計が一致。- 同セッションを 2 回走らせて重複追記されないことを確認 (session_id で dedupe)。
- Opus / Sonnet / Haiku 混在セッションで
models配列に全部出ているか。
What ships with it
Read from the repository
Just SKILL.md. No reference files, no scripts.