Install
Install with PiG
pig install npm:@twkrash/pi-headroomInstall with Pi
pi install npm:@twkrash/pi-headroomPackages run code with your permissions and influence agent behavior. Catalog inclusion is not a security audit. Review the source before installing a third-party package.
Pi manifest JSON
The pi field of package.json.
{
"extensions": [
"./src/index.ts"
]
}README
Written by the package's publisher, shown as published in version 0.2.1 (README.md). PiG does not review it.
Pi Headroom
Smaller tool results for Pi, without breaking the prompt cache.
Headroom compression for Pi — every provider, every subagent, each result compressed once and replayed byte for byte.
What is Pi Headroom?
Coding agents spend most of their input tokens re-reading tool output: logs, JSON, search results, file listings. Headroom shrinks that output algorithmically, with no LLM call. On real tool output from Pi:
| Tool output | Before | After | How |
|---|---|---|---|
1,500-line application log with one FATAL line | 12,816 tokens | 47 tokens | repeated INFO lines folded; the FATAL line kept |
| 400-row JSON array | 13,880 tokens | 5,732 tokens | rewritten as a table, nothing lost |
Before each model call, Pi Headroom sends every new large tool result through your local Headroom proxy, once, and records the result in the session. Every later call replays that recorded text byte for byte, while the session keeps the original. Anything Headroom dropped stays one tool call away: the model calls headroom_retrieve with the hash from the Retrieve more: hash=… marker and gets the original back, from the proxy or, once the proxy has let it go, from the session.
caveman level: LITE | headroom -47.5k tok (89%) · 2 results | jev: auto
Why another Headroom extension?
Pi already has Headroom extensions. They all compress in Pi's context hook, which runs before every model call: the conversation is compressed again on each request, and nothing is recorded. Provider prompt caches match on the exact bytes of the conversation prefix, so that approach relies on every pass producing byte-identical output for messages the provider has already cached, through proxy restarts, outages and Headroom upgrades.
Pi Headroom follows Headroom's own cache mode instead, which freezes what the provider has cached and compresses only new content, and makes that state part of the session:
- Compress once. A tool result after the last assistant message has never been sent, so it is compressed now. The decision is stored with
pi.appendEntry(). - Replay forever. Every later request sends the stored text byte for byte, without calling the proxy.
/resume, restarts and proxy restarts change nothing. - Never rewrite the past. A result that was already sent unchanged (Headroom saved too little, the proxy was down, the extension was installed mid-session) stays unchanged while the provider may have it cached.
- Use the free moment. A compaction replaces older history with a summary, so the first request after it has nothing cached past the system prompt. On that request every kept result that is not yet compressed gets another chance.
- Keep the original. The session stores the full tool result, so
headroom_retrieveworks for the life of the session, and uninstalling the extension brings every original back.
It hooks context_with_system, which sends the returned messages as they are; the plain context hook would rebuild the leading system message whenever the list changes.
| (blank) | @twkrash/pi-headroom | @casualjim/pi-headroom | @cltec/pi-make-headroom | pi-headroom |
|---|---|---|---|---|
| When it compresses | once per tool result, before the first call that sends it | every model call | every model call | every model call |
| Cache stability | stored decisions, replayed byte for byte | recompression must repeat exactly | recompression must repeat exactly | recompression must repeat exactly |
| What the session stores | original text, plus the compressed text | original text | original text | original text |
| Headroom proxy | yours, never started for you; setup notice if missing | yours | installed and run in a private venv | installed with pip and run by the extension |
headroom_retrieve tool | ✓, falls back to the session when the proxy's copy has expired | ✓ | — | — |
Pi's truncation note ([Showing lines … Full output: …]) | kept aside, re-appended verbatim | — | — | — |
| Subagents | one settings.json entry | — | — | — |
| Headroom dashboard | listed as Pi (x-client: pi) | — | — | — |
| Pi package namespace | @earendil-works | @earendil-works (also runs in omp) | @earendil-works | @mariozechner |
The comparison reflects each package's published source as of 2026-11-25. A "—" means the feature was not found in that package's source, not that it cannot be configured. Pick the one that fits:
- Pi Headroom if you want cache-stable savings across every provider and subagent and you run the Headroom proxy yourself.
- @cltec/pi-make-headroom if you want the extension to install and manage Headroom for you.
- @casualjim/pi-headroom if you also run omp and want one extension for both, or want its
/headroomcommand to switch compression on and off.
Install
Install and start Headroom:
uv tool install --python 3.13 "headroom-ai[all]" headroom proxy --port 8787Install the extension:
pi install npm:@twkrash/pi-headroomStart Pi. The footer shows
headroom ready.
If the proxy does not answer at session start, Pi shows a notice with the install or start command, once per Pi process, and tool results pass through unchanged.
Subagents
pi-subagents starts a child without auto-discovered extensions whenever the agent has its own extensions list. Add Pi Headroom to subagents.defaultSubagentOnlyExtensions in ~/.pi/agent/settings.json so every child loads it:
"subagents": {
"defaultSubagentOnlyExtensions": ["~/.pi/agent/npm/node_modules/@twkrash/pi-headroom/src/index.ts"]
}
Children share the same proxy, so headroom_retrieve works inside them too.
What gets compressed
- A tool result whose content is one text block of at least 2,000 characters.
- Not results that mix text and images, not shorter results, and never
headroom_retrieve's own output. - Headroom decides what it can shrink. Output without a recognisable shape, such as plain
seqlines, comes back unchanged and the original is kept. - A compression is kept only if it saves at least 200 tokens and at least a tenth of the result. A smaller saving is not worth a
Retrieve moremarker the model may follow back. - context-mode's
ctx_execute,ctx_searchandctx_batchoutput is skipped without calling the proxy: it is already summarised. Without context-mode installed, no result carries those names. - Other extensions that shrink tool output in their own
tool_resulthandler run first. Pi Headroom then sees their output and compresses it only if it is still at least 2,000 characters, so nothing is compressed twice.
Footer and dashboard
| Footer status | Meaning |
|---|---|
headroom ready | The proxy answered; nothing compressed yet this session. |
headroom compressing… | A tool result is on its way through the proxy. |
headroom -47.5k tok (89%) · 2 results | Tokens saved this session, the share of the compressed results, and their count. |
headroom offline: <reason> | Headroom is not installed, its proxy is not running, or the proxy returned an error. |
Every request carries x-client: pi, so the Headroom dashboard at http://127.0.0.1:8787/dashboard lists Pi's savings under its own Pi agent, next to Claude Code or any other client using the same proxy.
Configuration
| Variable | Default | Purpose |
|---|---|---|
HEADROOM_URL | http://127.0.0.1:8787 | Headroom proxy base URL. |
Limits
- The proxy keeps originals for 30 minutes (
HEADROOM_CCR_TTL_SECONDS). After that,headroom_retrievereads them from the session. Subagents run with--no-session, so theirs last as long as the subagent. - The session file grows by the compressed text of each compressed result, next to the original it already holds.
- The "not installed" check looks for a POSIX executable named
headroomonPATH.
Run from source
git clone https://github.com/twKrash/pi-headroom.git
cd pi-headroom
npm ci
npm run format:check && npm run lint && npm run typecheck && npm run knip
npm test
pi install ./