cost-anomaly
できること
このスキルは、ほかのセッションと比べて支出が通常よりはるかに多いAIセッションを見つけます。どのセッションがコストの急増を引き起こしたのかを知りたい人向けです。
使う場面
- ✓1つのAIセッションが、ほかよりずっと高いコストだったように見えるとき。
- ✓履歴全体で、異常に高いセッションの一覧がほしいとき。
- ✓異常なセッションが現れたら失敗させる確認を行いたいとき。
スキルのリンク
https://github.com/ruvnet/ruflo/blob/main/plugins/ruflo-cost-tracker/skills/cost-anomaly/SKILL.mdコピーしてAI(Claude、ChatGPT、Cursor)に貼り付け、指示に従うよう頼んでください。
使い方
いちばん簡単な方法:メッセージをコピーしてAIに貼り付けるだけ。AIがスキルを読んで指示に従います。
貼り付け用メッセージ
Claude Code、Codex、Cursorの場合:プロジェクトのフォルダで実行するとスキルがインストールされます。
SKILL.mdをダウンロードして、エージェントのスキル用フォルダに入れてください。
AIへの頼み方の例
“AIのセッションのうち、ほかよりずっと高い費用がかかったものはどれですか?”
毎週5つの新しいスキル。1分で読めます。
仕組み
スキルは、各セッションの支出を典型的な支出と比べます。1つの大きなセッションに大きく左右されにくい方法を使います。他より大きく突出しているセッションが、スコア付きで一覧になります。
技術的な内容(元のSKILL.md)
作者による元のテキスト(英語)をGitHubからそのまま表示しています。
Per-session outlier detection — the diagnostic counterpart to cost-burn's aggregate-trend signal.
| Question | Skill |
|---|---|
| "Is the AGGREGATE rate accelerating?" | cost-burn |
| "Which SPECIFIC sessions are anomalous outliers?" | cost-anomaly ← this |
| "Could we have spent less in aggregate?" | cost-counterfactual |
| "When will we hit budget?" | cost-projection |
Algorithm
Implementation: scripts/anomaly.mjs.
- Read all
session-*records fromcost-trackingnamespace. - Filter to
--sincewindow (default: all-time). - Compute
median(total_cost_usd)andMAD = median(|x - median|). - Per-session modified z-score (Iglewicz-Hoaglin 1993):
z = 0.6745 * (x - median) / MAD - Flag sessions with
|z| > --threshold(default 3.5).
Why MAD and not mean + sigma?
| Approach | What breaks |
|---|---|
mean + sigma |
A single $50 session inflates BOTH mean and sigma so badly that subsequent outliers hide inside the new "normal" band. Catastrophic on small samples. |
median + MAD |
Both estimators ignore up to 50% of the data — the outliers themselves can't shift them. Robust on n=10. The canonical cutoff |z| > 3.5 is from Iglewicz-Hoaglin (1993). |
Smoke transcript (5 baseline sessions $0.08-$0.12 + 1 outlier $5.00)
| Sessions considered | 5 |
| Threshold (|modified z|) | 3.5 |
| Median spend | $0.100000 |
| MAD | $0.010000 |
| Min / Max | $0.080000 / $5.000000 |
| **Outliers found** | **1** |
## Outlier sessions
| Session | Spend | Deviation | Modified z | Direction |
| outlier- | $5.000000 | +$4.900000 | 330.505 | high |
Exit codes
$ cost anomaly --alert-on-outliers 1
⚠ ALERT: found 1 outlier session(s) (|modified z| > 3.5); threshold was ≥1
exit 1
$ cost anomaly --alert-on-outliers 5
✓ found 1 outlier session(s); under threshold ≥5 — OK
exit 0
CI integration
# Fail the build if any session this week is a >3.5σ outlier
cost anomaly --since 7d --alert-on-outliers 1 || investigate-bad-session
Most useful when paired with cost-burn:
cost burn --alert-on-acceleration-pct 50 || page-oncall # rate-of-change alert
cost anomaly --alert-on-outliers 1 || investigate # point-anomaly alert
Together they cover "is the average shifting?" AND "is there a single rogue session?" — both can fire independently.
Edge cases
- n < 3: emit "Insufficient data" message, exit 0. MAD on 1-2 samples is meaningless.
- MAD = 0: ≥50% of sessions share the exact same spend, so z-scores collapse. Emit explainer instead of dividing by zero. Common cause: dry-run sessions all at $0.
- Low-direction outliers: usually crashed or dropped sessions, not over-spending. The output table explicitly labels direction so operators interpret correctly.
- Very small MAD: even tiny absolute deviations produce huge z-scores. The $5 outlier with MAD=$0.01 yields z=330 — that's correct, not a bug.
Direction column
| Direction | Likely cause | Action |
|---|---|---|
high |
Long session, stuck in expensive tier, or runaway loop | cost report + cost conversation to investigate |
low |
Crash, dropped session, or unfinished work | Verify the session completed normally |
よくある質問
何を外れ値とみなしますか?
デフォルトでは、スコアが3.5を超えるセッションが印付けされます。実行時に、この上限を変更できます。
なぜ高かったのか示しますか?
直接は示しません。外れ値のセッションを指摘するだけです。関連スキルを使うと、そのセッションをメッセージごとに分解できます。
確認を自動で失敗させられますか?
はい。任意の設定で、外れ値があるとエラーコードを返すようにできます。これは自動化された確認で役立ちます。
詳細
作者による元の説明
MAD-based outlier detection on session spend: lists anomalous sessions with modified-z scores, with an optional --alert-on-outliers exit code for CI. Use when asked which individual session is the cost outlier; cost-burn covers the aggregate trend.
repo: ruvnet/ruflo
人気
- GitHubのスター
- 81k
- ランキング
- #1591
- ライセンス
- MIT
- 更新日
- 2026/11/2
コメント
- …
このリポジトリの他のスキル
agent-adaptive-coordinator
81k作業量の変化に合わせて、エージェントのグループを分割し、再配分する手助けをします。作業に合った配置を選びます。
agent-agent
81k大きな目標を順番に並んだ行動計画にし、状況が変わったときに計画を立て直す方法をエージェントに教えます。
agent-agentic-payments
81kAIの買い物のために、支出の上限、期間、販売店のルール、署名付きの承認を含む支出の委任を管理する手助けをします。
agent-analyze-code-quality
81kコードの品質を確認し、コードの臭い、技術的負債、リファクタリングの案を見つける手助けをします。ファイルは変更しません。