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

pi-kiro-cache-key

v1.0.1

Published

pi extension: inject metadata.user_id so Anthropic-compatible proxies honor prompt caching

Downloads

367

Readme

pi-kiro-cache-key

给 pi 的扩展:为 Anthropic 兼容反代补上 metadata.user_id,让 prompt caching 生效。

为什么需要

部分 Anthropic 兼容反代(如 kiro 系)拿 metadata.user_id 当 prompt cache 的 key。缺这个字段,反代就无视 cache_control,每轮对话全量重算整个 prompt。pi 只在 options.metadata.user_id 有值时才发这个字段,而它默认没有赋值来源,所以缓存一直不命中。

实测(93k token 上下文):

修复前   input=93,207  cacheWrite=0       cacheRead=0
修复后   input=0       cacheWrite=37,411  cacheRead=0       ← 第 1 轮建缓存
        input=0       cacheWrite=14      cacheRead=37,413  ← 第 2 轮命中

安装

pi install npm:pi-kiro-cache-key

或直接从 git 装(不经 npm):

pi install git:github.com/zhengziyi0117/pi-kiro-cache-key

想先试不装:

pi -e git:github.com/zhengziyi0117/pi-kiro-cache-key

装完在 pi 里 /reload,或重启 pi。

配置

默认只对 provider 名为 kiro 的请求生效。改 extensions/kiro-cache-key.ts 里这一行,可填多个:

const PROVIDERS = new Set(["kiro"]);

provider 名就是 ~/.pi/agent/models.json 里 providers 下的键名。

生效确认

footer 会多出 R(cacheRead)、W(cacheWrite)、CH(命中率)三项:

↑876k ↓2.1k R37.4k W14 CH99.9% 9.3%/1.0M

说明

  • user_id 格式照抄 Claude Code 实际发出的内容:{"device_id":"...","account_uuid":"","session_id":"..."}。
  • session_id 用 pi 自己的 session id,所以缓存是会话级的 —— 会话内多轮命中,换会话重建。Claude Code 行为一致。
  • device_id 是 hostname 的 sha256,不含任何凭证。
  • payload 里已有 metadata.user_id 时不覆盖。

License

MIT