cost-tracking
Skill0 starsChanged 3 months agoMITView on GitHub
Track and report Claude Code token use, cost, and budgets from a local SQLite database. Use for questions about cost, spend, usage, tokens, budgets, or breakdowns by project, tool, session, model, or date.
9 other projects use a version of this, 4 of them edited.
Adopted by
Most recently taken up by
- satvikgbusiness-jpg/Claude-skillstheir own version, first seen Nov 29, 2026
- XORwell/archeflowtheir own version, first seen Nov 15, 2026
- renepf/claude-skillstheir own version, first seen Oct 25, 2026
- davidanthonyn/claude-skillsedited, first seen Oct 20, 2026
- airshell/ai-optimizertheir own version, first seen Oct 17, 2026
- gongyijie85/dsh-ecctheir own version, first seen Oct 13, 2026
Other versions9 projects use a version of this.
Word for word · 0
None found.
Edited · 4
- Fmarzochi/EGC★ 6121% same
- SamuelNDCE/claude-super-skill-library★ 122% same
- agenticluke/claude-cost-tracker-plus★ 027% same
- davidanthonyn/claude-skills★ 022% same
Wrote their own version · 5
- gongyijie85/dsh-ecc★ 8same name
- airshell/ai-optimizer★ 2same name
- renepf/claude-skills★ 0same name
- satvikgbusiness-jpg/Claude-skills★ 0same name
- XORwell/archeflow★ 0same name
How matches are found. Word for word: the exact same text. Edited: shares passages with this file (“99% same” means 99% of its five-word phrases also appear here; 10% or more counts). Their own version: similar meaning, or, weakest, the same name. We can’t tell which project had it first. Projects are counted among the 200 most-starred candidates, and mentions are links to the repository we found, up to 50 per site, so both counts are a floor.
The file
Show its rules and text
We split this skill into the rules it gives an agent
41 rules. 0 are common, 36 are distinctive, and 5 are very specific to this project.
0
Common
Most of the 9 edited versions we read keep these.
36
Distinctive
This author's own choices. Worth a look.
5
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Distinctive: line 9
Use this skill to read Claude Code cost and usage data from a local SQLite database.
- Distinctive: line 21
Use this skill when the user asks:
- Distinctive: line 34
Read local data only.
- Distinctive: line 35
Do not send usage data to any outside service.
- Distinctive: line 36
Do not install or run an unknown hook or plugin.
- Distinctive: line 37
Do not change or delete the database.
- Distinctive: line 38
Do not make up missing data.
- Distinctive: line 39
Do not show full session IDs unless the user asks.
- Distinctive: line 40
Do not treat tracked cost as an invoice.
- Distinctive: line 51
If SQLite is missing, say that it is needed to read the database.
- Distinctive: line 53
If the database is missing, do not create it.
- Distinctive: line 55
If the database cannot be read, report the file error.
- Very specific: line 66
If the usage table does not exist, inspect the listed tables and find the one that holds usage rows.
- Distinctive: line 81
Use only columns that exist.
- Very specific: line 83
Prefer cost_usd when it exists.
- Distinctive: line 91
Before a date report:
- Distinctive: line 93
Check a few timestamps.
- Distinctive: line 95
Use the user's local time if it can be done with clear data.
- Distinctive: line 96
If the time zone is not known, say that date totals may differ near midnight.
- Distinctive: line 132
Do not show a percent change when yesterday's cost is zero.
- Distinctive: line 201
Run this only when both token columns exist:
- Distinctive: line 216
If the user gives a budget, use the same date range for both spend and budget.
- Distinctive: line 233
Do not claim that a budget is stored unless the database has a budget table or field.
- Distinctive: line 237
Ask for the date range and output path if they are not clear.
- Distinctive: line 248
Do not export session IDs unless the user needs them.
- Distinctive: line 260
Check that SQLite and the database exist.
- Very specific: line 261
Check the usage table and its columns.
- Distinctive: line 262
Check the timestamp form and time zone.
- Distinctive: line 275
When the data allows it, include:
- Distinctive: line 283
Keep the report short. Put the main answer first.
- Distinctive: line 285
Use four decimal places for amounts under $1.
- Distinctive: line 291
Do not assume the database exists.
- Distinctive: line 292
Do not assume the table or column names.
- Very specific: line 293
Do not use SELECT * for a large report or export.
- Very specific: line 294
Do not use current model prices when cost_usd exists.
- Distinctive: line 295
Do not mix date ranges when checking a budget.
- Distinctive: line 296
Do not count blank session IDs as real sessions.
- Distinctive: line 297
Do not compare days without stating the time zone.
- Distinctive: line 298
Do not add costs from two databases unless the user asks.
- Distinctive: line 299
Do not hide null or missing cost rows.
- Distinctive: line 300
Do not suggest an untrusted hook or plugin that can run code.
“Common” is measured: kept by at least 6 in 10 of the 9 edited versions of this file we could read. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
Cost Tracking
Use this skill to read Claude Code cost and usage data from a local SQLite database.
This skill is for users who already have a trusted hook or plugin that writes usage data to:
~/.claude-cost-tracker/usage.dbCredit: This skill was recovered from community PR #1304 by MayurBhavsar.
When to Use
Use this skill when the user asks:
- How much did I spend?
- What did this session cost?
- How many tokens did I use?
- Am I over my budget?
- Which project, tool, session, or model costs the most?
- How does today compare with yesterday?
- What is my recent cost trend?
- Can I export recent usage as CSV?
Safety Rules
- Read local data only.
- Do not send usage data to any outside service.
- Do not install or run an unknown hook or plugin.
- Do not change or delete the database.
- Do not make up missing data.
- Do not show full session IDs unless the user asks.
- Do not treat tracked cost as an invoice. It may not match the final bill.
Check the Setup
First, check for SQLite and the database:
command -v sqlite3 >/dev/null && echo "sqlite3 available" || echo "sqlite3 missing"
test -f "$HOME/.claude-cost-tracker/usage.db" && echo "Database found" || echo "Database not found"If SQLite is missing, say that it is needed to read the database.
If the database is missing, do not create it. Tell the user that local cost tracking is not set up. Suggest that they enable a trusted local cost tracker.
If the database cannot be read, report the file error. Do not change its access rights without clear user approval.
Check the Schema
Trackers may use different table and column names. Check the real schema before running a report:
sqlite3 "$HOME/.claude-cost-tracker/usage.db" ".tables"
sqlite3 "$HOME/.claude-cost-tracker/usage.db" "PRAGMA table_info(usage);"If the usage table does not exist, inspect the listed tables and find the one that holds usage rows. Do not guess.
A common usage table has one row for each tool call or model event:
| Column | Meaning |
timestamp | Date and time of the event |
project | Project or repo name |
tool_name | Tool or event name |
input_tokens | Input token count |
output_tokens | Output token count |
cost_usd | Stored cost in US dollars |
session_id | Claude Code session ID |
model | Model used for the event |
Use only columns that exist.
Prefer cost_usd when it exists. Do not work out cost from token counts unless the user asks and gives a price list. Model prices and cache rules can change.
Some rows may have blank or null values. Group these as Unknown when useful.
Time Rules
SQLite uses UTC for date('now'). Stored times may use UTC or local time.
Before a date report:
- Check a few timestamps.
- State which time zone the report uses.
- Use the user's local time if it can be done with clear data.
- If the time zone is not known, say that date totals may differ near midnight.
Also check whether timestamps are text, Unix seconds, or Unix milliseconds. Change the query if needed.
Queries
Quick Summary
sqlite3 "$HOME/.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;
"Today and Yesterday
sqlite3 -header -column "$HOME/.claude-cost-tracker/usage.db" "
SELECT
ROUND(COALESCE(SUM(CASE
WHEN date(timestamp) = date('now') THEN cost_usd
END), 0), 4) AS today_usd,
ROUND(COALESCE(SUM(CASE
WHEN date(timestamp) = date('now', '-1 day') THEN cost_usd
END), 0), 4) AS yesterday_usd
FROM usage;
"Do not show a percent change when yesterday's cost is zero. Show the dollar change instead.
Cost by Project
sqlite3 -header -column "$HOME/.claude-cost-tracker/usage.db" "
SELECT
COALESCE(NULLIF(project, ''), 'Unknown') AS project,
ROUND(COALESCE(SUM(cost_usd), 0), 4) AS cost_usd,
COUNT(*) AS calls
FROM usage
GROUP BY COALESCE(NULLIF(project, ''), 'Unknown')
ORDER BY cost_usd DESC
LIMIT 20;
"Cost by Tool
sqlite3 -header -column "$HOME/.claude-cost-tracker/usage.db" "
SELECT
COALESCE(NULLIF(tool_name, ''), 'Unknown') AS tool,
ROUND(COALESCE(SUM(cost_usd), 0), 4) AS cost_usd,
COUNT(*) AS calls
FROM usage
GROUP BY COALESCE(NULLIF(tool_name, ''), 'Unknown')
ORDER BY cost_usd DESC
LIMIT 20;
"Last 7 Calendar Days
sqlite3 -header -column "$HOME/.claude-cost-tracker/usage.db" "
SELECT
date(timestamp) AS day,
ROUND(COALESCE(SUM(cost_usd), 0), 4) AS cost_usd,
COUNT(*) AS calls
FROM usage
WHERE timestamp >= datetime('now', '-7 days')
GROUP BY date(timestamp)
ORDER BY day DESC;
"This query skips days with no rows. Say so if the user asks for a daily chart.
Recent Sessions
sqlite3 -header -column "$HOME/.claude-cost-tracker/usage.db" "
SELECT
substr(session_id, 1, 8) || '...' AS session,
MIN(timestamp) AS started,
MAX(timestamp) AS ended,
ROUND(COALESCE(SUM(cost_usd), 0), 4) AS cost_usd,
COUNT(*) AS calls
FROM usage
WHERE session_id IS NOT NULL AND session_id != ''
GROUP BY session_id
ORDER BY started DESC
LIMIT 10;
"Token Totals
Run this only when both token columns exist:
sqlite3 -header -column "$HOME/.claude-cost-tracker/usage.db" "
SELECT
COALESCE(SUM(input_tokens), 0) AS input_tokens,
COALESCE(SUM(output_tokens), 0) AS output_tokens,
COALESCE(SUM(input_tokens), 0) +
COALESCE(SUM(output_tokens), 0) AS total_tokens
FROM usage;
"Budget Check
If the user gives a budget, use the same date range for both spend and budget.
sqlite3 "$HOME/.claude-cost-tracker/usage.db" "
SELECT ROUND(COALESCE(SUM(cost_usd), 0), 4)
FROM usage
WHERE timestamp >= datetime('now', 'start of month');
"Report:
- Budget amount
- Spend in the same time range
- Money left, or amount over
- Percent used when the budget is above zero
Do not claim that a budget is stored unless the database has a budget table or field.
Safe CSV Export
Ask for the date range and output path if they are not clear. Export only the needed columns and rows:
sqlite3 -header -csv "$HOME/.claude-cost-tracker/usage.db" "
SELECT timestamp, project, tool_name, input_tokens, output_tokens, cost_usd, model
FROM usage
WHERE timestamp >= datetime('now', '-7 days')
ORDER BY timestamp;
" > ./usage-last-7-days.csvDo not export session IDs unless the user needs them. Do not overwrite a file without clear approval.
Concrete Example
User request:
How much did I spend this week, and which project cost the most?Steps:
- Check that SQLite and the database exist.
- Check the
usagetable and its columns. - Check the timestamp form and time zone.
- Sum
cost_usdfor the chosen week. - Group the same rows by project.
- Report the total, top project, date range, and time zone.
Example answer:
You spent $3.4821 from Monday through today. Project `website` cost the most at $2.1044. The report uses UTC dates from the local tracker. These values are tracked estimates and may not match the final bill.Report Format
When the data allows it, include:
- Today's spend and yesterday's spend.
- Total spend for the asked date range.
- Top projects by cost.
- Top tools by cost.
- Session count and average cost per session.
Keep the report short. Put the main answer first.
Use four decimal places for amounts under $1. Use two decimal places for larger amounts. State the currency as USD.
Say when data is missing, blank, or incomplete. If no rows match the date range, report zero matching rows. Do not claim that usage was zero unless tracking was active for that whole time.
Common Problems
- Do not assume the database exists.
- Do not assume the table or column names.
- Do not use
SELECT *for a large report or export. - Do not use current model prices when
cost_usdexists. - Do not mix date ranges when checking a budget.
- Do not count blank session IDs as real sessions.
- Do not compare days without stating the time zone.
- Do not add costs from two databases unless the user asks.
- Do not hide null or missing cost rows. Note them in the report.
- Do not suggest an untrusted hook or plugin that can run code.
Related Skills
/cost-report: Command-style reports from the same database.cost-aware-llm-pipeline: Plans model use and budgets.token-budget-advisor: Plans context and token limits.strategic-compact: Cuts repeat token use by making context smaller.
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

