cost-track

Captures per-session token usage from Claude Code session jsonl and persists cost records to memory.

70.1k|8.4k|Updated Jun 2, 2025
One-click install
npx skills add https://github.com/ruvnet/claude-flow --skill cost-track
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: cost-track
Source: https://github.com/ruvnet/claude-flow/tree/main/plugins/ruflo-cost-tracker/skills/cost-track
Command: npx skills add https://github.com/ruvnet/claude-flow --skill cost-track

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes scripts (resource) components.

What problem does it solve?

Claude Code sessions consume tokens across multiple models and tiers, but there is no built-in way to know how much a session actually cost. This Skill reads the session jsonl, tallies token usage per model, computes USD cost from Anthropic pricing, and stores a structured record so spending can be reported and audited later.

Core Features & Use Cases

  • Automatic session discovery: Locates the active session jsonl from the current working directory, with overrides to pin a specific session file.
  • Per-model and per-tier cost breakdown: Aggregates input, output, cache-write, and cache-read tokens per model and rolls them up into haiku/sonnet/opus tiers with USD totals.
  • Persistent cost records: Writes a structured JSON record keyed by session ID into the cost-tracking AgentDB namespace for downstream consumers like cost-report.
  • Use Case: After finishing a chunk of work, run the tracker to capture spend for that session, then let cost-report aggregate all sessions into a spending summary.

Quick Start

Run the cost tracking script from the project root to tally this session's token usage and save the cost record to memory.

Frequently Asked Questions about cost-track

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I track Claude Code session token costs?

Run the track.mjs script from the project root; it auto-discovers the active session jsonl under ~/.claude/projects, tallies usage per model, and computes USD cost. Set TRACK_SESSION to pin a specific session file or TRACK_DRY_RUN=1 to skip the memory write.

How is Claude API cost calculated from token usage?

Cost is computed per model using Anthropic's per-million-token pricing: input, output, cache-write, and cache-read tokens are each billed at their own rate. The script's PRICING constant mirrors the REFERENCE.md pricing table and both must be updated together.

Where are Claude Code session jsonl files stored?

Session transcripts live under ~/.claude/projects/<encoded-cwd>/<session>.jsonl, with one directory per project working directory. The tracker derives this path from the current working directory, or you can override it with TRACK_CWD or TRACK_SESSION.

Can I run cost tracking on a schedule during long sessions?

Yes, the script is cron-friendly and can be invoked periodically, for example via a 30-minute loop, to capture incremental spend. Each run writes a record keyed by session ID to the cost-tracking namespace.

Why does the cost tracker not write to memory?

Check whether TRACK_DRY_RUN=1 is set, which intentionally skips the memory store call. Also verify the memory store tool is available and that TRACK_NAMESPACE points to the intended namespace, which defaults to cost-tracking.