Skip to content
PidebugCLI & tooling

Trace whether /usage counts pi -p sessions in pi-mono

Session from pi-extensions-sessions on Hugging Face by thomasmustier · MIT · condensed by Coders Talk

2msession
0interventions
GOAL

Determine whether the /usage extension's token counting includes sessions run via `pi -p` (print mode) or only interactive pi sessions, by reading through the pi-mono source.

  1. Prompt · +0
    Does /usage only count tokens used inside pi, or does it also account for pi -p? Source is in ~/pi-mono but don't edit anything there.
  2. Agent did · +0m
    Located and read the usage-extension source (README.md, index.ts) to understand how it aggregates usage stats.
  3. Agent did · +0m
    Searched pi-mono packages for session and print-mode handling, then read print-mode.ts to see how `pi -p` runs and whether it persists sessions.
  4. Agent did · +0m
    Traced AgentSession and createAgentSession/sdk.ts to see how events are subscribed and persisted across all run modes (interactive, print, rpc).
  5. Agent did · +1m
    Dug into session-manager.ts and config.ts to confirm SessionManager.create() default behavior, session directory resolution, and file writing logic used by both interactive and print mode.
  6. Outcome · +2m
    Answered: /usage does count pi -p sessions, since print mode still uses AgentSession and persists events to the same session files unless --no-session is passed.
VERDICT

I'd start by pointing the agent straight at usage-extension/index.ts and print-mode.ts together, since the answer hinges on whether both paths write to the same session files. No corrections were needed here — it was a pure read-only investigation that correctly traced the call chain from /usage's file reading down to AgentSession's persistence logic.

I tried this · 0

Discussion · 0

How Builds work