cost-session
它能做什么
这项技能逐条消息地拆解一次 AI 会话,显示哪些回复花费最多。适合想弄清楚某次会话为什么昂贵的人。
适用场景
- ✓当某次会话被标记为异常昂贵,你想知道原因时。
- ✓当你想查看最近一次会话中花费最多的消息时。
- ✓当你想知道缓存写入是否造成了大部分成本时。
技能链接
https://github.com/ruvnet/ruflo/blob/main/plugins/ruflo-cost-tracker/skills/cost-session/SKILL.md复制后粘贴给你的 AI(Claude、ChatGPT 或 Cursor),让它按照说明操作。
使用方法
最简单的方法:复制下面的消息,粘贴给你的 AI。它会读取这个技能并按说明操作。
可直接粘贴的消息
适用于 Claude Code、Codex 或 Cursor:在项目文件夹中运行,即可安装该技能。
下载 SKILL.md,放进智能体的技能文件夹。
可以这样问 AI
“我上一次 AI 会话中哪些消息花费最多?为什么?”
每周 5 个新技能,1 分钟读完。
工作原理
这项技能读取会话日志,按每条回复所用的令牌类型为其定价,并将回复按成本从高到低排序。它还会标记出明显高于该会话典型成本的回复。
技术内容(原始 SKILL.md)
作者在 GitHub 上的英文原文。
When cost-anomaly flags a session as a >3.5σ outlier, the next question is "which MESSAGES were expensive?". cost-session answers that.
| Question | Skill |
|---|---|
| "Which sessions cost the most?" | cost-conversation |
| "Which sessions are outliers?" | cost-anomaly |
| "Which messages in THIS session were expensive?" | cost-session ← this |
Algorithm
Implementation: scripts/session.mjs.
- Resolve session jsonl:
--session-id <id>(scans~/.claude/projects/*/) or--latest(default; picks most-recently-modified jsonl). - Parse all assistant messages with
usageblocks. - Cost each message via shared PRICING (
_prices.mjs). - Sort descending by
cost_usd, surface top-N (default 20). - Compute p50/p90/p99 of message costs for in-session percentile context.
- Flag the top message if it's >2× the p99 — that's an in-session outlier.
Why this matters: cache writes are the silent cost
Example real session, top message:
| # | Model | In | Out | Cache W | Cache R | Cost |
| 1 | opus-4-7 | 6 | 569 | 881898 | 0 | $16.58 |
Without the Cache W column it looks like "569 output tokens cost $16" — that's wrong by 380×. The actual cost is ephemeral 1h cache write at opus pricing: 881,898 tokens × $18.75/1M = $16.54.
Operators reading the table see immediately: "the model wrote 881K tokens to ephemeral cache". From there the question becomes "why did we cache 881K tokens of context for a 6-input request?" — that's a real engineering signal.
Drill-down workflow
# Step 1: find outliers across all sessions
cost anomaly --alert-on-outliers 1 || cost anomaly # see which session-ids
# Step 2: drill into the flagged session
cost session --session-id <flagged-id> --top 10
# Step 3: open that jsonl at the timestamp the top message reports,
# inspect the prompt + tool calls
Percentile context
Top of output:
| p50 (median) message | $0.85 |
| p90 message | $1.45 |
| p99 message | $1.74 |
Lets operators ask "is this top message a 2× outlier or a 380× one?" without having to compute it themselves. The "top is >2× p99" footer fires when the answer is "yes, this is an in-session outlier worth investigating".
--since filter
Useful for drilling into a specific time range within a long session:
cost session --since 2026-06-16T13:00:00Z --top 5
Only messages with timestamp >= --since are considered.
Edge cases
- No costed assistant messages → "No costed assistant messages" + exit 0.
--session-idnot found in any project's jsonls → exit 2 with error.--topmust be a positive integer → exit 2.
常见问题
我可以指定某次会话吗?
可以。你可以提供会话 ID;默认情况下,它会使用最近修改过的会话。
它默认显示多少条消息?
默认显示成本最高的前 20 条,你也可以选择其他数量。
为什么缓存写入很重要?
如果只看输出的大小,缓存写入可能带来很大成本,且很容易被忽略。
详情
作者的原始描述
Per-message cost breakdown within a single session. The drill-down companion to cost-anomaly — when an outlier session is flagged, this surfaces the specific expensive messages so operators can see whether the cost came from output tokens, cache writes, or model escalations.
repo: ruvnet/ruflo
热度
- GitHub 星标
- 81k
- 排名
- #1609
- 许可证
- MIT
- 更新时间
- 2026/11/2
评论
- …
同一仓库的更多技能
agent-adaptive-coordinator
81k帮你的智能体在工作量变化时拆分和重新平衡一组 AI 智能体,并选择适合任务的分工方式。
agent-agent
81k教你的智能体把一个大目标拆成有顺序的行动计划,并在情况变化时重新规划。
agent-agentic-payments
81k帮你的智能体管理 AI 购物的消费授权,包括消费上限、时间窗口、商户规则和签名审批。
agent-analyze-code-quality
81k帮你的智能体检查代码质量,找出代码异味、技术债务和重构建议,且不改动文件。