Show what the run that just finished cost, split by skill or by subagent role: wall clock, turns, tool calls, tokens, cost; optionally save it as JSON. Or compare a skill's saved runs over time, analyse its steps across them and suggest changes to the skill, or measure and compare build-epic runs.
Installs into .claude/skills of the current project.
Sponsors
SSkills DirectorySkills Directory
Know which skills are safe — weekly.
SSkills DirectorySkills Directory
Is that skill safe to install?
Are you the author of Telemetry?
Add the live security badge to your README. It updates with every re-scan.
[](https://www.skillsdirectory.com/skills/rpvsilva-telemetry)
---
name: telemetry
description: "Show what the run that just finished cost, split by skill or by subagent role: wall clock, turns, tool calls, tokens, cost; optionally save it as JSON. Or compare a skill's saved runs over time, analyse its steps across them and suggest changes to the skill, or measure and compare build-epic runs."
disable-model-invocation: true
---
Report what the **run** cost: this session from its start (or from the previous telemetry report) up to this request, subagents included. The report splits the run into **spans**, one per skill the user typed; skills those load count toward them, and activity before any skill is the `no skill` span. Scripts compute every number; you relay them and read them.
Claude Code also saves every session's whole run on its own when the session ends, as `~/.agents/telemetry/<session id>.json` (a session that ends again overwrites its file; its `date` is the UTC date of its start), through the session-end hook `scripts/hooks/telemetry-save.sh`. The Setting `auto_save` turns that off: `~/.agents/bin/settings set telemetry auto_save false --machine` (or `--repo`), or the `configure` skill. The `--save` below is separate and unchanged.
Arguments, all optional: a **skill** name to report only that skill's last span; `--save <label>`; `--session <id>` to report on an older session instead of this one; `--by-role [--run-folder <run>]` to split the cost by subagent role instead of by span (step 3).
A saved run (`schemaVersion` 6) holds, per span and for the whole run, `activeSeconds`: its time minus every gap over 15 minutes with nothing logged (a closed laptop, a night) and every wait on the human; per span `activeIntervals`, those stretches of work as `[start, end]` pairs, and `agentsAtOnce`, its subagents running at once (`peak`, and the `average` over the time any ran; `null` with none); and per span and for the whole run `humanMessages`, what the human typed after the span started (each a time the run stopped for them; subagent hand-backs, compaction summaries, notifications and commands are not counted), and `humanWaitSeconds`, the idle time before each answer of the human (a typed message or the answer to a question the run asked), at any length, listed per span in `humanWaits` (`answered`, `seconds`). It also holds, per subagent, its `role` (the prefix its description starts with, as `ROLES` in the extractor lists them: `implement: TT-NN`, `review: PR 12`, ...; `other` without one) and its `cost` in USD at the prices of the save (`null` when `pricing.json` or a model's price is missing), and at the top the `pricingAsOf` of those prices and `claudeVersions`, each Claude Code version the session ran on. Older saves have neither; the scripts below read them all.
Or `compare [skill] [--since YYYY-MM-DD] [--until YYYY-MM-DD]`: compare saved runs over time instead of reporting this one; go to step 1, then straight to step 6.
Or `analyse <skill> [--top N]`: find the slowest, failing, repeated and retried steps of a skill across its saved runs, and suggest what to change in it; go to step 1, then straight to step 7.
Or `metrics <run folder>`: the outcome metrics of one [build-epic](../build-epic/SKILL.md) run; go to step 1, then straight to step 8. Or `compare-runs`: compare two build-epic runs of the same epic; go to step 1, then straight to step 9.
## Steps
1. **Find the scripts.** Resolve this skill folder's real path (`cd <skill folder> && pwd -P`): it sits in the dotagents repo at `skills/telemetry/`. Beside it are `report.py`, `compare.py`, `analyse.py`, `run_metrics.py`, `compare_runs.py` and `file_missed_targets.py`; the extractor for the tool you are running in is `adapters/<tool>/telemetry/extract.py` from the repo root (`claude` for Claude Code). If your tool has no extractor, say so and stop (for `compare`, only `compare.py` is needed; for `analyse`, only `analyse.py`; for `metrics`, only its script; for `compare-runs`, `compare_runs.py` and `file_missed_targets.py`). Done when the paths you need exist.
2. **Extract the run.** `python3 <extract.py> [--skill <name>] [--session <id>] > <temp>/run.json`. Exit code 2 means there is nothing to measure (the skill never ran, or nothing happened since the last report): relay its message and stop. Done when `run.json` holds the run.
3. **Report.** `python3 <report.py> <temp>/run.json [--save <label>]`. Show the output verbatim in a code block, then three plain lines: the costliest span and what drove it (output, cache writes or cache reads), the busiest tool or subagent, and the cheapest lever to try next. Done when the table and the three lines are shown.
With `--by-role`, run `python3 <report.py> <temp>/run.json --by-role [--run-folder <run>]` instead: one table, an `orchestrator` row first (the spans minus their subagents, with its average context per turn: its cache-read tokens over its turns), then one row per role (runs, turns, cost) by cost, highest first, then, with `--run-folder`, a `remote` row summed from that build-epic run folder's `remote/*.json` (each remote task's result), and a `Total` row. Role cost is recomputed from each subagent's `tokensByModel` at today's prices, not read from its saved `cost`; a subagent saved without a role gets one from its type, else its description's keywords. When remote runs carry no cost, a line `N remote runs without cost` follows the table: say their cost is missing from the total. `--run-folder` without `--by-role`, or `--save` with it, exits 2. Show the output verbatim in a code block, then two plain lines: the costliest role and the orchestrator's share of the total. Done when the table and the two lines are shown.
4. **Check prices**, only when the report ends with a `check with: update_pricing.py …` line (prices over 30 days old, or a model with no price). Run that command from the skill folder: it compares `pricing.json` with LiteLLM's price list and writes nothing. Show its changes and ask whether to apply them; on yes, re-run it with `--apply`, then re-run step 3. If it prints `LiteLLM unavailable`, say prices stay as they are and go on. Done when prices are applied, declined, or unavailable.
5. **Offer to save**, unless `--save` was already given: ask once whether to save this run as JSON (to `.agents/telemetry/` at the repo root), and for a label. Saved runs hold step labels (masked commands and paths), so the first save writes a `.gitignore` of `*` into that folder, keeping them out of git without editing the repo's own files. On yes, run `python3 <report.py> <temp>/run.json --save <label>` and show only its final `Saved …` line. Done when the run is saved or the offer declined.
6. **Compare**, only for `compare`. `python3 <compare.py> [skill] [--since YYYY-MM-DD] [--until YYYY-MM-DD]`: it reads the saved runs in `~/.agents/telemetry/` and this repo's `.agents/telemetry/`, and prints one table per skill (`plug:deploy` and `deploy` share one), one row per run oldest to newest (a session's automatic save stands for the whole session; without one, each manual save of it is its own run; that run's spans of the skill summed, cost at today's prices, `unknown` for a model with no price; `Active` is the time minus stalls, `unknown` for a run saved before schemaVersion 5), then a `change` row: latest minus earliest. Exit code 2 means no saved run matches: relay its message and stop. Show the output verbatim in a code block, then one plain line on what changed most (the figure with the largest relative change, and in which skill). Done when the tables and the line are shown.
7. **Analyse**, only for `analyse`. `python3 <analyse.py> <skill> [--top N]`: it reads the same saved runs as step 6, keeps those where the skill ran, and lists that skill's steps in four tables, each row naming where the step ran (the subagent, else the skill) and how many runs show it: **Slowest** (median and max seconds, top N by median, default 10; questions, subagent launches and background steps left out), **Failing** (failed out of total), **Repeated** (the same step twice or more within one run) and **Retries** (a failed step run again nearly the same within the next 3 steps). Repeated and Retries count only steps of one subagent, or of one span outside subagents, so two subagents of one type started in parallel are neither. Repeated and Retries leave out steps with an empty label (MCP tools, `AskUserQuestion`), since nothing shows two of them are the same. An empty table prints `none`; saved runs without steps are skipped and counted on the last line. Exit code 2 means no saved run of the skill was found: relay its message and stop. Show the output verbatim in a code block. Then read the skill's `SKILL.md` (and the brief of a subagent named in `Where`) and, for the top findings (at most five, worst first), name the step they likely come from and one concrete change: drop a repeated read by keeping what the first one returned, fix the failing command, add a check before a retried step, or move a slow step to a script or a subagent. Say plainly when a finding matches no step. Done when the tables are shown and each top finding has its step and change, or the message for exit 2 is relayed.
8. **Run metrics**, only for `metrics`. `python3 -I <run_metrics.py> <run> [--gh <cmd>]` prints one JSON object (`schema: build-epic-run-metrics/v1`) from the run folder and GitHub: `tickets` and `tasks` (counts by status; tasks also by kind: `implement`, `fix`, `tune`), `fix_rounds` (the `OK <id> pushed` lines in `logs/<id>-push_fix.log`, in runs from before tasks were commits; the red merges, `FAIL <id> red` in `logs/<id>-merge_task.log`, and the fix tasks), `reviews` (reviewer outputs `<PR>-<sha7>.json` in `reviews/` (`.md` in older runs), and `<TT-NN>-<sha7>.json` for a task reviewed before it merged, and how many were re-reviews; posted copies, findings and security reports are not reviews, and `security` counts the security reports), `follow_ups`, `suites` (from `reports/<id>.checks.json`), `remote` (from `remote/*.json`: runs, cost, `runs_without_cost`, and `by_role`: runs by role and model, so remote reviewers count among the reviewer runs `compare_runs.py` judges), `prs` (each ticket's and task's PR: sizes, hours to merge, who merged, `first_created`, `last_merged`), `per_ticket` (tasks, PR, `first_task_pr_opened`, `ticket_merged` and the wall-clock minutes between them), `lead_time` (hours from the epic's issue opening, `run.md`'s `Epic:`, to the last ticket PR's merge; `null` until every ticket has merged) and `gaps` (what it could not measure). It reads GitHub only through `<cmd> pr view` and, for the epic, `<cmd> issue view` (default `gh`), run in `run.md`'s `Repo:` folder. Save the output beside the run (`<run>/metrics.json`) and show `gaps` and the headline figures (tasks, fix rounds, re-reviews, remote cost, PR hours to merge) as a short list. Done when the file is saved and the list shown.
9. **Compare runs**, only for `compare-runs`. Each run needs its saved telemetry (its session's automatic save, `~/.agents/telemetry/<session id>.json`) and its `run_metrics.py` output (step 8). `python3 -I <compare_runs.py> --a <run.json> --a-metrics <metrics.json> [--a-branch <branch.json>] [--a-name <name>] --b <run.json> --b-metrics <metrics.json> [--b-branch <branch.json>] [--b-name <name>] --pricing <pricing.json> [--targets <targets.json>]` prints one JSON object (`schema: build-epic-run-comparison/v1`): per run (`runs.<name>`, names default `a` and `b`), its time (with `activeMinutes` and `agentsAtOnce` for runs saved since schemaVersion 5, `null` before; `humanWaitMinutes`, `humanWaits` and `perTicketActiveMinutes`, each ticket's window from its first task PR (or, with tasks as commits, its first task's `Finished:` line) to its merge cut to the run's active intervals (`active_minutes` per ticket under `perTicket`; tickets building at once share that time), for runs saved since schemaVersion 6, `null` before; `perTicketWallMinutes`, the same windows by the wall clock, waits included; `leadTimeHours` and `runStartToLastTicketMergeMinutes` from the metrics' `lead_time`), cost (by model, token kind, orchestrator, subagents and remote runs, estimated from the other run's implementers where a remote run has no cost), tokens, subagents by role, steps and outcomes (with `interruptions`: the span's `humanMessages` plus its `AskUserQuestion` calls, `null` before schemaVersion 5); then `comparison`, each figure side by side with the difference, the percentage and which run did `better`. `--*-branch` adds the final branch's measurements (source and test lines, suite); `--pricing` is normally this folder's `pricing.json`. `--targets` is normally this folder's `targets.json` (the #181 targets): with it, `comparison.targets` judges run b (the rerun, so pass the new run as `--b`) against each target, with its `threshold`, `op`, run b's `value` and a `status` of `met`, `missed` or `unknown` (an input is missing; never call it missed). It reads no git and writes no prose. Save the output, then write the comparison yourself: the three largest differences (cost, time, fix rounds), each with the figure from both runs. Then, with `--targets`, list the missed targets, each with its value and threshold; for `total-cost-per-task` (costs are per done task, so epics of different sizes compare), say its `basis` (`measured`, or `estimate-mid` when remote runs lack cost) and, for an estimate, its `range` (low to high), since the target may hold at one end and not the other. When any target is missed, offer to file them as issues and run nothing until the human says yes: `python3 -I <file_missed_targets.py> <comparison.json> --epic <epic number> [--repo <owner/repo>]` files one issue per missed target not yet filed (its body says `Part of #<epic>`) as the identity the `identity_command` Setting names (unset: the current gh login; set it with `~/.agents/bin/settings set telemetry identity_command <command> --repo`, or the `configure` skill), and writes each issue number into its target in the comparison file as `issue`, so a rerun files only the rest. Show the issues it filed. Done when the file is saved, the three differences shown, and the missed targets listed and filed or the offer declined.