跳到正文
Skillpedia
其他81k · #1611

cost-track

它能做什么

这项技能读取你当前 AI 编程会话的日志,并保存其令牌用量和成本记录。适合希望长期追踪 AI 支出的人。

适用场景

  • ✓当你完成一大块工作,想记录它花了多少钱时。
  • ✓当你想在会话结束时保存最终合计时。
  • ✓当你在一次长会话中希望按计划检查支出时。

技能链接

https://github.com/ruvnet/ruflo/blob/main/plugins/ruflo-cost-tracker/skills/cost-track/SKILL.md

复制后粘贴给你的 AI(Claude、ChatGPT 或 Cursor),让它按照说明操作。

使用方法

最简单的方法:复制下面的消息,粘贴给你的 AI。它会读取这个技能并按说明操作。

可直接粘贴的消息

请用这个技能帮我:https://github.com/ruvnet/ruflo/blob/main/plugins/ruflo-cost-tracker/skills/cost-track/SKILL.md 阅读该链接中的 SKILL.md 文件,并在我的任务中按照它的说明来做。
想让你的 AI 自己找到这样的技能吗?安装免费的 Skillpedia MCP:只需一行,每次任务前它都会在 15,000+ 个技能中搜索。1 分钟完成安装 →

可以这样问 AI

“请记录这次会话花了多少钱,方便我之后在报告中查看。”

每周 5 个新技能,1 分钟读完。

工作原理

这项技能找到当前会话日志,将每个模型的令牌用量相加,根据价格表计算成本,并保存合计。你也可以以试运行方式运行它,此时不保存任何内容。

技术内容(原始 SKILL.md)

作者在 GitHub 上的英文原文。

Cost Track

Reads the active Claude Code session jsonl (~/.claude/projects/<encoded-cwd>/<session>.jsonl), tallies assistant-message usage per model, computes USD cost using REFERENCE.md pricing, and writes a structured record to the cost-tracking AgentDB namespace. This is the producer that gives cost-report and cost-optimize real data to consume.

When to use

  • After a meaningful chunk of work, to capture spend for the report.
  • At session-end to persist the final tally.
  • Periodically during long sessions (cron-friendly — see /loop 30m).

Steps

  1. Run the tracker from the project root:

    node plugins/ruflo-cost-tracker/scripts/track.mjs
    

    The script auto-discovers the session jsonl from the current working directory. To pin a specific session: TRACK_SESSION=/path/to/session.jsonl. To dry-run (no memory write): TRACK_DRY_RUN=1.

  2. Inspect the markdown summary — total cost, per-model and per-tier breakdowns, and the persisted memory key.

  3. Verify persistence — mcp__plugin_ruflo-core_ruflo__memory_search({ query: "session-", namespace: "cost-tracking" }) should list the new record. cost-report step 1 reads from this namespace.

Record shape (in cost-tracking namespace)

Key: session-<sessionId>. Value (JSON):

{
  "sessionId": "1dba3b8c-...",
  "cwd": "/Users/cohen/Projects/ruflo",
  "startedAt": "2026-05-04T...",
  "endedAt": "2026-05-05T...",
  "messageCount": 234,
  "byModel": {
    "claude-opus-4-7": {
      "tier": "opus",
      "input_tokens": 12345,
      "output_tokens": 6789,
      "cache_creation_input_tokens": 800000,
      "cache_read_input_tokens": 2000000,
      "messages": 50,
      "cost_usd": 1.23
    }
  },
  "byTier": { "haiku": 0.0, "sonnet": 0.45, "opus": 1.23, "unknown": 0 },
  "total_cost_usd": 1.68,
  "capturedAt": "2026-05-05T..."
}

Pricing source of truth

The script's PRICING constant mirrors REFERENCE.md "Model pricing (USD per 1M tokens)". Update both together when prices change. Cache-write tokens are billed at cache_write rate; cache-read tokens at cache_read (per Anthropic billing docs).

Env overrides

Env Default Purpose
TRACK_CWD process.cwd() Override which project's sessions to scan
TRACK_SESSION most-recent jsonl Pin a specific session file
TRACK_OUT unset Also write the JSON summary to this path
TRACK_DRY_RUN=1 unset Skip the memory store call
TRACK_QUIET=1 unset Suppress markdown output
TRACK_NAMESPACE cost-tracking Override target namespace

Cross-references

  • cost-report (consumer) — reads records produced by this skill
  • REFERENCE.md "Cost attribution formula" — the math the script implements
  • cost-budget-check (consumer; landing in P2) — reads totals to evaluate alerts
常见问题

会话日志在哪里找到?

除非你指定文件,否则它会在你正在工作的项目对应的 Claude Code 文件夹中查找。

我能不保存就测试吗?

可以。试运行设置会打印结果,但不会向记忆中写入任何内容。

哪个报告会用到这些数据?

成本报告和成本优化技能会读取这项技能保存的记录。

详情

作者的原始描述

Auto-capture per-session token usage from the Claude Code session jsonl and persist to the cost-tracking namespace

repo: ruvnet/ruflo

热度

GitHub 星标
81k
排名
#1611
许可证
MIT
更新时间
2026/11/2

这个技能有用吗?

0

登录 后即可投票。

评论

  • …

同一仓库的更多技能

相似技能