← Catalog

pi-cache-keeper

Pi can summarize long chats for less by reusing the conversation your provider saved. This fork of pi-cached-compaction adds early summaries, a model you can choose for fallback, and optional cache warming during breaks.

Extension

Install

Install with PiG

pig install npm:pi-cache-keeper

Install with Pi

pi install npm:pi-cache-keeper
Review before installing

Packages 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. The compaction card reads "cached compaction (ctrl+o for details). 15:05:52 compact when full: cached, 99% of 904k from cache, 5k out, 41.6s, summary 9840 chars. vs Pi's compaction: 75% less, $0.59 instead of ~$2.4 (it sends ~451k tokens, none from cache). 15:06:34 saved, 903k tokens summarized." Below the editor, Pi's footer ends with "cache warm · 59m left · long 1h (in use) · short 5m · sent 1h · sub, counted at $4/$20 per M".

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, then cache 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 compactionPi's compactionpi-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.0009044k sent, 99% from the cache, $0.00097
2k tokens, a few tool calls (gpt-6-luna)0.3k sent, $0.000092.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.0pi-cache-keeper
When to compactPi's own automatic compaction, near the end of the windowadds a configurable after-turn threshold (90% by default, compactAtPercent) and a token cap (compactAtTokens)
Summary lengthat 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 fallbacknoyes (fallbackCompactionModel), also when your model refuses the summary or is too small
Cache warming during breaks, within an estimated budgetnooptional (keepWarmMinutes)
Stopping new idle refreshes in every windowno/cache-keeper-stop
Warming a model again after two missesno/cache-keeper-warm
Settings3 keys, in JSON8 keys, a menu (/cache-keeper-settings), and per-session values
Model data (cache lifetimes, input limits, prices)nofrom providers.dev, /cache-keeper-refresh
Countdownsthe model's lifetime, the reported write, OpenAI's minimum, Kimiadds countdowns for further models by looking up lifetimes on providers.dev
Compacting before expiry while Pi is busyone trytried again every second, with a last check just before sending
The footer⏱ 59mcache 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)nowhat answered, with its price and cache lifetimes (Through a proxy)
cache-flag for GPT on opencode-go/cached-compaction cache-flagremoved: 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

CommandWhat it does
/cache-keeperShows 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-settingsOpens a menu of the settings, for this session or for all sessions.
/cache-keeper-refreshFetches the model data from providers.dev again, now.
/cache-keeper-stopStops 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-warmLets 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.

SettingDefaultPer sessionWhat it does
compactAtPercent90yesCompact once the context fills this share of the window. 0 is off.
compactAtTokens0 (off)yesAlso compact once the context holds this many tokens, on any model.
fallbackCompactionModel"" (off)yesThe model ("provider/modelId") that writes the summary when the cache can't be used.
compactBeforeExpirytrueyesCompact 20 s before the cache expires, when Pi is idle.
minContextTokens140000yesCompact before expiry only from this many tokens.
keepWarmMinutes0 (off)yesKeep the cache warm up to this many minutes after Pi goes idle.
cacheRetention"long"noAsk for the longer cache (1 hour on Anthropic, where a write costs 2× the input price, not 1.25×). "short" keeps Pi's.
modelDatatruenoRead 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:

