# cost Token and spend telemetry for Pi. ## Install / load Loaded through the root `pi-ext` package. See [root README](../../README.md). ## Commands / tools / settings Commands: none. Tools: none. Settings: none. Hooks: - `session_start`: reads current-month session files, resets counters, publishes first snapshot when UI exists. - `agent_start`, `agent_end`, `tool_execution_end`: refresh telemetry. - `model_select`, `session_compact`: clears snapshot signature, then refreshes telemetry. - `session_shutdown`: clears published status/footer segments. Events emitted: - `footer:segment` when `@bugabinga/pi-ext-footer` is loaded: `tokens`, `cost` in the `llm` zone. `tokens` uses `muted`, order `2`. `cost` uses `success`, order `3`. UI status: - `cost` status fallback when shared footer is not loaded. ## Behavior Shows last assistant-turn token usage, turn cost, session cost, and current-month cost. Token label uses input, output, and cache-read counts. Cache reads use `◐` and `` with cache percentage when mixed with uncached input. No token usage shows `↑0`. Uses provider-reported `usage.cost.total` when present and greater than zero. If reported cost is zero or missing, estimates cost only for built-in `zai` and `minimax` pricing rows. Unknown provider/model prices produce `$0` estimated cost. Session cost is summed from assistant messages in the active branch. Turn cost is the increase since the previous telemetry sync. Monthly cost is summed from `.jsonl` session files whose names start with the current `YYYY-MM`, scanning `dirname(getSessionDir())` and its direct child directories. Cost label shows turn cost, `Σ` session cost, and `` monthly cost. Monthly cost is shown only when it is greater than session cost. Cost label is hidden when all costs are zero. Telemetry publishes only when UI exists. Duplicate snapshots are skipped by signature. Read/parse/update errors are swallowed so the agent loop keeps running.