cost-anomaly

Detects anomalous session spend using MAD-based modified z-score outlier analysis.

70.1k|8.4k|Updated Jun 2, 2025
One-click install
npx skills add https://github.com/ruvnet/claude-flow --skill cost-anomaly
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: cost-anomaly
Source: https://github.com/ruvnet/claude-flow/tree/main/plugins/ruflo-cost-tracker/skills/cost-anomaly
Command: npx skills add https://github.com/ruvnet/claude-flow --skill cost-anomaly

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes scripts (resource) components.

What problem does it solve?

Aggregate cost trends can hide individual rogue sessions that burn through budget. This Skill pinpoints exactly which specific sessions are statistical outliers in spend, so you can investigate runaway loops, stuck expensive tiers, or crashed sessions instead of guessing.

Core Features & Use Cases

  • Robust Outlier Detection: Computes median and MAD (median absolute deviation) across session costs, then flags sessions with modified z-scores above a configurable threshold (default 3.5, per Iglewicz-Hoaglin 1993).
  • CI Gate Integration: The --alert-on-outliers flag returns a non-zero exit code when outlier counts exceed a limit, enabling automated build failures on anomalous spend.
  • Direction Labeling: Classifies outliers as high (runaway spend) or low (crashed/dropped sessions) so operators interpret results correctly.
  • Use Case: Run a weekly check with --since 7d --alert-on-outliers 1 in CI to fail the pipeline whenever any session that week is a >3.5σ spending outlier, then investigate with cost report.

Quick Start

Ask the AI to run cost anomaly detection over the last 7 days of sessions and alert if any individual session is a spending outlier.

Frequently Asked Questions about cost-anomaly

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I detect outlier sessions in AI API spending?

Run cost anomaly with an optional --since window to compute modified z-scores per session using median and MAD. Sessions with |z| above the threshold (default 3.5) are flagged with direction labels so you can investigate high-spend or crashed sessions.

Why use MAD instead of mean and standard deviation for outlier detection?

Mean and standard deviation are inflated by the very outliers being hunted, letting anomalies hide inside the widened normal band. Median and MAD resist up to 50% contamination, so outliers cannot shift the baseline, which is critical on small samples.

How do I fail a CI build when a session is a cost outlier?

Use the --alert-on-outliers flag with a threshold count, for example cost anomaly --since 7d --alert-on-outliers 1. The command exits with code 1 when outlier count meets or exceeds the threshold, failing the pipeline step.

What is the difference between cost-anomaly and cost-burn?

cost-burn answers whether the aggregate spending rate is accelerating, while cost-anomaly identifies which specific individual sessions are statistical outliers. They are complementary and can fire independently.

What happens when there are too few sessions or identical costs?

With fewer than 3 sessions the skill reports insufficient data and exits 0, since MAD is meaningless on tiny samples. When MAD equals zero because most sessions share identical spend, it emits an explanation instead of dividing by zero.