pi-cache-graph
Pi extension for visualizing context cache distribution and statistics
Package details
Install pi-cache-graph from npm and Pi will load the resources declared by the package manifest.
$ pi install npm:pi-cache-graph- Package
pi-cache-graph- Version
0.2.0- Published
- May 2, 2026
- Downloads
- 245/mo · 245/wk
- Author
- championswimmer
- License
- MIT
- Types
- extension
- Size
- 44 KB
- Dependencies
- 0 dependencies · 3 peers
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-cache-graph
A project-local pi extension that adds cache inspection commands for monitoring LLM context cache usage.
This extension was built primarily to add observability to the pi-context-prune extension — which compacts the session context to keep token usage down. pi-cache-graph lets you see in real time how effectively the cache is being used and how pruning affects cache hit rates over a session.

Adds cache inspection commands:
/cache graph— shows cache hit % over time for assistant turns across the current session timeline/cache stats— shows per-message token/cache breakdown for assistant messages across the whole session tree, plus cumulative totals/cache export— writes the same stats data tosession-name.csvat the project root
Commands
/cache graph
Opens a TUI overlay with three switchable views:
| Key | View | Description |
|---|---|---|
1 |
Per-turn (%) | Cache hit % per individual turn (default) |
2 |
Cumulative (%) | Running cache hit % across all turns so far |
3 |
Cumulative (total) | Running cumulative token volumes (input / cacheWrite / cacheRead) |
Keyboard shortcuts inside the dialog:
1/2/3— jump directly to that viewv— cycle view forwardV(Shift+v) — cycle view backward↑/↓,PgUp/PgDn,Home/End— scrollq/Esc— close
All views show active-branch totals and whole-tree totals at the top.
Cache hit % is computed as:
cacheRead / (input + cacheRead + cacheWrite)
The denominator is the full prompt size that was sent in the turn:
input— fresh, non-cached prompt tokenscacheRead— prompt tokens served from cachecacheWrite— prompt tokens that were freshly written to cache this turn (Anthropic-style providers report this separately frominput; OpenAI-style providers reportcacheWrite = 0, so the formula behaves identically there)
The cumulative-total chart uses distinct glyphs per series (▇ input, ░ cacheWrite, ▒ cacheRead) with a dynamic scale shown in the legend (default: 1 row = 5,000 tokens).
/cache stats
Opens a TUI overlay table that shows:
- one row per assistant message with usage data
- whether the message is on the current active branch
- prompt / received / cache-hit / cache-write tokens
- per-message cache hit %
- cumulative totals for the active branch and the whole tree
/cache export
Writes a CSV to the project root:
- filename:
session-name.csv - uses the current pi session name when available
- falls back to the session file basename if the session has no explicit name
- contains summary rows plus the per-message rows shown in
/cache stats - can be opened in Excel to build graphs from the exported columns
Install from npm
Install globally via pi:
pi install pi-cache-graph
Or add it to your pi settings manually in .pi/settings.json:
{
"packages": [
"pi-cache-graph"
]
}
Once installed, the /cache commands are available in any pi session.
Install from local source (development)
Clone the repo and run pi with this extension directly:
git clone https://github.com/championswimmer/pi-cache-graph.git
cd pi-cache-graph
npm install
pi -e .
Or install the local path into pi:
pi install /path/to/pi-cache-graph
Or add it to .pi/settings.json:
{
"packages": [
"/path/to/pi-cache-graph"
]
}
Development
npm install
npm run check
Maintainer release workflow
This repo includes a project-local Pi release workflow for maintainers:
- prompt template:
/release <major|minor|patch> - skill:
.agents/skills/release/SKILL.md - helper script:
scripts/release.mjs - detailed notes:
docs/releasing.md
The release flow bumps the version, creates the release tag, pushes main plus the tag, and then relies on .github/workflows/publish.yml to publish to npm.
Files
index.ts— extension entrypointsrc/index.ts— command registrationsrc/session-data.ts— session traversal and metric computationsrc/cumulative.ts— cumulative series computation (pure, no UI dependency)src/cache-math.ts— cache hit % and totals calculationssrc/format-utils.ts— number/percent formatting helperssrc/graph-view.ts— graph renderingsrc/stats-view.ts— stats table renderingsrc/scroll-dialog.ts— scrollable TUI overlay componentsrc/render-utils.ts— shared rendering helperssrc/export.ts— CSV export logicsrc/types.ts— shared TypeScript interfaces