ProviderCompaction from the cacheCountdown in the footerCompact before expiryLonger cache
Anthropic API, Claude on opencode-goyes1 hour (5 minutes with "cacheRetention": "short")yes1 hour instead of 5 minutes
Claude through pi-claude-bridgeyes, on a copy of the Claude Code conversation (the extension can't check that request)1 houryesClaude Code decides
GPT-5.6+ on openaiyes, not tested live yetThe conversation cache is 30 minutes. The footer can show 12 hours when the model data describes the longer system-prompt cache.yes, on that countdowna 12-hour shared system prompt
GPT-5.6+ on opencode-goyesafter a flag in models.jsonafter the flagafter the flag
Kimi K3 on moonshotai, moonshotai-cnyes, not tested live yet5 minutes or 1 houryes1 hour instead of 5 minutes
openai-codex (ChatGPT sign-in)yes, not tested live yetwith providers.dev's lifetimeyes, with that lifetimeno
Other Responses and Chat Completions APIsyeswith a lifetime from providers.dev or your own, or the write an Anthropic Messages answer reportsyes, with a countdownthe provider's own
Google and othersno: Pi's compaction runswhen a lifetime is declared and the answer reports cache useno cached pre-expiry summary on this APIno

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 providerproviders.dev providerHow it is known
anthropicClaude Code (claude-subscription)stated, with sources
github-copilotGitHub Copilot (github-copilot)stated, with sources
kimi-codingKimi For Coding (kimi.com) (kimi-code-plan-cn)stated, with sources
metaMuse Code (meta-subscription)stated, with sources
openaiOpenAI Codex (ChatGPT plan) (openai-codex) or OpenAI (openai)stated, with sources
openai-codexOpenAI Codex (ChatGPT plan) (openai-codex)same id
xainot on providers.devstated, with sources

API keys

Pi providerproviders.dev providerHow it is known
amazon-bedrockAmazon Bedrock (amazon-bedrock)same id
ant-lingBailing (bailing)paired by base URL
anthropicAnthropic (anthropic)same id
azureAzure (azure)same id
basetenBaseten (baseten)same id
cerebrasCerebras (cerebras)same id
cloudflare-ai-gatewayCloudflare AI Gateway (cloudflare-ai-gateway)same id
cloudflare-workers-aiCloudflare Workers AI (cloudflare-workers-ai)same id
deepseekDeepSeek (deepseek)same id
fireworksFireworks AI (fireworks-ai)paired by base URL
github-copilotGitHub Copilot (github-copilot)same id
googleGoogle (google)same id
google-vertexVertex (google-vertex)same id
groqGroq (groq)same id
huggingfaceHugging Face (huggingface)same id
kimi-codingKimi For Coding (kimi.com) (kimi-code-plan-cn)paired by base URL
metaMeta (meta)same id
minimaxMiniMax (minimax.io) (minimax) or MiniMax Token Plan (minimax.io) (minimax-coding-plan)stated, with sources
minimax-cnMiniMax (minimax.cn) (minimax-cn) or MiniMax Token Plan (minimax.cn) (minimax-cn-coding-plan)stated, with sources
mistralMistral (mistral)same id
moonshotaiMoonshot AI (moonshotai)same id
moonshotai-cnMoonshot AI (China) (moonshotai-cn)same id
nvidiaNvidia (nvidia)same id
openaiOpenAI (openai)same id
opencodeOpenCode (opencode)same id
opencode-goOpenCode Go (opencode-go)same id
openrouterOpenRouter (openrouter)same id
qwen-token-planAlibaba Token Plan (alibaba-token-plan)paired by base URL
qwen-token-plan-cnAlibaba Token Plan (China) (alibaba-token-plan-cn)paired by base URL
qwen-token-plan-individualAlibaba Token Plan (alibaba-token-plan)stated, with sources
qwen-token-plan-individual-cnAlibaba Token Plan (China) (alibaba-token-plan-cn)stated, with sources
radiusnot on providers.devstated, with sources
togetherTogether AI (togetherai)paired by base URL
typesafeTypeSafe (typesafe)same id
vercel-ai-gatewayVercel AI Gateway (vercel)paired by base URL
xaixAI (xai)same id
xiaomiXiaomi (xiaomi)same id
xiaomi-token-plan-amsXiaomi Token Plan (Europe) (xiaomi-token-plan-ams)same id
xiaomi-token-plan-cnXiaomi Token Plan (China) (xiaomi-token-plan-cn)same id
xiaomi-token-plan-sgpXiaomi Token Plan (Singapore) (xiaomi-token-plan-sgp)same id
zaiZ.AI Coding Plan (zai-coding-plan)stated, with sources
zai-coding-cnZhipu 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

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

Website: https://pi-cache-keeper.providers.dev