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
Click a segment to jump to that moment
2msession
0interventions
by library · 2d
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.
- +0Prompt · +0Does /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.
- +0mAgent did · +0mLocated and read the usage-extension source (README.md, index.ts) to understand how it aggregates usage stats.
- +0mAgent did · +0mSearched 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.
- +0mAgent did · +0mTraced AgentSession and createAgentSession/sdk.ts to see how events are subscribed and persisted across all run modes (interactive, print, rpc).
- +1mAgent did · +1mDug 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.
- +2mOutcome · +2mAnswered: /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.