cost-tracking
Skill0 starsChanged 2 months agoMITView on GitHub
Track and report Claude Code token use, cost, and budgets from a local cost database. Use for questions about cost, spend, usage, tokens, budgets, or cost by project, tool, session, model, or date.
6 other projects use a version of this, 3 of them edited.
Adopted by
Most recently taken up by
- 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
- Fmarzochi/EGCedited, first seen Sep 16, 2026
- SamuelNDCE/claude-super-skill-libraryedited, first seen Aug 1, 2026
Other versions6 projects use a version of this.
Word for word · 0
None found.
Edited · 3
- Fmarzochi/EGC★ 6115% same
- SamuelNDCE/claude-super-skill-library★ 116% same
- davidanthonyn/claude-skills★ 016% same
Wrote their own version · 3
- gongyijie85/dsh-ecc★ 8same name
- airshell/ai-optimizer★ 2same name
- renepf/claude-skills★ 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
39 rules. 0 are common, 33 are distinctive, and 6 are very specific to this project.
0
Common
Most of the 6 edited versions we read keep these.
33
Distinctive
This author's own choices. Worth a look.
6
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Distinctive: line 11
Use this skill to read Claude Code cost and usage data from a local SQLite database.
- Distinctive: line 23
Use this skill when the user asks:
- Distinctive: line 36
Check for SQLite and the database:
- Distinctive: line 43
If SQLite is missing, say that it is needed to read the file.
- Distinctive: line 45
If the database is missing:
- Distinctive: line 47
Do not make fake usage data.
- Distinctive: line 50
Do not install a hook or plug-in unless the user asks.
- Distinctive: line 51
Do not suggest code that sends usage data to the web.
- Very specific: line 62
Do not assume the table is named usage.
- Distinctive: line 77
Use only columns that exist.
- Very specific: line 79
If cost_usd exists, use it.
- Very specific: line 81
If cost_usd does not exist, report token use only.
- Distinctive: line 86
Never change, delete, or add rows.
- Distinctive: line 87
Do not print full session IDs unless the user asks.
- Distinctive: line 88
Treat project names and session IDs as private data.
- Very specific: line 89
Use COALESCE so missing values do not break totals.
- Distinctive: line 91
Check how timestamps are stored before using date filters.
- Distinctive: line 93
Do not place raw user text inside SQL.
- Distinctive: line 94
Use a fixed limit for row lists and exports.
- Distinctive: line 95
If the database is locked or damaged, report the error.
- Distinctive: line 96
If there are no rows, say that no tracked use was found.
- Distinctive: line 202
Use this only when the token columns exist:
- Distinctive: line 216
Ask for the date range if the user did not give one.
- Distinctive: line 239
If the user gives a budget, compare it with the matching time range.
- Distinctive: line 250
Do not treat a budget as saved unless the database has a clear budget table or column.
- Distinctive: line 266
Use four digits after the decimal for costs under $1.
- Distinctive: line 268
Do not call a row a model call until the table proves that it is one.
- Distinctive: line 280
Check that SQLite and the database exist.
- Distinctive: line 281
Read the table shape.
- Distinctive: line 282
Check the timestamp form and time zone.
- Very specific: line 299
Do not guess costs when cost_usd is present.
- Distinctive: line 300
Do not use live model prices in the report.
- Distinctive: line 301
Do not assume the database or table exists.
- Very specific: line 302
Do not run an open-ended SELECT * on a large table.
- Distinctive: line 303
Do not change the database.
- Distinctive: line 304
Do not hide missing or bad data.
- Distinctive: line 305
Do not install unreviewed hooks or plug-ins.
- Distinctive: line 306
Do not send local cost data to any outside service.
- Distinctive: line 307
Do not add analytics, telemetry, or web calls.
“Common” is measured: kept by at least 6 in 10 of the 6 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
Credit: This skill comes from community PR #1304 by MayurBhavsar.
Use this skill to read Claude Code cost and usage data from a local SQLite database.
The normal database path is:
~/.claude-cost-tracker/usage.dbThis skill only reads local data. Do not send data outside the computer. Do not add tracking, logs, web calls, or other data collection.
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, model, or session costs the most?
- How does today compare with yesterday?
- What is my recent cost trend?
- Can I export recent use as CSV?
First Checks
Check for SQLite and the database:
command -v sqlite3 >/dev/null && echo "sqlite3 found" || 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 file.
If the database is missing:
- Do not make fake usage data.
- Say that local cost tracking is not set up.
- Suggest a trusted local cost tracker.
- Do not install a hook or plug-in unless the user asks.
- Do not suggest code that sends usage data to the web.
Check the Data Shape
Trackers may use different table and column names. Check the real shape before you run a report:
sqlite3 -readonly "$HOME/.claude-cost-tracker/usage.db" ".tables"
sqlite3 -readonly "$HOME/.claude-cost-tracker/usage.db" "PRAGMA table_info(usage);"Do not assume the table is named usage. If it has another name, use that name.
A common usage table has one row for each model event or tool call:
| 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 | Saved cost in US dollars |
session_id | Claude Code session ID |
model | Model used for the event |
Use only columns that exist.
If cost_usd exists, use it. Do not work out the cost from token counts. Model and cache prices can change. The saved row cost should be the main source.
If cost_usd does not exist, report token use only. Explain that exact cost is not stored. Do not guess the price.
Safe Query Rules
- Open the database in read-only mode.
- Never change, delete, or add rows.
- Do not print full session IDs unless the user asks. A short prefix is often enough.
- Treat project names and session IDs as private data.
- Use
COALESCEso missing values do not break totals. - Say when key values are missing or
NULL. - Check how timestamps are stored before using date filters.
- State whether dates use UTC or local time.
- Do not place raw user text inside SQL.
- Use a fixed limit for row lists and exports.
- If the database is locked or damaged, report the error. Do not try to repair it unless the user asks.
- If there are no rows, say that no tracked use was found.
The examples below use the common usage table and column names. Change them only after checking the real data shape.
Report Examples
Quick Summary
sqlite3 -readonly "$HOME/.claude-cost-tracker/usage.db" "
SELECT
'Today: \$' ||
ROUND(COALESCE(SUM(
CASE WHEN date(timestamp, 'localtime') = date('now', 'localtime')
THEN COALESCE(cost_usd, 0) ELSE 0 END
), 0), 4) ||
' | Total: \$' ||
ROUND(COALESCE(SUM(COALESCE(cost_usd, 0)), 0), 4) ||
' | Rows: ' || COUNT(*) ||
' | Sessions: ' || COUNT(DISTINCT session_id)
FROM usage;
"Today and Yesterday
sqlite3 -readonly -header -column "$HOME/.claude-cost-tracker/usage.db" "
SELECT
date(timestamp, 'localtime') AS day,
ROUND(SUM(COALESCE(cost_usd, 0)), 4) AS cost_usd,
COUNT(*) AS rows
FROM usage
WHERE date(timestamp, 'localtime') IN (
date('now', 'localtime'),
date('now', 'localtime', '-1 day')
)
GROUP BY day
ORDER BY day DESC;
"Cost by Project
sqlite3 -readonly -header -column "$HOME/.claude-cost-tracker/usage.db" "
SELECT
COALESCE(project, '(not set)') AS project,
ROUND(SUM(COALESCE(cost_usd, 0)), 4) AS cost_usd,
COUNT(*) AS rows
FROM usage
GROUP BY project
ORDER BY cost_usd DESC
LIMIT 20;
"Cost by Tool
sqlite3 -readonly -header -column "$HOME/.claude-cost-tracker/usage.db" "
SELECT
COALESCE(tool_name, '(not set)') AS tool,
ROUND(SUM(COALESCE(cost_usd, 0)), 4) AS cost_usd,
COUNT(*) AS rows
FROM usage
GROUP BY tool_name
ORDER BY cost_usd DESC
LIMIT 20;
"Last Seven Days
sqlite3 -readonly -header -column "$HOME/.claude-cost-tracker/usage.db" "
SELECT
date(timestamp, 'localtime') AS day,
ROUND(SUM(COALESCE(cost_usd, 0)), 4) AS cost_usd,
COUNT(*) AS rows
FROM usage
WHERE datetime(timestamp) >= datetime('now', '-7 days')
GROUP BY day
ORDER BY day DESC;
"Recent Sessions
sqlite3 -readonly -header -column "$HOME/.claude-cost-tracker/usage.db" "
SELECT
substr(COALESCE(session_id, '(not set)'), 1, 12) AS session,
MIN(timestamp) AS started,
MAX(timestamp) AS ended,
ROUND(SUM(COALESCE(cost_usd, 0)), 4) AS cost_usd,
COUNT(*) AS rows
FROM usage
GROUP BY session_id
ORDER BY started DESC
LIMIT 10;
"Token Totals
Use this only when the token columns exist:
sqlite3 -readonly -header -column "$HOME/.claude-cost-tracker/usage.db" "
SELECT
SUM(COALESCE(input_tokens, 0)) AS input_tokens,
SUM(COALESCE(output_tokens, 0)) AS output_tokens,
SUM(COALESCE(input_tokens, 0) + COALESCE(output_tokens, 0)) AS total_tokens
FROM usage;
"Small CSV Export
Ask for the date range if the user did not give one. Keep the export small.
sqlite3 -readonly -header -csv "$HOME/.claude-cost-tracker/usage.db" "
SELECT
timestamp,
project,
tool_name,
input_tokens,
output_tokens,
cost_usd,
model
FROM usage
WHERE datetime(timestamp) >= datetime('now', '-7 days')
ORDER BY timestamp DESC
LIMIT 10000;
" > cost-usage-last-7-days.csvTell the user where the file was saved. Do not include full session IDs unless they ask.
Budget Checks
If the user gives a budget, compare it with the matching time range.
Report:
- The budget
- The amount spent
- The amount left
- The percent used
- The date range and time zone
- Whether the user is over budget
Do not treat a budget as saved unless the database has a clear budget table or column.
What to Report
A full report should include:
- Today’s spend.
- Yesterday’s spend.
- The change from yesterday, when both days have data.
- Total spend in the tracked database.
- The top projects by cost.
- The top tools by cost.
- Session count and mean cost per session, when session IDs exist.
- The date range and time zone used.
- Any missing fields or gaps that may make the report less exact.
Use four digits after the decimal for costs under $1. Use two digits for larger costs.
Do not call a row a model call until the table proves that it is one. Some trackers also save tool events. Use the word “row” or “event” when unsure.
Concrete Usage Example
User:
How much did I spend this week, and which project cost the most?Steps:
- Check that SQLite and the database exist.
- Read the table shape.
- Check the timestamp form and time zone.
- Sum
cost_usdfor the last seven days. - Group the same rows by project.
- Show the top project and its share of the week’s cost.
Example reply:
You spent $2.1843 in the last 7 days, using local time.
The top project was `shop-app` at $1.3021. That was 59.6% of the total.
The database had 184 rows across 9 sessions. Two rows had no project name, so I grouped them as `(not set)`.Do Not
- Do not guess costs when
cost_usdis present. - Do not use live model prices in the report.
- Do not assume the database or table exists.
- Do not run an open-ended
SELECT *on a large table. - Do not change the database.
- Do not hide missing or bad data.
- Do not install unreviewed hooks or plug-ins.
- Do not send local cost data to any outside service.
- Do not add analytics, telemetry, or web calls.
Related Skills
/cost-report: A command-style report from the same database.cost-aware-llm-pipeline: Plans model use and budgets.token-budget-advisor: Plans token and context 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.

