@yusukeshib/pi-token-counter
Append each tool's own output token cost to its tool-use row, color-coded by size.
Package details
Install @yusukeshib/pi-token-counter from npm and Pi will load the resources declared by the package manifest.
$ pi install npm:@yusukeshib/pi-token-counter- Package
@yusukeshib/pi-token-counter- Version
0.1.1- Published
- Jun 6, 2026
- Downloads
- not available
- Author
- yusukeshib
- License
- MIT
- Types
- extension
- Size
- 339.6 KB
- Dependencies
- 0 dependencies · 2 peers
Pi manifest JSON
{
"extensions": [
"./extensions"
],
"image": "https://raw.githubusercontent.com/yusukeshib/pi-token-counter/main/assets/preview.png"
}Security note
Pi packages can execute code and influence agent behavior. Review the source before installing third-party packages.
README
@yusukeshib/pi-token-counter
A pi extension that appends each tool's own output token cost to its tool-use row, color-coded by size. This is the tool's own contribution to the context (its result content) — not the cumulative total.
What it looks like

Each tool-use row gains a trailing token count, colored by how much it adds:
read src/main.rs +312 tok
$ npm test -- --watch=false +1,840 tok
grep "TODO" src +6,204 tok
| Color | Meaning | Threshold |
|---|---|---|
| blue (accent) | small output | < 1,000 tok |
| yellow (warning) | medium output | < 5,000 tok |
| red (error) | large output | >= 5,000 tok |
The token estimate uses the same heuristic as pi's built-in estimator (text characters / 4).
Install
pi install npm:@yusukeshib/pi-token-counter
Via git (no npm publish required):
pi install git:github.com/yusukeshib/pi-token-counter
Try it without installing:
pi -e npm:@yusukeshib/pi-token-counter
How it works
The tool_result event carries each tool's result content, so the extension
estimates its tokens there and caches the value by toolCallId. It overrides
only renderCall for the built-in tools (read / bash / edit / write / grep /
find / ls) to append the colored token count — renderResult is left untouched
so pi's built-in result rendering (diffs, syntax highlighting, etc.) is fully
preserved. When a result arrives the row re-renders and renderCall reads the
cached estimate.
License
MIT
