omp packages

@twkrash/pi-headroom0.2.2

Headroom compression for Pi tool results: each result compressed once and replayed byte for byte, so the prompt cache stays intact. Originals stay in the session. Works with every provider and with subagents.

GitHub Actions Published 4 days ago MIT ~853 downloads/mo

Untested on omp

This is a pi package. No one has reported whether it works on omp yet. If you try it, add your result below.

Did it work for you?

Result

One report per person. A new report replaces your old one.

Reports 0

No reports yet.

Readme

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.

npm version

CI

GitHub release

license: MIT

node: >=22.19.0

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/9 compressed | 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_retrieve works 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.

@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 /headroom command to switch compression on and off.

Install

  1. Install and start Headroom:

    uv tool install --python 3.13 "headroom-ai[all]"
    headroom proxy --port 8787
    
  2. Install the extension:

    pi install npm:@twkrash/pi-headroom
    
  3. Start 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 seq lines, 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 more marker the model may follow back.
  • context-mode's ctx_execute, ctx_search and ctx_batch output 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_result handler 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; no tool result has gone through it yet this session.
headroom ready · 0/179 compressed 179 large results were sent, none compressed. Headroom compresses JSON, logs and search output, not prose or source code, so a session that mostly runs cat or reads docs stays here. File reads (Pi's read tool) are never sent to the proxy and are not counted.
headroom compressing… A tool result is on its way through the proxy.
headroom -47.5k tok (89%) · 2/9 compressed Tokens saved this session, the share of the compressed results, and how many of the 9 results were compressed.
headroom offline: <reason> Headroom is not installed, its proxy is not running, or the proxy returned an error or timed out. The status clears the next time a compress request gets an answer.

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.
HEADROOM_TIMEOUT_MS 30000 How long a compress or retrieve request may take. The first request after the proxy starts loads its models and is the slowest.

Limits

  • The proxy keeps originals for 30 minutes (HEADROOM_CCR_TTL_SECONDS). After that, headroom_retrieve reads 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 headroom on PATH.

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 ./

License

MIT