|
| 1 | +# usage extension |
| 2 | + |
| 3 | +Adds a `/usage` slash command that reads your local pi session files, aggregates token spend, and renders an inline dashboard with three views. |
| 4 | + |
| 5 | +## Install |
| 6 | + |
| 7 | +```bash |
| 8 | +pi install npm:pi-mono-usage |
| 9 | +``` |
| 10 | + |
| 11 | +## Views |
| 12 | + |
| 13 | +- **Summary** — totals, top providers, and an environmental footprint estimate (kWh, kg CO₂e, real-world equivalences) computed from [`impact-equivalences`](https://www.npmjs.com/package/impact-equivalences). |
| 14 | +- **Providers** — per-provider table that expands into per-model rows. Includes session/call counts, cost, and token breakdown (input, output, cache). |
| 15 | +- **Patterns** — cost-driver insights for the selected period: parallel sessions, oversized contexts, large uncached prompts, marathon sessions, and top-session concentration. |
| 16 | + |
| 17 | +## Period selector |
| 18 | + |
| 19 | +Tab between `Today`, `This Week`, `Last Week`, and `All Time`. Each period is computed once on open from the same parsed dataset, so cycling is instant. |
| 20 | + |
| 21 | +## Keybindings |
| 22 | + |
| 23 | +| Key | Action | |
| 24 | +| ----------------- | -------------------------------------- | |
| 25 | +| `Tab` / `←` / `→` | Cycle period | |
| 26 | +| `v` | Cycle view | |
| 27 | +| `1` / `2` / `3` | Jump to Summary / Providers / Patterns | |
| 28 | +| `↑` / `↓` | Move provider cursor (Providers view) | |
| 29 | +| `Enter` / `Space` | Expand / collapse a provider | |
| 30 | +| `q` / `Esc` | Close the panel | |
| 31 | + |
| 32 | +## Data source |
| 33 | + |
| 34 | +Reads `~/.pi/agent/sessions/**/*.jsonl` (or `$PI_CODING_AGENT_DIR/sessions`). For each `assistant` message with a `usage` block, the extension records cost and token counts. Duplicate turns from branched session files are deduplicated by a fingerprint over timestamp + token counts. |
| 35 | + |
| 36 | +## Sustainability estimate |
| 37 | + |
| 38 | +The Summary view feeds the period's charged tokens (`input + output + cacheWrite`) into `impact-equivalences` `estimateAiImpact`, which returns electricity (kWh) and carbon (kg CO₂e) ranges along with formatted real-world equivalences (e.g. _"~X average US households for a day"_). Estimates are illustrative — see the package's source attribution for boundaries and assumptions. |
0 commit comments