npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@touchtechclub/pi-oc-prompt-cache

v0.1.0

Published

Pi coding-agent extension: opencode-inspired prompt-cache optimizer (frozen context epoch, durable baseline, mid-conversation updates, payload tuning).

Readme

@touchtechclub/pi-oc-prompt-cache

Opencode-inspired prompt-cache optimizer for the Pi coding agent.

opencode v2 gets its famously high prompt-cache hit rate from one architectural idea: an immutable Context Epoch / Baseline System Context. The system prompt is rendered once per epoch and reused byte-for-byte on every turn — and across process restarts — so the provider's prompt-cache prefix never invalidates. When a context source actually changes, opencode appends a durable Mid-Conversation System Message instead of re-rendering the system prompt.

Pi already implements the wire-level half of prompt caching (cache_control breakpoints, prompt_cache_key, store: false, x-session-affinity). This extension adds the missing half.

What it does

  1. Frozen Context Epoch — freezes the system prompt into a stable per-session baseline and returns it unchanged on every turn, so the cache prefix stays valid.
  2. Durable baseline — persists the frozen baseline to the session, so it survives restarts and /reload instead of being re-derived.
  3. Mid-conversation updates — when the live system prompt drifts (AGENTS.md edited, tool set changed, skills changed, ...), it keeps the frozen baseline and appends a durable update message with a line diff of what changed.
  4. Deterministic tool ordering — sorts tool definitions by name in the provider payload (opencode sorts tools alphabetically; pi does not).
  5. Tighter cache breakpoints — when pi's built-in caching is active, extends Anthropic cache_control breakpoints to the last two messages (opencode's placement) rather than just the last one.

Install

pi extension add @touchtechclub/pi-oc-prompt-cache

Or add to settings.json:

{
  "extensions": ["@touchtechclub/pi-oc-prompt-cache"]
}

Behavior notes

  • Chain-safe. It mutates payloads in place per Pi's hook contract, only adds cache hints (never removes a user's PI_CACHE_RETENTION=none opt-out), and freezes rather than clobbers the chained system prompt.
  • Load it last if you also use extensions that append to the system prompt — its freeze then covers their mutations too, keeping the final prompt stable.
  • Compaction starts a new epoch. After /compact or auto-compaction, the next turn re-freezes the current prompt as the new baseline (matching opencode).
  • The injected update message uses customType pi-prompt-cache-update and is rendered in the transcript; the frozen baseline is stored as a hidden custom entry (pi-prompt-cache-epoch, not sent to the LLM).

Benchmark

bun bench drives pi's real request builders (@earendil-works/pi-ai) against the configured providers and measures prompt-cache hit rate on the second turn of three arms:

  • steady — no context change (pi's own ceiling).
  • drift — a context line changed and the system prompt rebuilt (pi without this extension).
  • frozen — the same change, but the baseline is frozen and the delta is appended as a mid-conversation message (this extension).

Measured on ClinePass (api.cline.bot, OpenAI-compatible):

| model | steady | drift (no ext) | frozen (ext) | improvement | |---|---|---:|---:|---:| | cline-pass/deepseek-v4-pro | 93.9% | 0.0% | 96.7% | +96.7pp | | cline-pass/deepseek-v4-flash | 81.5% | 0.0% | 89.6% | +89.6pp | | cline-pass/kimi-k3 | 90.7% | 0.0% | 88.3% | +88.3pp |

When the system context changes, rebuilding the prompt drops the cache hit rate to 0%; freezing the baseline keeps it at ~88–97%. The steady column shows pi already caches well (~82–94%) when nothing changes — the extension's job is to preserve that across context drift and restarts.

License

MIT