Skip to content

usage — GitHub Copilot CLI

Analyze historical Copilot CLI spend from local session logs — spend by model and session in USD and AI Credits, read-only. Use when the user asks what they've spent, which models they've been using, or where they could save.

In practice

What it does

This never calls the copilot CLI to gather your spend — the logs already sitting on disk are the source, so checking your own numbers costs nothing and touches no network. What comes back is the same shape as the Claude cost report: total spend, which model dominated, and specific sessions where a cheaper tier likely would have done just as well.

When to reach for it

  • You want to know what you've actually spent, not what you assume you spent.
  • Checking which sessions used an expensive tier for a small amount of work.
  • Deciding whether a default-model change would have saved credits over a recent window.
  • Not for "what should I use next" — that's route; this only looks backward.

Worked example

python3 bin/copilot_usage.py --days 30

Read it top to bottom: a headline total in USD and AIC and the dominant model, a by-model table, then downgrade-candidate sessions with the script's own estimated-savings figure — relay that number rather than restating it yourself. Add --top N for more or fewer sessions, or --copilot-home DIR / --session-dir DIR to point at a non-default home.

Failure modes & fallbacks

  • A session mixed models. Its whole token split is attributed to the LAST model and flagged ≈ — the logs carry no per-model split to attribute more precisely, so never present a flagged figure as exact.
  • totalNanoAiu shows up in the output. That's Copilot's own reported consumption unit, shown only as a labeled cross-check — never convert it to USD or AIC yourself; the authoritative estimate is token counts priced through the pricing file.
  • Logs are missing or empty. Report that plainly rather than guessing a number; if the script errors, show the error and the file it choked on.

Cost & safety

Strictly read-only over <copilot-home>/session-state/*/events.jsonl — never the *.db stores, and never a live copilot call, because that would spend real credits and hit the network for a report that's supposed to be free. Every dollar and credit figure is priced from the pricing file at run time, never quoted from memory.

The skill card — what the model reads

This is the SKILL.md body the model reads, transformed for this page: the source's own leading title, if it had one, is removed; every remaining heading is demoted one level to nest under this section; and relative links are rewritten to site or GitHub URLs. ${CLAUDE_PLUGIN_ROOT} and {{POLYTROPOS_ROOT}} are install-time path variables, left intact exactly as the model sees them. The unmodified original is copilot/.github/skills/usage/SKILL.md.

You report historical Copilot CLI spend from the user's own local session logs. You are a read-only reporter, not a router — for "what should I use next" point the user at the route skill instead.

Run the engine — never invoke the copilot CLI to gather usage

Shell to the analyzer rather than reading raw logs yourself:

python3 {{POLYTROPOS_ROOT}}/bin/copilot_usage.py --days 30

Flags (the real argparse surface — do not invent others): - --days N — lookback window (default 30) - --top N — how many top sessions to list (default 10) - --copilot-home DIR / --session-dir DIR — point at a non-default home (rarely needed)

The script reads <copilot-home>/session-state/*/events.jsonl strictly read-only — it never opens the *.db session stores and it NEVER invokes the copilot CLI itself (that would spend real AI Credits and hit the network; the logs already on disk are the source). It prices everything from {{POLYTROPOS_ROOT}}/data/pricing.copilot.json — USD and AI Credits, both derived from the pricing dict at run time. Never quote a price, credit value, or model id from memory. AIC are money — treat every figure the engine emits as real spend, not a synthetic score.

Presenting the results

The script emits markdown. Summarize it for the user rather than dumping it verbatim:

  1. Headline — the total priced estimate in USD and AIC over the window, and which model dominated spend.
  2. By-model table — as emitted.
  3. Downgrade candidates — as emitted (sessions on an expensive tier with a small token footprint and few turns). Relay the estimated-savings figure the script computed rather than restating it yourself.
  4. One actionable recommendation — e.g. a default-model change — grounded in what this window's data actually shows, not a generic tip.

Honesty rules carried from the engine

  • A multi-model session has its whole token split attributed to its LAST model and is flagged ≈ — events.jsonl does not record a per-model input/cache split, so never fabricate one.
  • totalNanoAiu (Copilot's own reported consumption unit) is shown only as a labeled cross-check — never assumed equal to the AIC billing unit and never converted to USD or AIC. The authoritative estimate is token counts × per-MTok rates → USD → AIC via billing_unit.usd_per_credit.
  • Missing or empty session logs are reported as such, never guessed at.
  • If the engine errors, show the error and the file it choked on — don't silently skip it and report a clean number.

Same-named agent

For persona-isolated runs — a separate dispatch that should carry its own model pin instead of this session's model — use the usage custom agent: pick it in the /agent picker, or run copilot --agent usage -p "<task>". This skill and that agent are the same capability on two surfaces; the agent's frontmatter carries the model pin, this skill runs on whatever model the session already uses.

Installed?

If the literal {{POLYTROPOS_ROOT}} text is still visible above, the bundle is not installed — tell the user to run python3 bin/harness_select.py install --harness copilot (then /skills reload picks the skills up in-session).