Format and lint PromQL expressions embedded in Prometheus/Thanos/Cortex/Mimir rule YAML files — multiline layout, redundant aggregation-clause removal, aggregation-style consistency, and naming/instrumentation best-practice checks. Use whenever writing, editing, or reviewing alert/recording rule YAML, or as a CI formatting gate on pull requests that touch rule files. Fully hermetic: no network access or running Prometheus required.
Ships in promql-cody. Installing the plugin adds it to Claude Code.
What the skill costs in Claude's context, stage by stage
Name and description: Claude knows it exists.
SKILL.md joins the conversation and stays.
None: SKILL.md is the whole skill.
Static analyzer and auto-formatter for PromQL expr:/query: fields inside
Prometheus-style rule YAML files. Hermetic — it only reads the files you
point it at.
go build -o bin/promql-fmt ./cmd/promql-fmt
# or: go install github.com/conallob/o11y-analysis-tools/cmd/promql-fmt@latest
promql-fmt [options] <file|directory>...
Only .yml/.yaml files are scanned; directories are walked recursively.
There is no stdin mode (unlike label-check) — always pass a file or
directory path.
| Flag | Default | Effect |
|---|---|---|
--check | true | Report issues, exit 1 if any found. Do not modify files. |
--fix / --fmt | false | Rewrite files in place with the formatted output. --fmt is an alias for --fix. Passing either disables --check automatically. |
--verbose | false | Print per-file "Fixing …" lines while fixing. |
--disable-line-length | false | Suppress the "should use multiline formatting" nudge for long lines — useful for recording rules with unavoidably long metric names. |
--prometheus-url | "" | Optional. If set, additionally queries that Prometheus for timeseries continuity — i.e., flags expressions that reference metrics with no matching series. This is the one non-hermetic opt-in check; omit the flag to stay fully offline. |
# CI gate / pre-commit check (default mode)
promql-fmt --check ./prometheus/
# Auto-fix in place, then re-check
promql-fmt --fix ./prometheus/
# Verbose fix, skip line-length nudges for long recording-rule names
promql-fmt --fix --verbose --disable-line-length ./prometheus/recording-rules.yml
expr: blocks into an
indented multiline YAML block scalar (expr: |), removing a redundant
by (...) clause from the left operand of a binary expression when both
operands share the same aggregation labels, and inserting an explicit
on (...) vector-matching clause.sum(metric) by (label)) or prefix
(sum by (label) (metric)) style and flags expressions that break with
the file's dominant style._milliseconds/_minutes/etc., wants
_seconds), _total suffix on counters, _ratio instead of raw
percentages, level:metric:operations naming for recording rules.rate()/irate() applied to something
that doesn't look like a counter, division without zero-protection,
utilization ratios where the denominator metric name doesn't contain
total, up{...} used without a job selector.for: at all (a distinct,
static check from the separate alert-hysteresis tool, which instead
tunes an existing for: value against real firing history).Check mode groups issues by file:
./alerts/api-alerts.yml:
- Metric 'httpRequestCount' should use snake_case, not camelCase
- Expression should use multiline formatting: sum(rate(http_requests_total...
Found formatting issues in 1/12 files
Run with --fix to automatically format
Exit code is 1 whenever any file has issues in check mode (or a write
error occurs in fix mode), 0 otherwise. Every issue is plain English —
there's no machine-readable JSON mode, so an agent should parse them as
free text and either explain them to the user or run --fix and re-check.
promql-fmt --check <path> first. If exit code is 0, nothing to do.promql-fmt --fix <path> over manual edits, then re-run
--check to confirm.--check only; never run --fix unattended in a pipeline
that auto-commits, since some rewrites (removing a "redundant"
aggregation clause) change semantics if the assumption about matching
labels doesn't actually hold — treat --fix output as something a human
reviews before merge, same as any auto-formatter.What SKILL.md sets; muted values are Claude Code's defaults
/promql-cody:promql-fmtfrom promql-cody
npx claudepluginhub conallob/o11y-analysis-tools --plugin promql-cody7 skills in this plugin
/alert-hysteresisQuery a live Prometheus's historical ALERTS series to statistically recommend better 'for:' hold-down durations, reducing spurious short-lived alerts and alert fatigue. Use interactively when an alert is firing too often/too briefly and needs its hysteresis tuned, or when auditing a rules file's for: values against real firing behavior. Requires a live Prometheus with sufficient ALERTS retention — not hermetic, not a CI check./autogen-promql-testsIdentify Prometheus alert/recording rules that have no promtool unit-test coverage, and scaffold true-positive/false-positive/hysteresis test-case skeletons for them. Use when bootstrapping unit tests for new or existing PromQL rules, or auditing test coverage of a rules file. Fully hermetic: reads only local rule/test YAML, no running Prometheus required./Other plugins' skills for the same job