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

cost-session

它能做什么

这项技能逐条消息地拆解一次 AI 会话,显示哪些回复花费最多。适合想弄清楚某次会话为什么昂贵的人。

适用场景

  • ✓当某次会话被标记为异常昂贵,你想知道原因时。
  • ✓当你想查看最近一次会话中花费最多的消息时。
  • ✓当你想知道缓存写入是否造成了大部分成本时。

技能链接

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

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

使用方法

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

可直接粘贴的消息

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

可以这样问 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.

  1. Resolve session jsonl: --session-id <id> (scans ~/.claude/projects/*/) or --latest (default; picks most-recently-modified jsonl).
  2. Parse all assistant messages with usage blocks.
  3. Cost each message via shared PRICING (_prices.mjs).
  4. Sort descending by cost_usd, surface top-N (default 20).
  5. Compute p50/p90/p99 of message costs for in-session percentile context.
  6. 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-id not found in any project's jsonls → exit 2 with error.
  • --top must 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

这个技能有用吗?

0

登录 后即可投票。

评论

  • …

同一仓库的更多技能

相似技能