cost-track
Original:🇺🇸 English
Translated
Auto-capture per-session token usage from the Claude Code session jsonl and persist to the cost-tracking namespace
4installs
Sourceruvnet/ruflo
Added on
NPX Install
npx skill4agent add ruvnet/ruflo cost-trackTags
Translated version includes tags in frontmatterSKILL.md Content
View Translation Comparison →Cost Track
Reads the active Claude Code session jsonl (), tallies assistant-message per model, computes USD cost using REFERENCE.md pricing, and writes a structured record to the AgentDB namespace. This is the producer that gives and real data to consume.
~/.claude/projects/<encoded-cwd>/<session>.jsonlusagecost-trackingcost-reportcost-optimizeWhen 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:bash
node plugins/ruflo-cost-tracker/scripts/track.mjsThe script auto-discovers the session jsonl from the current working directory. To pin a specific session:. To dry-run (no memory write):TRACK_SESSION=/path/to/session.jsonl.TRACK_DRY_RUN=1 -
Inspect the markdown summary — total cost, per-model and per-tier breakdowns, and the persisted memory key.
-
Verify persistence —should list the new record.
mcp__claude-flow__memory_search --query "session-" --namespace cost-trackingstep 1 reads from this namespace.cost-report
Record shape (in cost-tracking
namespace)
cost-trackingKey: . Value (JSON):
session-<sessionId>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 constant mirrors REFERENCE.md "Model pricing (USD per 1M tokens)". Update both together when prices change. Cache-write tokens are billed at rate; cache-read tokens at (per Anthropic billing docs).
PRICINGcache_writecache_readEnv overrides
| Env | Default | Purpose |
|---|---|---|
| | Override which project's sessions to scan |
| most-recent jsonl | Pin a specific session file |
| unset | Also write the JSON summary to this path |
| unset | Skip the |
| unset | Suppress markdown output |
| | Override target namespace |
Cross-references
- (consumer) — reads records produced by this skill
cost-report - REFERENCE.md "Cost attribution formula" — the math the script implements
- (consumer; landing in P2) — reads totals to evaluate alerts
cost-budget-check