Catalog
affaan-m/cost-tracking

affaan-m

cost-tracking

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.

global
0installs0uses~1.1k
v1.0Saved May 15, 2026

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:

  1. Today's spend and yesterday comparison.
  2. Total spend across the tracked database.
  3. Top projects ranked by cost.
  4. Top tools ranked by cost.
  5. 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_usd is 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.
  • /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.
Files1
1 files · 1.0 KB

Select a file to preview

Overall Score

87/100

Grade

A

Excellent

Safety

92

Quality

84

Clarity

86

Completeness

82

Summary

This skill enables agents to query a local SQLite cost-tracking database to report Claude Code token usage, spending, and budget information. It provides safe, read-only access to usage records with predefined SQL queries for common reporting patterns like cost breakdowns by project, tool, session, and date.

Detected Capabilities

local database readsqlite3 query executionfile existence checksshell command executiondata aggregation and reporting

Trigger Keywords

Phrases that MCP clients use to match this skill to user intent.

cost breakdownspending reporttoken usagebudget trackingsession costsproject expenses

Risk Signals

INFO

Read-only database access scoped to ~/.claude-cost-tracker/usage.db

All query examples
INFO

Prerequisite validation before querying (sqlite3 availability and database existence)

How It Works section
INFO

No write operations, modification, or deletion of database records

Entire skill
INFO

Shell execution via sqlite3 CLI with parameterized queries (no dynamic SQL injection patterns)

SQL query examples

Use Cases

  • Display today's spend and cumulative costs
  • Compare spending across projects and tools
  • Analyze session-level cost drilldowns
  • Track 7-day cost trends
  • Export cost data for budget monitoring
  • Identify high-cost projects or tool usage patterns

Quality Notes

  • Clear scope: reads from a specific, user-managed database file at a known path
  • Strong anti-patterns section explicitly forbids unsafe practices (unbounded exports, cost hard-coding, unrecommended plugins)
  • Detailed column mapping reduces ambiguity about database schema expectations
  • Predefined SQL queries prevent ad-hoc command construction and injection risks
  • Guidance on reporting format (currency decimals) shows attention to output quality
  • Appropriate prerequisites check prevents errors when database or tool is unavailable
  • Related skills section helps users discover complementary tools
  • Strong documentation of expected schema reduces implementation friction
Model: claude-haiku-4-5-20251001Analyzed: May 15, 2026

Reviews

Add this skill to your library to leave a review.

No reviews yet

Be the first to share your experience.

Add affaan-m/cost-tracking to your library

Command Palette

Search for a command to run...