anomaly-detection — skill for Claude Code, Codex, Gemini CLI
anomaly-detection detects outliers in time-series metrics from CSV, cloud monitoring, and other sources. Chooses smoothing and algorithms automatically, or accepts your tuning parameters.
Apache-2.0 ★ 151 updated 2026-10-12
/plugin marketplace add gemini-cli-extensions/sre
/plugin install sre-extension@sreWhat anomaly-detection does
The skill ingests data from your source, selects or asks which metrics to analyze, applies preprocessing when needed, and runs anomaly detection. It defaults to Isolation Forest but supports KNN and Z-Score with user-provided tuning. Python scripts handle data preparation, multiple detection methods, and quality validation—if the result flags more than 5% of points as anomalous, the skill auto-switches to stricter settings (moving-average smoothing and Z-Score threshold 3.0+) to reduce false positives.
Output includes PNG plots with anomalies marked and a list of timestamps where anomalies occur. Requires a Python virtual environment sre-extension-anomaly-detection with the necessary machine learning libraries.
What it helps with
- spot spikes in CPU, memory, or response-time metrics over hours or days
- correlate anomalies across multiple metrics in the same time window
- export anomaly reports from application logs in CSV format
- tune detector sensitivity for noisy or clean datasets
- visualize time-series data with anomalies highlighted on plots
Example prompts for the agent
- Find anomalies in my
metrics.csvfor CPU and memory over the last 24 hours - Detect outliers in response_time using z-score algorithm with threshold 2.5
- Analyze Cloud Monitoring data, apply moving-average smoothing with window 7, then isolation_forest
How to install anomaly-detection
1Plugin marketplace
/plugin marketplace add gemini-cli-extensions/sre/plugin install sre-extension@sreThis installs the whole sre-extension plugin with all its skills
2Skills CLI (Vercel)
npx skills add gemini-cli-extensions/sre --skill anomaly-detection -a claude-code3Manually: put the files in place
~/.claude/skills/anomaly-detection/SKILL.mdCopy the whole skill folder; for one project use .claude/skills/anomaly-detection/
1Skills CLI (Vercel)
npx skills add gemini-cli-extensions/sre --skill anomaly-detection -a codex2Manually: put the files in place
.agents/skills/anomaly-detection/SKILL.mdFor all projects use ~/.agents/skills/
1Skills CLI (Vercel)
npx skills add gemini-cli-extensions/sre --skill anomaly-detection -a cursor2Manually: put the files in place
.cursor/skills/anomaly-detection/SKILL.mdCursor also reads .agents/skills/ and .claude/skills/
1GitHub CLI
gh skill install gemini-cli-extensions/sre skills/anomaly-detection2Manually: put the files in place
.github/skills/anomaly-detection/SKILL.md1Skills CLI (Vercel)
npx skills add gemini-cli-extensions/sre --skill anomaly-detection -a gemini-cli2Platform CLI
gemini skills install https://github.com/gemini-cli-extensions/sre --path skills/anomaly-detectionManually: put the files in place
.devin/skills/anomaly-detection/SKILL.mdThe legacy .windsurf/skills/ path still works
Claude.ai
Zip the folder and upload it in Settings → Capabilities → Skills
Step by step, with commands for each platform: How to install skills in Claude Code: five ways
Questions about anomaly-detection
How do I install anomaly-detection in Claude Code?
Run these commands in order: /plugin marketplace add gemini-cli-extensions/sre, then /plugin install sre-extension@sre, then npx skills add gemini-cli-extensions/sre --skill anomaly-detection -a claude-code. Open the SKILL.md file at ~/.claude/skills/anomaly-detection/SKILL.md.
What does anomaly-detection do?
It analyzes time-series data (metrics, logs) and identifies unusual values using machine learning. It smooths noise, picks the best detection method, validates quality, and returns plots plus a list of anomalous timestamps.
What does the skill require to work?
An active Python virtual environment sre-extension-anomaly-detection with dependencies for Isolation Forest, KNN, or Z-Score. Data sources can be CSV files or Cloud Monitoring.
Source text
SKILL.md · Apache-2.0
---
name: anomaly-detection
description: 🐉 Detects anomalies in time-series data from various sources.
metadata:
author: Google
version: 0.1.0
status: published
---
# Anomaly Detection Skill
You are an expert SRE Detective. Your job is to analyze time-series metrics and pinpoint anomalous behavior with minimal user friction.
**Inputs:**
* `source_type`: String indicating the data source (e.g., "csv", "cloud_monitoring").
* `source_details`: A dictionary or list containing the necessary information to access the data source.
* For `source_type: "csv"`: A list of file paths.
* `context`: (Optional) String, either free-form text describing the issue or an issue tracker ID like a GitHub issue or Jira ticket.
* `metrics`: (Optional) List of strings, specific metric names to analyze from the source.
* `smoothing`: (Optional) String, method for smoothing (e.g., "moving_average", "exponential"). USER OVERRIDE.
* `window`: (Optional) Integer, window for moving average. USER OVERRIDE.
* `alpha`: (Optional) Float, alpha for exponential smoothing. USER OVERRIDE.
* `algorithm`: (Optional) String, anomaly detection algorithm (e.g., "knn", "zscore", "isolation_forest"). USER OVERRIDE.
* `n_neighbors`: (Optional) Integer for KNN detector. USER OVERRIDE.
* `threshold`: (Optional) Float, for Z-Score. USER OVERRIDE.
* `contamination`: (Optional: Float or "auto") For Isolation Forest. USER OVERRIDE.
**Workflow:**
1. **Get Data:**
* Call `@skills/data_ingestion` with `source_type` and `source_details`.
* Save output to `.gemini/tmp/user/merged_data.json`.
2. **Select Metrics:** (Same as before - infer from query/context, ask if needed)
* Let `available_metrics` be `metadata.available_metrics` from `merged_data.json`.
* If `metrics` input is provided, validate they are in `available_metrics`. Use these valid metrics.
* If `metrics` input is NOT provided, analyze the user's initial query and `context` for metric names. Try to match keywords with `available_metrics`.
* If no clear metrics can be inferred, or if there's ambiguity, use `ask_user` to prompt the user to select one or more metrics from `available_metrics`.
* Let `selected_metrics` be the list of metrics to analyze.
3. **Process Each Selected Metric:** Iterate through each `metric_name` in `selected_metrics`:
a. **Filter Metric Data:** Create a temporary JSON file (`/tmp/single_metric_data.json`) containing only the "timestamp" and the current `metric_name` column from `merged_data.json`. You can write a short Python script to extract the relevant column based on the metric index in the `"columns"` list, ignoring rows where the metric value is `null`.
b. **Automated Preprocessing:**
* **Check for User Override:** If `smoothing` parameter is provided, use the specified method and parameters.
* **Automated Choice:** If no override, the agent should *autonomously* decide if smoothing is needed. Heuristic: calculate the point-to-point change percentage. If a significant number of points exceed a threshold (e.g., >20% change), apply a default `moving_average` with a small window (e.g., 3 or 5).
* Log the decision: "No smoothing applied" or "Applied Moving Average smoothing with window=3".
* If smoothing is applied, run `scripts/preprocess_data.py` as before, outputting to `/tmp/preprocessed_data.json`.
* Input to next step is `/tmp/preprocessed_data.json` or `/tmp/single_metric_data.json`.
* Let this be `data_for_detection.json`.
c. **Automated Algorithm Selection:**
* **Check for User Override:** If `algorithm` parameter is provided, use the specified algorithm.
* **Automated Choice:** Default to `isolation_forest` as it's generally robust. Contamination set to "auto".
* Let `chosen_algorithm` be the selected method.
d. **Detect Anomalies:** Execute the script for `chosen_algorithm`:
* All detection scripts take `data_for_detection.json` as input and output to `/tmp/detected_data.json`.
* **Example (Isolation Forest):**
```bash
source $HOME/.venvs/sre-extension-anomaly-detection/bin/activate &&
python3 .gemini/skills/anomaly_detection/scripts/detect_isolation_forest.py \
/tmp/data_for_detection.json --contamination auto \
> /tmp/detected_data.json
```
* Adjust command and parameters for knn or zscore if overridden.
e. **Evaluate Noise & Auto-Tune (Self-Reflection) - MANDATORY:**
* **Requirement:** You MUST evaluate the noise level of the detection result for EVERY metric, without exception.
* **Calculation:** Use `jq` to count the total points and the anomaly points in `/tmp/detected_data.json`.
* **Noise Threshold:** If the anomaly count exceeds **5%** of the total data points, the result is considered "noisy" (false positives).
* **Autonomous Fallback:** If noisy, you MUST discard the result, log "Detection too noisy ({count} anomalies), applying autonomous auto-tuning", and loop back to **Step 3.b**.
* **Auto-Tune Parameters:** Force **Smoothing** to `moving_average` (window=5) and **Algorithm** to `zscore` (threshold=3.0).
* **Quality Check:** After re-running, ensure the new result is within reasonable bounds (e.g., < 2% of points). If still noisy, increase the Z-Score threshold iteratively (e.g., to 4.0 or 5.0) until the signal is clear.
f. **Plot Anomalies:** Execute `scripts/plot_anomalies.py` and move the output to the destination directory.
* **Example:**
```bash
PLOT_FILE=$(python3 .gemini/skills/anomaly_detection/scripts/plot_anomalies.py /tmp/detected_data.json) &&
mkdir -p data && mv "$PLOT_FILE" data/${metric_name}_anomalies.png
```
g. **Extract Results Summary:** Use `jq` to extract the exact timestamps where an anomaly was detected to summarize the findings.
* **Example:**
```bash
jq -r '.timeseries[] | select(.[2] == true) | .[0]' /tmp/detected_data.json | head -n 5
```
4. **Correlate & Explain:** Synthesize the detected anomalies, matching up the time windows across multiple metrics. Explain which anomalies correlate and what the underlying cause might be.
5. **Report Results:** Provide a clear summary to the user including the algorithm used, any preprocessing applied, the time windows of the anomalies, and the path to the generated plots.
© Google · Apache-2.0 · gemini-cli-extensions/sre