File contents Procedure
インストール : npm install -g ccusage (Node 20+)
基本コマンド :
ccusage daily — 当日の input/output/cost
ccusage weekly --json — 週次 JSON
ccusage blocks --active --json — 現在の 5h block 状態
statusline 連携 (~/.claude/scripts/statusline.sh):
BLOCK_JSON=$(ccusage blocks --active --json)
tokenCounts.outputTokens / projection.remainingMinutes / costUSD を抽出
キャッシュ戦略 : blocks 30s / weekly 5min で statusline 高速化
cost-guard hook 連携 : UserPromptSubmit で閾値超え警告 (500k/800k tokens / $80/hr burn)
Pitfalls
ccusage は非公式 → MAX plan の cost は API 換算値 で実費ではない
session_id × transcript の重複加算で stop_cost_log と乖離 → ccusage の per-block 値を優先
node version 不一致で動かない → command -v ccusage で nvm fallback
weekly 集計は ISO week (月曜起点) なので、Anthropic billing と日付差あり
block 切り替わり時に projection.remainingMinutes が NaN → null check 必須
Verification
ccusage blocks --active --json | jq '.blocks[0].tokenCounts' で生値確認
statusline で 5h:Nk(cost) 表示成功
cost-guard hook が 800k 超で WARN を stderr に出すこと
See Also
— transcript JSONL直集計によるセッション後コスト集計(ccusageが使えない環境のフォールバック/事後精算はこちら)
1 --- 2 name: ccusage-cli-cost-tracking 3 description: Procedure 4 --- 5 6 ## Procedure 7 8 1. **インストール**: `npm install -g ccusage` (Node 20+) 9 2. **基本コマンド**: 10 - `ccusage daily` — 当日の input/output/cost 11 - `ccusage weekly --json` — 週次 JSON 12 - `ccusage blocks --active --json` — 現在の 5h block 状態 13 3. **statusline 連携** (~/.claude/scripts/statusline.sh): 14 - `BLOCK_JSON=$(ccusage blocks --active --json)` 15 - `tokenCounts.outputTokens / projection.remainingMinutes / costUSD` を抽出 16 4. **キャッシュ戦略**: blocks 30s / weekly 5min で statusline 高速化 17 5. **cost-guard hook 連携**: UserPromptSubmit で閾値超え警告 (500k/800k tokens / $80/hr burn) 18 19 ## Pitfalls 20 21 - ccusage は非公式 → MAX plan の cost は **API 換算値**で実費ではない 22 - session_id × transcript の重複加算で stop_cost_log と乖離 → ccusage の per-block 値を優先 23 - node version 不一致で動かない → `command -v ccusage` で nvm fallback 24 - weekly 集計は ISO week (月曜起点) なので、Anthropic billing と日付差あり 25 - block 切り替わり時に projection.remainingMinutes が NaN → null check 必須 26 27 ## Verification 28 29 - `ccusage blocks --active --json | jq '.blocks[0].tokenCounts'` で生値確認 30 - statusline で `5h:Nk(cost)` 表示成功 31 - cost-guard hook が 800k 超で WARN を stderr に出すこと 32 33 ## See Also 34 - — transcript JSONL直集計によるセッション後コスト集計(ccusageが使えない環境のフォールバック/事後精算はこちら)
bokuwalily/claude-code-skills/tree/main/skills/ccusage-cli-cost-tracking commit 1a22e95e86
Frequently asked questions How do I install the Ccusage CLI Cost Tracking skill? Run npx skillmds@latest add bokuwalily/ccusage-cli-cost-tracking in your terminal (requires Node.js), paste this page's agent-chat prompt into Claude, Cursor, or any MCP-connected agent, or download the SKILL.md file and copy it into your agent's skills directory.
What does the Ccusage CLI Cost Tracking skill do? Procedure It is listed under Coding & Dev Tools on SkillMD.
Is Ccusage CLI Cost Tracking safe to use? This skill has not completed SkillMD's automated safety review yet. SkillMD never runs a skill's scripts for you; review the SKILL.md before installing.
Which AI agents work with Ccusage CLI Cost Tracking? This skill is tagged as working with Claude Code, Claude.ai, OpenAI Codex. SKILL.md is an open format, so most agents that read a skills directory can load it too.
Is Ccusage CLI Cost Tracking free to use? Yes. Installing skills from SkillMD is free, and the skill stays under its author's original license.
Who published Ccusage CLI Cost Tracking? bokuwalily (@bokuwalily) published this skill. Their other Agent Skills are listed on their SkillMD profile.