💼 Cost Track
Claude Codeの利用時に、セッションごとに
📺 まず動画で見る(YouTube)
▶ 【自動化】AIガチ勢の最新活用術6選がこれ1本で丸分かり!【ClaudeCode・AIエージェント・AI経営・Skills・MCP】 ↗
※ jpskill.com 編集部が参考用に選んだ動画です。動画の内容と Skill の挙動は厳密には一致しないことがあります。
📜 元の英語説明(参考)
Auto-capture per-session token usage from the Claude Code session jsonl and persist to the cost-tracking namespace
🇯🇵 日本人クリエイター向け解説
Claude Codeの利用時に、セッションごとに
※ jpskill.com 編集部が日本のビジネス現場向けに補足した解説です。Skill本体の挙動とは独立した参考情報です。
⚠️ ダウンロード・利用は自己責任でお願いします。当サイトは内容・動作・安全性について責任を負いません。
🎯 この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-17
- 同梱ファイル
- 1
💬 こう話しかけるだけ — サンプルプロンプト
- › Cost Track で、私のビジネスを分析して改善案を3つ提案して
- › Cost Track を使って、来週の会議用の資料を作って
- › Cost Track で、現状の課題を整理してアクションプランに落として
これをClaude Code に貼るだけで、このSkillが自動発動します。
📖 Claude が読む原文 SKILL.md(中身を展開)
この本文は AI(Claude)が読むための原文(英語または中国語)です。日本語訳は順次追加中。
Cost Track
Reads the active Claude Code session jsonl (~/.claude/projects/<encoded-cwd>/<session>.jsonl), tallies assistant-message usage per model, computes USD cost using REFERENCE.md pricing, and writes a structured record to the cost-tracking AgentDB namespace. This is the producer that gives cost-report and cost-optimize real data to consume.
When to use
- After a meaningful chunk of work, to capture spend for the report.
- At session-end to persist the final tally.
- Periodically during long sessions (cron-friendly — see
/loop 30m).
Steps
-
Run the tracker from the project root:
node plugins/ruflo-cost-tracker/scripts/track.mjsThe script auto-discovers the session jsonl from the current working directory. To pin a specific session:
TRACK_SESSION=/path/to/session.jsonl. To dry-run (no memory write):TRACK_DRY_RUN=1. -
Inspect the markdown summary — total cost, per-model and per-tier breakdowns, and the persisted memory key.
-
Verify persistence —
mcp__claude-flow__memory_search --query "session-" --namespace cost-trackingshould list the new record.cost-reportstep 1 reads from this namespace.
Record shape (in cost-tracking namespace)
Key: session-<sessionId>. Value (JSON):
{
"sessionId": "1dba3b8c-...",
"cwd": "/Users/cohen/Projects/ruflo",
"startedAt": "2026-05-04T...",
"endedAt": "2026-05-05T...",
"messageCount": 234,
"byModel": {
"claude-opus-4-7": {
"tier": "opus",
"input_tokens": 12345,
"output_tokens": 6789,
"cache_creation_input_tokens": 800000,
"cache_read_input_tokens": 2000000,
"messages": 50,
"cost_usd": 1.23
}
},
"byTier": { "haiku": 0.0, "sonnet": 0.45, "opus": 1.23, "unknown": 0 },
"total_cost_usd": 1.68,
"capturedAt": "2026-05-05T..."
}
Pricing source of truth
The script's PRICING constant mirrors REFERENCE.md "Model pricing (USD per 1M tokens)". Update both together when prices change. Cache-write tokens are billed at cache_write rate; cache-read tokens at cache_read (per Anthropic billing docs).
Env overrides
| Env | Default | Purpose |
|---|---|---|
TRACK_CWD |
process.cwd() |
Override which project's sessions to scan |
TRACK_SESSION |
most-recent jsonl | Pin a specific session file |
TRACK_OUT |
unset | Also write the JSON summary to this path |
TRACK_DRY_RUN=1 |
unset | Skip the memory store call |
TRACK_QUIET=1 |
unset | Suppress markdown output |
TRACK_NAMESPACE |
cost-tracking |
Override target namespace |
Cross-references
cost-report(consumer) — reads records produced by this skill- REFERENCE.md "Cost attribution formula" — the math the script implements
cost-budget-check(consumer; landing in P2) — reads totals to evaluate alerts