/ruflo-cost-tracker:cost-trackfrom ruflo-cost-tracker
Captures per-session Claude Code token usage from session jsonl files, computes USD cost using Anthropic pricing, and persists structured records to a cost-tracking namespace for reporting.
Ships in ruflo-cost-tracker. Installing the plugin adds it to Claude Code.
What the skill costs in Claude's context, stage by stage
Name and description: Claude knows it exists.
SKILL.md joins the conversation and stays.
None: SKILL.md is the whole skill.
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.
/loop 30m).Run the tracker from the project root:
node plugins/ruflo-cost-tracker/scripts/track.mjs
The 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__plugin_ruflo-core_ruflo__memory_search({ query: "session-", namespace: "cost-tracking" }) should list the new record. cost-report step 1 reads from this namespace.
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..."
}
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 | 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 |
cost-report (consumer) — reads records produced by this skillcost-budget-check (consumer; landing in P2) — reads totals to evaluate alertsWhat SKILL.md sets; muted values are Claude Code's defaults
Three short reads, in order
token-usage, cost-tracking, session-metrics, claude-code-costs
npx claudepluginhub ruvnet/ruflo --plugin ruflo-cost-tracker24 skills in this plugin
/cost-adviseOptimisation findings from your own Claude Code and Codex logs — low cache hit ratio, 1-hour cache writes that did not pay back, sub-agents on a top-tier model, Codex reasoning share, bloated sessions — each with evidence and a what-if saving. Use when asked how to cut spend or why it is high./cost-anomalyMAD-based outlier detection on session spend: lists anomalous sessions with modified-z scores, with an optional --alert-on-outliers exit code for CI. Use when asked which individual session is the cost outlier; cost-burn covers the aggregate trend./cost-benchmarkRun the corpus benchmark — booster locally, optional Gemini/Sonnet/Opus baselines — and persist a verifiable measured-vs-claimed tableOther plugins' skills for the same job