💼 Cost追跡
Claude Codeのトークン使用量や費用、
📺 まず動画で見る(YouTube)
▶ 【自動化】AIガチ勢の最新活用術6選がこれ1本で丸分かり!【ClaudeCode・AIエージェント・AI経営・Skills・MCP】 ↗
※ jpskill.com 編集部が参考用に選んだ動画です。動画の内容と Skill の挙動は厳密には一致しないことがあります。
📜 元の英語説明(参考)
Track and report Claude Code token usage, spending, and budgets from a local cost-tracking database. Use when the user asks about costs, spending, usage, tokens, budgets, or cost breakdowns by project, tool, session, or date.
🇯🇵 日本人クリエイター向け解説
Claude Codeのトークン使用量や費用、
※ jpskill.com 編集部が日本のビジネス現場向けに補足した解説です。Skill本体の挙動とは独立した参考情報です。
下記のコマンドをコピーしてターミナル(Mac/Linux)または PowerShell(Windows)に貼り付けてください。 ダウンロード → 解凍 → 配置まで全自動。
mkdir -p ~/.claude/skills && cd ~/.claude/skills && curl -L -o cost-tracking.zip https://jpskill.com/download/889.zip && unzip -o cost-tracking.zip && rm cost-tracking.zip
$d = "$env:USERPROFILE\.claude\skills"; ni -Force -ItemType Directory $d | Out-Null; iwr https://jpskill.com/download/889.zip -OutFile "$d\cost-tracking.zip"; Expand-Archive "$d\cost-tracking.zip" -DestinationPath $d -Force; ri "$d\cost-tracking.zip"
完了後、Claude Code を再起動 → 普通に「動画プロンプト作って」のように話しかけるだけで自動発動します。
💾 手動でダウンロードしたい(コマンドが難しい人向け)
- 1. 下の青いボタンを押して
cost-tracking.zipをダウンロード - 2. ZIPファイルをダブルクリックで解凍 →
cost-trackingフォルダができる - 3. そのフォルダを
C:\Users\あなたの名前\.claude\skills\(Win)または~/.claude/skills/(Mac)へ移動 - 4. Claude Code を再起動
⚠️ ダウンロード・利用は自己責任でお願いします。当サイトは内容・動作・安全性について責任を負いません。
🎯 このSkillでできること
下記の説明文を読むと、このSkillがあなたに何をしてくれるかが分かります。Claudeにこの分野の依頼をすると、自動で発動します。
📦 インストール方法 (3ステップ)
- 1. 上の「ダウンロード」ボタンを押して .skill ファイルを取得
- 2. ファイル名の拡張子を .skill から .zip に変えて展開(macは自動展開可)
- 3. 展開してできたフォルダを、ホームフォルダの
.claude/skills/に置く- · macOS / Linux:
~/.claude/skills/ - · Windows:
%USERPROFILE%\.claude\skills\
- · macOS / Linux:
Claude Code を再起動すれば完了。「このSkillを使って…」と話しかけなくても、関連する依頼で自動的に呼び出されます。
詳しい使い方ガイドを見る →- 最終更新
- 2026-05-17
- 取得日時
- 2026-05-18
- 同梱ファイル
- 1
💬 こう話しかけるだけ — サンプルプロンプト
- › Cost Tracking で、私のビジネスを分析して改善案を3つ提案して
- › Cost Tracking を使って、来週の会議用の資料を作って
- › Cost Tracking で、現状の課題を整理してアクションプランに落として
これをClaude Code に貼るだけで、このSkillが自動発動します。
📖 Skill本文(日本語訳)
※ 原文(英語/中国語)を Gemini で日本語化したものです。Claude 自身は原文を読みます。誤訳がある場合は原文をご確認ください。
[Skill 名] cost-tracking
コストトラッキング
このスキルは、ローカルの SQLite データベースから Claude Code のコストと使用履歴を分析するために使用します。これは、~/.claude-cost-tracker/usage.db に使用状況の行を書き込むコストトラッキングフックまたはプラグインをすでに持っているユーザーを対象としています。
ソース: MayurBhavsar による、古くなったコミュニティ PR #1304 からサルベージされました。
使用するタイミング
- ユーザーが「いくら使いましたか?」「このセッションの費用はいくらでしたか?」「私のトークン使用量はどれくらいですか?」と尋ねた場合。
- ユーザーが予算、支出制限、超過、またはコスト管理について言及した場合。
- ユーザーがプロジェクト、ツール、セッション、モデル、または日付ごとのコスト内訳を求めた場合。
- ユーザーが今日と昨日を比較したり、最近の傾向を調べたりしたい場合。
- ユーザーが最近の使用記録の CSV エクスポートを求めた場合。
仕組み
まず、前提条件を確認します。
command -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 を優先してください。モデルの価格とキャッシュの価格は時間とともに変化するため、トラッカーが各行の価格設定の真の情報源であるべきです。
例
クイックサマリー
sqlite3 ~/.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;
"
プロジェクト別コスト
sqlite3 -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;
"
ツール別コスト
sqlite3 -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;
"
過去7日間
sqlite3 -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;
"
セッション詳細
sqlite3 -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- 繰り返されるトークン消費を削減するためのコンテキスト圧縮。
📜 原文 SKILL.md(Claudeが読む英語/中国語)を展開
Cost Tracking
Use this skill to analyze Claude Code cost and usage history from a local SQLite
database. It is intended for users who already have a cost-tracking hook or
plugin writing usage rows to ~/.claude-cost-tracker/usage.db.
Source: salvaged from stale community PR #1304 by MayurBhavsar.
When to Use
- The user asks "how much have I spent?", "what did this session cost?", or "what is my token usage?"
- The user mentions budgets, spending limits, overruns, or cost controls.
- The user wants a cost breakdown by project, tool, session, model, or date.
- The user wants to compare today against yesterday or inspect a recent trend.
- The user asks for a CSV export of recent usage records.
How It Works
First verify prerequisites:
command -v sqlite3 >/dev/null && echo "sqlite3 available" || echo "sqlite3 missing"
test -f ~/.claude-cost-tracker/usage.db && echo "Database found" || echo "Database not found"
If the database is missing, do not fabricate usage data. Tell the user that cost tracking is not configured and suggest installing or enabling a trusted local cost-tracking hook/plugin.
The expected usage table usually contains one row per tool call or model
interaction. Column names vary by tracker, but the examples below assume:
| Column | Meaning |
|---|---|
timestamp |
ISO timestamp for the usage event |
project |
Project or repository name |
tool_name |
Tool or event name |
input_tokens |
Input token count, when recorded |
output_tokens |
Output token count, when recorded |
cost_usd |
Precomputed cost in USD |
session_id |
Claude Code session identifier |
model |
Model used for the event |
Prefer cost_usd over hand-calculating pricing. Model prices and cache pricing
change over time, and the tracker should be the source of truth for how each row
was priced.
Examples
Quick Summary
sqlite3 ~/.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;
"
Cost By Project
sqlite3 -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;
"
Cost By Tool
sqlite3 -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;
"
Last Seven Days
sqlite3 -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;
"
Session Drilldown
sqlite3 -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;
"
Reporting Guidance
When presenting cost data, include:
- Today's spend and yesterday comparison.
- Total spend across the tracked database.
- Top projects ranked by cost.
- Top tools ranked by cost.
- Session count and average cost per session when enough data exists.
For small amounts, format currency with four decimal places. For larger amounts, two decimals are enough.
Anti-Patterns
- Do not estimate costs from raw token counts when
cost_usdis present. - Do not assume the database exists without checking.
- Do not run unbounded
SELECT *exports on large databases. - Do not hard-code current model pricing in user-facing answers.
- Do not recommend installing unreviewed hooks or plugins that execute arbitrary code.
Related
/cost-report- Command-form report using the same database.cost-aware-llm-pipeline- Model-routing and budget-design patterns.token-budget-advisor- Context and token-budget planning.strategic-compact- Context compaction to reduce repeated token spend.