Skip to content

Releases: nicobailon/pi-cached-compaction

Release list

v0.2.0

Choose a tag to compare

@nicobailon nicobailon released this 24 Oct 06:00

If you use Kimi K3 on Moonshot's API, its prompt cache now lasts an hour in interactive sessions instead of five minutes. A short break no longer means paying to write the whole session into the cache again. The footer counts down Kimi's cache like it does for Claude and GPT, and the session compacts from the warm cache just before it expires. Compacting before expiry also waits longer now, until a session holds 140k tokens, so shorter sessions keep their full history through a break.

Highlights

  • Kimi K3 on Moonshot's API keeps its cache for an hour in interactive sessions.
  • The footer counts down Kimi's cache, and the session compacts just before it expires.
  • Compacting before expiry starts at 140k tokens of context instead of 50k.

Need to know

Writing Kimi's 1-hour cache costs 2× the input price, where the 5-minute cache costs 1×. To keep the 5-minute cache, set "cacheRetention": "short" under cachedCompaction in ~/.pi/agent/settings.json. If you want compacting before expiry to start sooner, set minContextTokens there, for example 50000 for the old behavior.

Changelog

Highlights

  • Kimi K3 on Moonshot's API keeps its cache for an hour in interactive sessions, so a coffee break no longer means paying to write the whole session again.
  • The footer counts down Kimi's cache, and the session compacts just before it expires.
  • Compacting before expiry now waits until a session holds 140k tokens, so shorter sessions keep their full history through a break.

Added

  • Kimi K3's 1-hour cache — On Moonshot's API (moonshotai and moonshotai-cn), interactive sessions now ask Kimi K3 for its 1-hour cache instead of the 5-minute default, so ordinary breaks don't expire it. The footer counts down either lifetime, and the session compacts before it expires. Writing a 1-hour cache costs 2× the input price; set cacheRetention: "short" to keep 5 minutes. Thanks @fungilation for the request (#1).

Changed

  • Compacting before expiry waits for bigger sessions — It now starts at 140k tokens of context instead of 50k, so shorter sessions keep their full history through a break. Set minContextTokens under cachedCompaction in ~/.pi/agent/settings.json to change it.
  • /cached-compaction wording — When the last request didn't use the cache, it now says so in the same words as the compaction card.

v0.1.0

Choose a tag to compare

@nicobailon nicobailon released this 22 Oct 17:51

pi-cached-compaction is a Pi extension that compacts your session by reading the prompt cache it already built, instead of paying full price to send it all again. It asks for the summary as the next turn of the same conversation, so about 99% of the request comes from the cache and the model writing the summary sees the full tool output. On a real 667k-token Opus session that came to $0.19 instead of about $1.40 at API prices. When you step away, it compacts just before the cache goes cold. Install it with pi install npm:pi-cached-compaction.

Highlights

  • About 99% from cache. Pi's own compaction rebuilds the request and pays full price; this one reuses what your session already cached.
  • Full tool output in the summary. The model sees every tool result in full, not the first 2,000 characters of each.
  • Compacts before the cache expires. A footer countdown shows the cache's remaining life, and an idle session compacts 20 seconds before it runs out.
  • Shows its cost next to Pi's. Every compaction gets a card comparing it with what Pi's compaction would have cost, and it falls back to Pi's whenever it can't prove a cache hit.

Changelog

First release. Needs Pi 0.87.0 or newer.

Highlights

  • Compaction reads the prompt cache your session already built. About 99% of the summary request comes from the cache instead of being billed at full price; on a 667k-token Opus session that was $0.19 instead of about $1.40.
  • The summary is written from the full tool output, not the first 2,000 characters of each result.
  • When you step away, it compacts just before the cache expires, so your next message doesn't pay to write the whole session again.
  • Every compaction shows a card comparing its cost with what Pi's own compaction would have cost.

Added

  • Cached compaction — The summary request repeats your conversation as it is (the same system prompt, tools and messages) and asks for the summary as the next turn. The result has Pi's format: older messages summarized, recent ones kept word for word, and the read and modified file lists carried forward. If the request can't be shown to match your last one byte for byte, or the model tries to call a tool, Pi's own compaction runs.
  • Compaction card — After each compaction, a card under the summary shows how much came from the cache, the cost and the time, next to Pi's estimated cost for the same messages. Expand it with ctrl+o to see what the decision rested on. Every decision is also logged to ~/.pi/agent/cached-compaction.jsonl.
  • Cache countdown and compacting before expiry — The footer counts down the cache's remaining life (⏱ 59m … ⏱ 0:25, then cache cold). When Pi is idle with at least 50k tokens of context, the extension compacts 20 seconds before the cache expires. Turn it off with compactBeforeExpiry: false, or raise minContextTokens, under cachedCompaction in ~/.pi/agent/settings.json.
  • Longer cache in interactive sessions — Asks for the 1-hour cache on Anthropic, and a 12-hour cache for the system prompt and tools on GPT-5.6 and later, so ordinary breaks don't expire it. Set cacheRetention: "short" to keep Pi's default.
  • /cached-compaction — Shows the cache right now, whether the next compaction would read it, and this session's compactions. /cached-compaction cache-flag turns on OpenAI's cache options for GPT models on opencode-go, which Pi doesn't send by default.
  • Providers — Works with Anthropic, Claude on opencode-go, Claude through pi-claude-bridge, GPT-5.6 and later on openai and opencode-go, other Responses and Chat Completions APIs, and openai-codex. Google and other providers keep Pi's own compaction.