Install
Install with PiG
pig install npm:pi-cache-keeperInstall with Pi
pi install npm:pi-cache-keeperPackages 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.
{
"image": "https://pi-cache-keeper.providers.dev/og.png",
"extensions": [
"./index.ts"
]
}README
Written by the package's publisher, shown as published in version 0.11.1 (README.md). PiG does not review it.
pi-cache-keeper
Summarize long Pi chats for less.
When a Pi chat gets long, Pi replaces older messages with a summary. On supported providers, pi-cache-keeper can lower the cost of that summary by reusing the conversation your provider has temporarily saved. It gives the summarizer the tool text the model saw during the chat, including long test logs. This fork of Nico Bailon's pi-cached-compaction also lets you choose how early to summarize and which model can take over.

A sample session, drawn for this README (media/figures.html); its figures are not a measurement. The measured numbers are in What it costs.
Install
pi install npm:pi-cache-keeper
Then run /reload in Pi (Pi loads extensions only at startup or on /reload). It needs Pi 1.6.0 or newer. It works as soon as it loads. The two extras marked off below wait until you turn them on.
What you get
- Keeps the cache warm during breaks (optional, off by default). Shortly before the cache expires, it sends a small refresh, timed by the cache lifetime that providers.dev supplies where Pi has none. It works on the Anthropic Messages, OpenAI Chat Completions and OpenAI Responses connections where it can safely re-send your last request. Claude through pi-claude-bridge,
openai-codex, Gemini and other APIs are left to Pi's own warmer. A refresh goes out only when its estimated cost fits the remaining budget, about the cost of one cache miss. A refresh that misses can take the total over budget: the docs' example spends $2.43 against $2.07. Without prices, it allows up to 10 refreshes per idle period. See it: the footer, e.g.keep-warm 2h until 16:40, $0.36 spent of $2.07. Keeping the cache warm. - Less to resend after a break. If Pi stays open and idle with a known cache lifetime, automatic compaction can summarize a large chat from the warm cache shortly before it expires. The default minimum is 140,000 tokens. Your next message then carries the summary and recent messages. A smaller chat, one whose cache lifetime is unknown, or a chat whose Pi was closed while you were away can pay to send everything again.
- A cheaper model you choose when the cache is cold (off). For a manual or size-triggered summary that can't use the cache, a model you selected (a cheaper one, or one on a login with spare quota) can try first. It also steps in when your session's model refuses the summary, or the chat no longer fits that model. Otherwise Pi uses its usual summarizer. A summary attempted only to beat cache expiry is skipped if the cache can't be used. If you choose a model with another provider, that provider receives the conversation text being summarized.
- Compacts at a threshold you set. With Pi's automatic compaction on, it checks after a turn and can summarize when the chat reaches 90% of the model's input capacity (the default), or a token cap you set. One turn can carry the chat past the threshold; the check after that turn can still produce a cached summary. See it:
/cache-keeper. - More of your tool output reaches the summarizer. Cached compaction uses the text already in the conversation, including the part past Pi's usual 2,000-character cut. That can include failures at the bottom of a log. Through pi-claude-bridge, Claude Code keeps a tool result over about 50 KB as a 2 KB preview, so the summary sees that preview. See it: Nico Bailon's tool-output comparison.
- A card with the cost of each summary. A cached summary sends the conversation exactly as it was, plus one instruction, so the provider can read it at its cache-read price instead of the full input price. After a cached summary, the card compares its cost with an estimate for Pi's compaction. If price data is missing, it compares token counts. A summary written by a fallback model shows its own cost, with no comparison.
- Model data from providers.dev. For matching models, the extension looks up available cache lifetimes, input limits and prices on providers.dev. Some input limits are the largest size tested. Missing figures stay unknown or use Pi's own values. The lookup sends only the names of the providers you have credentials for, nothing about your sessions. See it: the footer, e.g.
long 1h (in use) · api $3/$15 per M. - A countdown in the footer. Where the cache lifetime is known, the footer shows how long the cache stays warm:
cache warm · 59m left, thencache cold · next message full price. - Settings per session. One session can compact earlier, or stay warm longer, than the others.
On small chats, and on chats that mostly read big files, Pi's own compaction is often cheaper: it has little to send. When it takes over from this extension, Pi starts its lists of read and modified files over.
What it costs
Nico Bailon replayed a 667k-token chat on a Claude subscription using pi-cached-compaction, through pi-claude-bridge. Its recorded token use works out to $0.19 at Anthropic API rates. He estimated about $1.40 for Pi's usual summary. In that run, 665,973 of 667,091 prompt tokens came from the cache (99%), and a cache read cost 5% of the input price ($0.20 against $4 per million tokens). His other runs read less from the cache: 83% on the small GPT example, 79% on Kimi through opencode-go, and 76% mid-run through the updated bridge.
| Session at compaction | Pi's compaction | pi-cached-compaction (Nico's run) |
|---|---|---|
667k tokens, a real coding session (claude-opus-5-5) | ~328k tokens sent, ~$1.40 (estimated) | 667k sent, 99% from the cache; recorded tokens at API rates: $0.19 |
44k tokens, ten whole docs read (gpt-6-luna) | 5.9k sent, $0.00090 | 44k sent, 99% from the cache, $0.00097 |
2k tokens, a few tool calls (gpt-6-luna) | 0.3k sent, $0.00009 | 2.2k sent, 83% from the cache, $0.00035 |
- Whose numbers. Nico Bailon measured all of these for pi-cached-compaction, on 2026-10-21 with Pi 1.3.0: Nico's cost table and Nico's live tests. This extension keeps his method. Pi's side of the 667k row is the card's estimate; in his tests that estimate of the input tokens was 2–12% high, so the card slightly overstates the saving.
- What the summarizer sees. In that 667k chat, Pi's compaction would have cut 109 of 521 tool results, dropping 61% of the tool output. In 11 chats over 700k tokens, it would have shown the summarizer only 35–57% of the tool output. Both counts are Nico Bailon's, over whole sessions, including the recent messages Pi keeps word for word. No test compares the quality of the summaries.
- A break. Had that 667k cache expired, the next message would have written it all again: $5.33, calculated at the one-hour write price.
More rows and the reasons: What it costs.
Added to pi-cached-compaction
pi-cache-keeper is based on pi-cached-compaction by Nico Bailon (MIT), from its 0.2.0 release. The original already did these, and they are his work, kept here: compaction from the warm cache, with its byte-for-byte check of the request's start; the summary that stops at the first kept message; the compaction card; the cache countdown (from the model's lifetime, the cache write the provider reports, OpenAI's minimum or Kimi's options); compacting before the cache expires; the longer cache; pi-claude-bridge support; handling Pi's own automatic compaction; and the log. What this fork adds or changes:
| (blank) | pi-cached-compaction 0.2.0 | pi-cache-keeper |
|---|---|---|
| When to compact | Pi's own automatic compaction, near the end of the window | adds a configurable after-turn threshold (90% by default, compactAtPercent) and a token cap (compactAtTokens) |
| Summary length | at most 80% of Pi's reserveTokens (about 13k tokens) | up to the model's output limit, fitted to the window |
| A model you choose for fallback | no | yes (fallbackCompactionModel), also when your model refuses the summary or is too small |
| Cache warming during breaks, within an estimated budget | no | optional (keepWarmMinutes) |
| Stopping new idle refreshes in every window | no | /cache-keeper-stop |
| Warming a model again after two misses | no | /cache-keeper-warm |
| Settings | 3 keys, in JSON | 8 keys, a menu (/cache-keeper-settings), and per-session values |
| Model data (cache lifetimes, input limits, prices) | no | from providers.dev, /cache-keeper-refresh |
| Countdowns | the model's lifetime, the reported write, OpenAI's minimum, Kimi | adds countdowns for further models by looking up lifetimes on providers.dev |
| Compacting before expiry while Pi is busy | one try | tried again every second, with a last check just before sending |
| The footer | ⏱ 59m | cache warm · 59m left, cache cold · next message full price, the lifetimes, the price and warnings, fitted to the width |
| Status command | /cached-compaction | /cache-keeper, with the settings, keep-warm and model data |
| Proxies (Provimux, CLIProxyAPI) | no | what answered, with its price and cache lifetimes (Through a proxy) |
cache-flag for GPT on opencode-go | /cached-compaction cache-flag | removed: set the flag by hand in models.json (Providers) |
When switching, copy any settings you want from cachedCompaction to cacheKeeper in ~/.pi/agent/settings.json: this fork doesn't read the old key, so a value you set there (compactBeforeExpiry: false, say) goes back to this fork's default. This fork uses Pi 1.6.0 or newer and displays its own compaction cards. Earlier cards from the original stay in the session file but no longer appear.
The CHANGELOG has each version.
Commands
| Command | What it does |
|---|---|
/cache-keeper | Shows the cache's time left, whether the next compaction can read the cache, the settings, the model data and this session's latest log entries. |
/cache-keeper-settings | Opens a menu of the settings, for this session or for all sessions. |
/cache-keeper-refresh | Fetches the model data from providers.dev again, now. |
/cache-keeper-stop | Stops new idle refreshes in the Pi windows that share this agent directory and have loaded the extension. Each window resumes after your next message there. A refresh already sent can still cost. |
/cache-keeper-warm | Lets the extension warm a model again after two refreshes in a row missed the cache. |
Pi's own /compact goes through the extension too. Each command, with its output: Commands.
Settings
Change them with /cache-keeper-settings, or under cacheKeeper in ~/.pi/agent/settings.json. A setting marked "per session" can also be set for one session only.
| Setting | Default | Per session | What it does |
|---|---|---|---|
compactAtPercent | 90 | yes | Compact once the context fills this share of the window. 0 is off. |
compactAtTokens | 0 (off) | yes | Also compact once the context holds this many tokens, on any model. |
fallbackCompactionModel | "" (off) | yes | The model ("provider/modelId") that writes the summary when the cache can't be used. |
compactBeforeExpiry | true | yes | Compact 20 s before the cache expires, when Pi is idle. |
minContextTokens | 140000 | yes | Compact before expiry only from this many tokens. |
keepWarmMinutes | 0 (off) | yes | Keep the cache warm up to this many minutes after Pi goes idle. |
cacheRetention | "long" | no | Ask for the longer cache (1 hour on Anthropic, where a write costs 2× the input price, not 1.25×). "short" keeps Pi's. |
modelData | true | no | Read model data from providers.dev into Pi's models.json. |
Both layers, and a list of common tasks: Settings.
Providers
Cached compaction, the footer's countdown and the model data are three separate things, and each provider has its own mix:
| Provider | Compaction from the cache | Countdown in the footer | Compact before expiry | Longer cache |
|---|---|---|---|---|
| Anthropic API, Claude on opencode-go | yes | 1 hour (5 minutes with "cacheRetention": "short") | yes | 1 hour instead of 5 minutes |
| Claude through pi-claude-bridge | yes, on a copy of the Claude Code conversation (the extension can't check that request) | 1 hour | yes | Claude Code decides |
GPT-5.6+ on openai | yes, not tested live yet | The conversation cache is 30 minutes. The footer can show 12 hours when the model data describes the longer system-prompt cache. | yes, on that countdown | a 12-hour shared system prompt |
| GPT-5.6+ on opencode-go | yes | after a flag in models.json | after the flag | after the flag |
Kimi K3 on moonshotai, moonshotai-cn | yes, not tested live yet | 5 minutes or 1 hour | yes | 1 hour instead of 5 minutes |
openai-codex (ChatGPT sign-in) | yes, not tested live yet | with providers.dev's lifetime | yes, with that lifetime | no |
| Other Responses and Chat Completions APIs | yes | with a lifetime from providers.dev or your own, or the write an Anthropic Messages answer reports | yes, with a countdown | the provider's own |
| Google and others | no: Pi's compaction runs | when a lifetime is declared and the answer reports cache use | no cached pre-expiry summary on this API | no |
Model data covers more than this table: providers.dev has entries for many providers and logins, and what it has varies by model. Which providers.dev provider each Pi provider is, with an API key and with a login, comes from providers.dev's own match, and the lookup follows the login where its model has a matching entry. For ChatGPT through Pi's openai route, the extension checks both possible entries: where they differ it uses the smaller input limit or cache lifetime, a value only one has is not used, and prices that differ are left out. Through a gateway, the last answer's displayed figures can differ from the countdown. Works with lists every provider and login, and the providers.dev provider it is looked up at.
Details, and the opencode-go flag: Providers.
Using a proxy such as Provimux or CLIProxyAPI? The footer can say which account really answered, with its price and cache lifetimes: Through a proxy.
Works with
pi-cache-keeper reads providers.dev for 41 of Pi's 42 providers that take an API key, and for 6 of its 7 subscription logins. Which providers.dev provider each one is comes from providers.dev's own match (/api/v1/pi-providers).
Subscription logins
| Pi provider | providers.dev provider | How it is known |
|---|---|---|
anthropic | Claude Code (claude-subscription) | stated, with sources |
github-copilot | GitHub Copilot (github-copilot) | stated, with sources |
kimi-coding | Kimi For Coding (kimi.com) (kimi-code-plan-cn) | stated, with sources |
meta | Muse Code (meta-subscription) | stated, with sources |
openai | OpenAI Codex (ChatGPT plan) (openai-codex) or OpenAI (openai) | stated, with sources |
openai-codex | OpenAI Codex (ChatGPT plan) (openai-codex) | same id |
xai | not on providers.dev | stated, with sources |
API keys
| Pi provider | providers.dev provider | How it is known |
|---|---|---|
amazon-bedrock | Amazon Bedrock (amazon-bedrock) | same id |
ant-ling | Bailing (bailing) | paired by base URL |
anthropic | Anthropic (anthropic) | same id |
azure | Azure (azure) | same id |
baseten | Baseten (baseten) | same id |
cerebras | Cerebras (cerebras) | same id |
cloudflare-ai-gateway | Cloudflare AI Gateway (cloudflare-ai-gateway) | same id |
cloudflare-workers-ai | Cloudflare Workers AI (cloudflare-workers-ai) | same id |
deepseek | DeepSeek (deepseek) | same id |
fireworks | Fireworks AI (fireworks-ai) | paired by base URL |
github-copilot | GitHub Copilot (github-copilot) | same id |
google | Google (google) | same id |
google-vertex | Vertex (google-vertex) | same id |
groq | Groq (groq) | same id |
huggingface | Hugging Face (huggingface) | same id |
kimi-coding | Kimi For Coding (kimi.com) (kimi-code-plan-cn) | paired by base URL |
meta | Meta (meta) | same id |
minimax | MiniMax (minimax.io) (minimax) or MiniMax Token Plan (minimax.io) (minimax-coding-plan) | stated, with sources |
minimax-cn | MiniMax (minimax.cn) (minimax-cn) or MiniMax Token Plan (minimax.cn) (minimax-cn-coding-plan) | stated, with sources |
mistral | Mistral (mistral) | same id |
moonshotai | Moonshot AI (moonshotai) | same id |
moonshotai-cn | Moonshot AI (China) (moonshotai-cn) | same id |
nvidia | Nvidia (nvidia) | same id |
openai | OpenAI (openai) | same id |
opencode | OpenCode (opencode) | same id |
opencode-go | OpenCode Go (opencode-go) | same id |
openrouter | OpenRouter (openrouter) | same id |
qwen-token-plan | Alibaba Token Plan (alibaba-token-plan) | paired by base URL |
qwen-token-plan-cn | Alibaba Token Plan (China) (alibaba-token-plan-cn) | paired by base URL |
qwen-token-plan-individual | Alibaba Token Plan (alibaba-token-plan) | stated, with sources |
qwen-token-plan-individual-cn | Alibaba Token Plan (China) (alibaba-token-plan-cn) | stated, with sources |
radius | not on providers.dev | stated, with sources |
together | Together AI (togetherai) | paired by base URL |
typesafe | TypeSafe (typesafe) | same id |
vercel-ai-gateway | Vercel AI Gateway (vercel) | paired by base URL |
xai | xAI (xai) | same id |
xiaomi | Xiaomi (xiaomi) | same id |
xiaomi-token-plan-ams | Xiaomi Token Plan (Europe) (xiaomi-token-plan-ams) | same id |
xiaomi-token-plan-cn | Xiaomi Token Plan (China) (xiaomi-token-plan-cn) | same id |
xiaomi-token-plan-sgp | Xiaomi Token Plan (Singapore) (xiaomi-token-plan-sgp) | same id |
zai | Z.AI Coding Plan (zai-coding-plan) | stated, with sources |
zai-coding-cn | Zhipu AI Coding Plan (zhipuai-coding-plan) | paired by base URL |
Where two providers are named, the same key reaches either at the same address (a pay-as-you-go API or a coding plan), and pi-cache-keeper takes the values they share, or the smaller.
Not on providers.dev
radius(API key): Pi's own gateway. providers.dev has no provider for it.xai(login): Pi's SuperGrok or X Premium sign-in. providers.dev has no provider for a Grok subscription; xai is the API, paid per token.
Where providers.dev's match can't be read and none was saved, and for a provider it doesn't list (one of your models.json, say), the extension's own table stands in.
Documentation
- Commands: each command, its output, and what it changes.
- The footer: every part of the footer line.
- Settings: both layers, and common tasks.
- Compaction: from the cache, the card and the log, when full, before expiry, and how it works.
- Compacting with another model: the fallback model, and where your conversation goes.
- Keeping the cache warm: the budget, who warms what, and stopping it.
- Model data from providers.dev: what is fetched and written, and privacy.
- Through a proxy: the
model-upstreamsevents, and Provimux. - Providers · What it costs · Limitations
- Live tests: Nico Bailon's runs behind the numbers.
- Keep-warm coverage, stopping warming (design), publishing.
Origins and credit
pi-cache-keeper is based on pi-cached-compaction by Nico Bailon, released under the MIT licence, starting from its 0.2.0 release. Compaction from the warm cache, the compaction card, the cache countdown, compacting before the cache expires and the longer cache are his work, and his commits are kept in this repository's history. His releases are kept in the CHANGELOG as he wrote them, and the LICENSE carries his copyright line beside this project's. This is a separate project; it is not maintained by Nico Bailon.
Watch Nico Bailon's demo in the original README (78 seconds; it uses the old name).