Define Metric
Write or refine a metric definition — name, plain-language meaning, grain, filters, source tables and columns, edge cases, and owner — into analysis/metrics/<slug>.md, after searching the repo for a definition that already exists.
/define-metric[metric name]A Claude Code slash command that writes a metric definition to analysis/metrics/<slug>.md: name, plain-language meaning, grain, filters, source tables and columns, edge cases, and owner. It searches the repo for an existing definition first and refines that one rather than creating a rival, so two teams stop shipping two versions of the same number.
Install to ~/.claude/commands/define-metric.md
npx agentscamp add commands/define-metricMost metric arguments are not disagreements about the data. They are two people using one word for two calculations, with neither definition written down. This command writes the definition into the repository next to the queries that implement it, and searches first, because a second definition of an existing metric is worse than none: if analysis/metrics/ or the SQL already defines this number, it refines that file rather than opening a rival.
Scope
$ARGUMENTS is a metric name or a description of one. Interpret it in this order:
- A short name ("active users", "MRR", "trial conversion"): treat it as the metric to define, and slug it in kebab-case.
- A sentence describing a metric ("the share of signups that pay within 30 days"): derive a name, propose it, and use the sentence as the first draft of the plain-language definition.
- A path to a
.sqlfile or a notebook: read it, work out which metric it computes, and define that. This is the most useful direction, because a definition written from working code starts out true. - Empty:
Globforanalysis/metrics/*.md, list the metrics already defined, and ask which to refine.
Step 1 — Search before writing
Glob for analysis/metrics/** and read anything with a matching or near-matching name. Then Grep the repo for the metric's name and its likely synonyms in .sql, .py, .ipynb, dbt models, and dashboard configs. Look for the same number computed under a different name, and the same name computing a different number; both are findings that belong in the definition.
Report what you found before writing: a definition exists and you will refine it, several conflicting implementations exist and the differences must be resolved first, or nothing exists and you are writing the first one. When implementations conflict, list the conflicts with file paths and ask which is authoritative. Do not pick one and write it up as settled.
Step 2 — Pin the definition down
Work through the fields in order. A field you cannot answer becomes an open question in the file, marked TBD, never a plausible guess.
- Name. The one the team will use, plus any aliases the search turned up so both resolve to this file.
- Plain-language definition. One or two sentences a non-analyst can read, saying what is counted and over what period.
- Grain. What one row of the result represents: per user per day, per account per month, per order. Almost every metric dispute is a grain dispute.
- Filters. Every condition applied, and for each one the reason: excluded internal accounts, excluded test orders, excluded refunds, a specific status. An unexplained filter is where the next disagreement starts.
- Source tables and columns. The exact tables and columns, with a note on any that are nullable or updated in place, since those decide how the metric behaves over time.
- Edge cases. How the metric handles nulls, zero denominators, refunds and reversals, backdated rows, deleted accounts, users active in two segments, partial first periods, and time zone. Cover late-arriving data explicitly: whether the number is expected to move after it is first published.
- Owner. A named person or team who decides changes, and the date the definition was last agreed.
Where the definition comes from existing SQL, run the sql-explainer reading over that query first: its grain statement and its silent-drop list fill in the grain, filters, and edge-case fields directly.
Step 3 — Write the file
Write to analysis/metrics/<slug>.md with those fields as headings in that order, plus a Reference implementation line pointing at the query that computes it and an Open questions list holding every TBD. When refining, preserve wording a human wrote, add a dated changelog line saying what changed and why, and never silently alter a grain or filter someone agreed to.
Output
The file path, whether it was created or refined, the conflicting implementations found with their paths, and the open questions still needing an owner's answer. Then the next step: take those questions to the owner named in the file, profile the underlying data with /first-look if you have not, and have the analysis-reviewer agent check that analyses citing this metric actually implement it. Where these files are maintained as a modeling layer instead, see semantic layer, Claude Code for data analysts, and Claude skills for data analysts.
Related
- SQL ExplainerWalk through a pasted SQL query in execution order in plain language: what each step does, the grain of the result, where a join can fan rows out, which filters silently drop rows, and a ranked list of what could be wrong. Comprehension only, not performance tuning. Use when you inherited a query, are reviewing one before trusting its numbers, or have to explain it to someone who does not read SQL.
- First LookRead the first rows and the true row count of a CSV or spreadsheet, profile it against a fixed checklist, and write the result to analysis/profiles/<name>.md so the dataset's condition is on record before anyone queries it.
- Analysis ReviewerUse this agent to review a finished analysis for methodological errors before it ships — checking grain and double counting, join fan-out, rows silently dropped by filters and inner joins, sampling and truncation, null handling, time zone and date boundaries, numbers in the prose that disagree with the code's output, charts that mislead, and causal language resting on correlational evidence. Examples — 'review this notebook before I send the deck', 'the query and the summary disagree somewhere, find it', 'does this analysis actually support the conclusion it draws?'.
- Claude Code for Data Analysts: Notebooks, SQL, and CSV Work Without a Data EngineerRun analysis work in Claude Code: an analysis repo with CLAUDE.md, a CSV profiling pass, a pandas loop, a read-only warehouse query, and permission rules.
- Claude Skills for Data Analysts: 5 to Upload TodayFive portable skills that make Claude behave like a careful analyst: first look, chart choice, memo writing, SQL explanation, and formula auditing.
- Semantic LayerA semantic layer defines business metrics, dimensions, and joins once, so every query and every AI agent computes the same number the same way.