anomalies — Claude Code command: what it does, how to install
anomalies spots outlier agent sessions with unusual token spikes or dollar costs using z-score calculations.
MIT ★ 1,198 updated 2026-10-23
/plugin marketplace add hoangsonww/Claude-Code-Agent-Monitor
/plugin install ccam-insights@claude-code-agent-monitor-pluginsWhat anomalies does
This command queries your local Agent Monitor dashboard at http://localhost:4820 to pull up to 200 recent sessions. It calculates the mean and standard deviation for run expenses and token usage across the retrieved population.
Any session exceeding the z-score threshold (default 2.0) is rendered into a Markdown table. Total tokens account for input, output, cache-read, and cache-write values. Items are sorted by cost deviation and flagged with 🟡 for z > 2 or 🔴 for z > 3.
If the dashboard server is down at http://localhost:4820, metric gathering fails entirely. You need to launch it with npm start from the Agent Monitor repository root before invoking this command.
What it helps with
- spot sessions that exceed normal API cost baselines
- identify runaway token counts across prompt loops
- isolate cost outliers using a custom z-score threshold
- inspect token totals including cache reads and writes
Example prompts for the agent
- /anomalies
- /anomalies 2.5
- /anomalies 1.2
How to install anomalies
1Plugin marketplace
/plugin marketplace add hoangsonww/Claude-Code-Agent-Monitor/plugin install ccam-insights@claude-code-agent-monitor-plugins2Manually: put the files in place
.claude/commands/anomalies.mdCall it with /anomalies. For all projects use ~/.claude/commands/
Manually: put the files in place
~/.codex/prompts/anomalies.mdCall it with /prompts:anomalies. Codex marks this format deprecated in favour of skills
Manually: put the files in place
.github/prompts/anomalies.prompt.mdManually: put the files in place
.gemini/commands/anomalies.tomlGemini stores commands as TOML: the prompt text goes into the prompt field
Questions about anomalies
How to install anomalies in Claude Code?
Run /plugin marketplace add hoangsonww/Claude-Code-Agent-Monitor first, then run /plugin install ccam-insights@claude-code-agent-monitor-plugins.
What does the anomalies command do?
It calculates statistical z-scores over your recent agent runs and highlights executions with abnormal token or dollar expenses.
What is required before using anomalies?
An active Agent Monitor web server listening on http://localhost:4820 is required. Start it by running npm start in the repository root.
Source text
anomalies.md · MIT
--- description: List current cost and token outlier sessions via z-score argument-hint: "[threshold]" --- List the current cost/token **outlier** sessions from the Agent Monitor dashboard using a z-score test. **$ARGUMENTS** optionally sets the z-score threshold (default `2.0`; lower = stricter). 1. Fetch the population: - `curl -s "http://localhost:4820/api/sessions?limit=200"` → a session list; each item has `id`, `status`, `model`, `cwd`, `started_at`, `cost`, and `metadata`. 2. Compute the baseline over all returned sessions: - Mean and standard deviation of `cost`. - For sessions where you need token totals, pull `curl -s http://localhost:4820/api/pricing/cost/<id>` and sum `input_tokens + output_tokens + cache_read_tokens + cache_write_tokens`; compute mean and stddev of total tokens too. 3. Flag outliers: any session whose `z = (value − mean) / stddev` exceeds the threshold (default 2.0) on cost (primary) or tokens (secondary). Skip the calc gracefully if stddev is 0. 4. Print the flagged sessions, sorted by descending cost z-score: - Session id (short), model, started_at. - Cost (USD, 4 decimals) and its z-score. - Total tokens and its z-score (when fetched). - A flag tag: 🔴 if z > 3, 🟡 if z > 2. Output rules: a Markdown table of flagged sessions only; currency in USD to 4 decimals; z-scores to 2 decimals; if nothing exceeds the threshold, say "No cost/token outliers above z=<threshold>" and report the top session by cost for context. Cite only API values — never fabricate. If the dashboard is unreachable at `http://localhost:4820`, tell the user to start it with `npm start` from the repo root.
© Son Nguyen · MIT · hoangsonww/Claude-Code-Agent-Monitor