Install any skill in seconds. Free to start, no credit card required.
Get Started Free →ローカルのコスト追跡データベースからClaude Codeのトークン使用量、支出、予算を追跡・レポートします。コスト、支出、使用量、トークン、予算、またはプロジェクト、ツール、セッション、日付によるコスト内訳について質問する場合に使用します。
.claude/skills/affaan-m-cost-tracking/SKILL.md| Test case | Without → With | Effect | Δ tokens | Δ turns |
|---|---|---|---|---|
| case-05 | ✗→✓ | ▲ Improved | -8% | 0% |
| case-06 | ✗→✓ | ▲ Improved | -16% | 0% |
| case-09 | ✗→✓ | ▲ Improved | 69% | 0% |
| case-10 | ✗→✓ | ▲ Improved | 64% | 0% |
| case-12 | ✗→✓ | ▲ Improved | 11% | 0% |
このスキルを使用して、ローカルSQLiteデータベースからClaude Codeのコストと使用履歴を分析します。これは、~/.claude-cost-tracker/usage.dbに使用行を書き込むコスト追跡フックまたはプラグインをすでに持っているユーザーを対象としています。
出典: MayurBhavsarによるコミュニティのPR #1304から救済されました。
まず前提条件を確認します:
bashcommand -v sqlite3 >/dev/null && echo "sqlite3 available" || echo "sqlite3 missing" test -f ~/.claude-cost-tracker/usage.db && echo "Database found" || echo "Database not found"
データベースが見つからない場合、使用データを作成しません。ユーザーにコスト追跡が設定されていないことを伝え、信頼できるローカルコスト追跡フック/プラグインのインストールまたは有効化を提案します。
期待されるusageテーブルには通常、ツール呼び出しまたはモデルインタラクションごとに1行が含まれます。列名はトラッカーによって異なりますが、以下の例では次のように仮定します:
| 列 | 意味 | | --- | --- | | timestamp | 使用イベントのISOタイムスタンプ | | project | プロジェクトまたはリポジトリ名 | | tool_name | ツールまたはイベント名 | | input_tokens | 記録された場合の入力トークン数 | | output_tokens | 記録された場合の出力トークン数 | | cost_usd | USDで事前計算されたコスト | | session_id | Claude Codeセッション識別子 | | model | イベントに使用されたモデル |
cost_usdを使用して手動で価格計算するよりも優先します。モデルの価格とキャッシュ価格は時間とともに変化し、トラッカーが各行の価格設定の信頼できる情報源であるべきです。
bashsqlite3 ~/.claude-cost-tracker/usage.db " SELECT 'Today: $' || ROUND(COALESCE(SUM(CASE WHEN date(timestamp) = date('now') THEN cost_usd END), 0), 4) || ' | Total: $' || ROUND(COALESCE(SUM(cost_usd), 0), 4) || ' | Calls: ' || COUNT(*) || ' | Sessions: ' || COUNT(DISTINCT session_id) FROM usage; "
bashsqlite3 -header -column ~/.claude-cost-tracker/usage.db " SELECT project, ROUND(SUM(cost_usd), 4) AS cost, COUNT(*) AS calls FROM usage GROUP BY project ORDER BY cost DESC; "
bashsqlite3 -header -column ~/.claude-cost-tracker/usage.db " SELECT tool_name, ROUND(SUM(cost_usd), 4) AS cost, COUNT(*) AS calls FROM usage GROUP BY tool_name ORDER BY cost DESC; "
bashsqlite3 -header -column ~/.claude-cost-tracker/usage.db " SELECT date(timestamp) AS date, ROUND(SUM(cost_usd), 4) AS cost, COUNT(*) AS calls FROM usage GROUP BY date(timestamp) ORDER BY date DESC LIMIT 7; "
bashsqlite3 -header -column ~/.claude-cost-tracker/usage.db " SELECT session_id, MIN(timestamp) AS started, MAX(timestamp) AS ended, ROUND(SUM(cost_usd), 4) AS cost, COUNT(*) AS calls FROM usage GROUP BY session_id ORDER BY started DESC LIMIT 10; "
コストデータを表示する場合、以下を含めます:
少額の場合、通貨を小数点4桁でフォーマットします。大きな金額には2桁で十分です。
cost_usdが存在する場合に生のトークン数からコストを推定しないこと。SELECT *エクスポートを実行しないこと。/cost-report - 同じデータベースを使用するコマンド形式のレポート。cost-aware-llm-pipeline - モデルルーティングと予算設計のパターン。token-budget-advisor - コンテキストとトークン予算の計画。strategic-compact - 繰り返しのトークン支出を削減するためのコンテキスト圧縮。| Case | Status | Duration (ms) | Turns | Tokens | Tool calls | ||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| Without | With | Δ | Without | With | Δ | Without | With | Δ | Without | With | Δ | ||
case-01 | fail→fail | 11,702 | 4,761 | -59% | 1 | 1 | 0% | 2,150 | 1,504 | -30% | 0 | 0 | — |
case-02 | fail→fail | 2,982 | 2,573 | -14% | 1 | 1 | 0% | 417 | 1,526 | +266% | 0 | 0 | — |
case-03 | fail→fail | 8,105 | 5,645 | -30% | 1 | 1 | 0% | 1,012 | 1,558 | +54% | 0 | 0 | — |
case-04 | fail→fail | 8,687 | 4,925 | -43% | 1 | 1 | 0% | 1,293 | 1,558 | +20% | 0 | 0 | — |
case-05 | fail→pass | 13,439 | 5,908 | -56% | 1 | 1 | 0% | 2,669 | 2,453 | -8% | 0 | 0 | — |
case-06 | fail→pass | 11,696 | 4,370 | -63% | 1 | 1 | 0% | 2,475 | 2,071 | -16% | 0 | 0 | — |
case-07 | pass→pass | 8,247 | 3,345 | -59% | 1 | 1 | 0% | 1,487 | 1,972 | +33% | 0 | 0 | — |
case-08 | pass→pass | 8,428 | 3,709 | -56% | 1 | 1 | 0% | 1,634 | 1,955 | +20% | 0 | 0 | — |
case-09 | fail→pass | 7,091 | 5,038 | -29% | 1 | 1 | 0% | 1,333 | 2,258 | +69% | 0 | 0 | — |
case-10 | fail→pass | 6,544 | 4,269 | -35% | 1 | 1 | 0% | 1,226 | 2,009 | +64% | 0 | 0 | — |
case-11 | pass→pass | 8,524 | 10,441 | +22% | 1 | 1 | 0% | 1,473 | 2,551 | +73% | 0 | 0 | — |
case-12 | fail→pass | 9,114 | 2,652 | -71% | 1 | 1 | 0% | 1,609 | 1,788 | +11% | 0 | 0 | — |
case-13 | fail→pass | 13,385 | 12,708 | -5% | 1 | 1 | 0% | 2,187 | 3,508 | +60% | 0 | 0 | — |
case-14 | pass→pass | 12,213 | 6,496 | -47% | 1 | 1 | 0% | 1,964 | 2,258 | +15% | 0 | 0 | — |
case-15 | pass→pass | 10,528 | 6,317 | -40% | 1 | 1 | 0% | 1,608 | 2,220 | +38% | 0 | 0 | — |
case-16 | fail→fail | 17,531 | 9,645 | -45% | 1 | 1 | 0% | 3,037 | 3,134 | +3% | 0 | 0 | — |
case-17 | pass→pass | 9,988 | 6,685 | -33% | 1 | 1 | 0% | 1,745 | 2,489 | +43% | 0 | 0 | — |
case-18 | pass→pass | 12,495 | 3,425 | -73% | 1 | 1 | 0% | 1,976 | 1,673 | -15% | 0 | 0 | — |
case-19 | fail→fail | 12,173 | 2,982 | -76% | 1 | 1 | 0% | 1,903 | 1,728 | -9% | 0 | 0 | — |
case-20 | pass→pass | 7,947 | 5,812 | -27% | 1 | 1 | 0% | 1,555 | 2,414 | +55% | 0 | 0 | — |
case-21 | pass→pass | 10,319 | 10,887 | +6% | 1 | 1 | 0% | 1,649 | 3,071 | +86% | 0 | 0 | — |
case-22 | pass→pass | 18,440 | 13,794 | -25% | 1 | 1 | 0% | 2,766 | 3,349 | +21% | 0 | 0 | — |
DecimalAI ran this skill against gemini-3.6-flash twice over the same eval suite — once with the skill loaded and once without — and compared the two runs case by case. 22 cases were attempted, and 19 counted toward the lift figure. The other 3 produced results that are not comparable between the two arms, so they are excluded from the headline rather than averaged into it. The headline lift of +27 percentage points is the difference between those two pass rates over the 19 comparable cases.
Without the skill loaded, the model failed this case. With it loaded, the same prompt on the same model passed. This is one improved case from the latest verified run; every case, including any that regressed, is in the table above.
Other measured skills in the registry, with their headline benchmark lift.