pi-token-tracker
Pi extension that tracks token usage across all sessions including taskplane workers and merge agents. Writes per-call token records to usage.jsonl and provides a token-report command.
Package details
Install pi-token-tracker from npm and Pi will load the resources declared by the package manifest.
$ pi install npm:pi-token-tracker- Package
pi-token-tracker- Version
0.0.1- Published
- May 19, 2026
- Downloads
- not available
- Author
- skyscribe
- License
- MIT
- Types
- extension
- Size
- 21.1 KB
- Dependencies
- 0 dependencies · 1 peer
Pi manifest JSON
{
"extensions": [
"./index.ts"
]
}Security note
Pi packages can execute code and influence agent behavior. Review the source before installing third-party packages.
README
pi-token-tracker
Pi extension that tracks per-call token usage across all sessions, including taskplane lane workers and merge agents.
How it works
message_endhook: Writes one JSONL line per assistant response to~/.pi/token-logs/usage.jsonltoken-reportcommand: Scans usage.jsonl + taskplane runtime exit summaries and prints a hierarchical vendor/model breakdown
Installation
# Clone and install
git clone https://github.com/skyscribe-yf/pi-token-tracker.git
cd pi-token-tracker
npm link
# Add to pi settings
# Edit ~/.pi/agent/settings.json and add "npm:pi-token-tracker" to the "packages" array:
# {
# "packages": [
# "npm:pi-token-tracker",
# ...
# ]
# }
Why a pi package?
Taskplane lane workers and merge agents run with --no-extensions, which prevents auto-discovery of user extensions from the working directory. However, taskplane's loadPiSettingsPackages mechanism automatically forwards pi packages (from settings.json) to worker processes as explicit -e flags.
By installing this extension as a pi package, it gets loaded in:
- Main pi sessions ✓
- Taskplane lane workers ✓
- Taskplane merge agents ✓
Safety in RPC mode
The extension is safe to load in headless RPC worker processes:
session_starthook uses try-catch to handle missing UItoken-reportcommand uses try-catch for notify in UI-less contexts
License
MIT