cost-tracking

GitHub

用于分析本地SQLite数据库中的Claude Code令牌用量、花费和预算。支持按项目、工具、会话或日期查询成本,提供快速摘要、趋势分析及CSV导出功能,帮助用户监控和管理AI使用成本。

data/skills-md/affaan-m/everything-claude-code/cost-tracking/SKILL.md NeverSight/learn-skills.dev

Trigger Scenarios

用户询问花费金额或代币用量 用户提及预算、支出限制或成本控制 用户要求按项目、工具、会话或日期进行成本分解 用户希望比较不同时间段的使用情况

Install

npx skills add NeverSight/learn-skills.dev --skill cost-tracking -g -y
More Options

Non-standard path

npx skills add https://github.com/NeverSight/learn-skills.dev/tree/main/data/skills-md/affaan-m/everything-claude-code/cost-tracking -g -y

Use without installing

npx skills use NeverSight/learn-skills.dev@cost-tracking

指定 Agent (Claude Code)

npx skills add NeverSight/learn-skills.dev --skill cost-tracking -a claude-code -g -y

安装 repo 全部 skill

npx skills add NeverSight/learn-skills.dev --all -g -y

预览 repo 内 skill

npx skills add NeverSight/learn-skills.dev --list

SKILL.md

Frontmatter
{
    "name": "cost-tracking",
    "origin": "community",
    "description": "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."
}

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.

Related

  • /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.

Version History

  • e0220ca Current 2026-07-05 23:53

Same Skill Collection

data/skills-md/00prabalk00/claude-skills/knowledge-base-gap-finder/SKILL.md
data/skills-md/01000001-01001110/agent-jira-skills/jira-agile/SKILL.md
data/skills-md/01000001-01001110/agent-jira-skills/jira-auth/SKILL.md
data/skills-md/01000001-01001110/agent-jira-skills/jira-issues/SKILL.md
data/skills-md/01000001-01001110/agent-jira-skills/jira-project-management/SKILL.md
data/skills-md/01000001-01001110/agent-jira-skills/jira-projects/SKILL.md
data/skills-md/01000001-01001110/agent-jira-skills/jira-safe/SKILL.md
data/skills-md/01000001-01001110/agent-jira-skills/jira-search/SKILL.md
data/skills-md/01000001-01001110/agent-jira-skills/jira-spaces/SKILL.md
data/skills-md/01000001-01001110/agent-jira-skills/jira-transitions/SKILL.md
data/skills-md/0731coderlee-sudo/wechat-publisher/wechat-publisher/SKILL.md
data/skills-md/0froq/skills/conventionalcommits/SKILL.md
data/skills-md/0froq/skills/nuxt/SKILL.md
data/skills-md/0froq/skills/oq/SKILL.md
data/skills-md/0froq/skills/pinia/SKILL.md
data/skills-md/0froq/skills/pnpm/SKILL.md
data/skills-md/0froq/skills/slidev/SKILL.md
data/skills-md/0froq/skills/tsdown/SKILL.md
data/skills-md/0froq/skills/turborepo/SKILL.md
data/skills-md/0froq/skills/unocss/SKILL.md
data/skills-md/0froq/skills/vitepress/SKILL.md
data/skills-md/0froq/skills/vitest/SKILL.md
data/skills-md/0froq/skills/vue-best-practices/SKILL.md
data/skills-md/0froq/skills/vue-router-best-practices/SKILL.md
data/skills-md/0froq/skills/vue-testing-best-practices/SKILL.md
data/skills-md/0froq/skills/vue/SKILL.md
data/skills-md/0froq/skills/vueuse-functions/SKILL.md
data/skills-md/0froq/skills/web-design-guidelines/SKILL.md
data/skills-md/0juano/agent-skills/bondterminal-x402/SKILL.md
data/skills-md/0juano/agent-skills/edgeone-pages-deploy/SKILL.md
data/skills-md/0juano/agent-skills/ley-ar/SKILL.md
data/skills-md/0juano/agent-skills/ticktick/SKILL.md
data/skills-md/0juano/agent-skills/x-image-cards/SKILL.md
data/skills-md/0juano/x-image-cards/x-image-cards/SKILL.md
data/skills-md/0x0funky/agent-sprite-forge/generate2dsprite/SKILL.md
data/skills-md/0x0funky/agent-sprite-forge/video2dsprite/SKILL.md
data/skills-md/0x2e/superpowers/brainstorming/SKILL.md
data/skills-md/0x2e/superpowers/dispatching-parallel-agents/SKILL.md
data/skills-md/0x2e/superpowers/executing-plans/SKILL.md
data/skills-md/0x2e/superpowers/finishing-a-development-branch/SKILL.md
data/skills-md/0x2e/superpowers/receiving-code-review/SKILL.md
data/skills-md/0x2e/superpowers/requesting-code-review/SKILL.md
data/skills-md/0x2e/superpowers/subagent-driven-development/SKILL.md
data/skills-md/0x2e/superpowers/systematic-debugging/SKILL.md
data/skills-md/0x2e/superpowers/test-driven-development/SKILL.md
data/skills-md/0x2e/superpowers/using-git-worktrees/SKILL.md
data/skills-md/0x2e/superpowers/using-superpowers/SKILL.md
data/skills-md/0x2e/superpowers/verification-before-completion/SKILL.md
data/skills-md/0x2e/superpowers/writing-plans/SKILL.md
data/skills-md/0x2e/superpowers/writing-skills/SKILL.md

Metadata

Files
0
Version
e4a0f95
Hash
c48d78c1
Indexed
2026-07-05 23:53

Accueil - Wiki
Copyright © 2011-2026 iteam. Current version is 2.155.2. UTC+08:00, 2026-08-09 18:24
浙ICP备14020137号-1 $Carte des visiteurs$