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

opencode-cache-injector

v1.0.0

Published

OpenCode plugin that enables prompt caching for multiple API providers by injecting metadata.user_id

Downloads

24

Readme

opencode-cache-injector

OpenCode 插件,为 Claude API 中转站启用 Prompt 缓存功能。

为什么需要

许多 Claude API 中转站要求请求中必须包含 metadata.user_id 字段才能启用 Prompt 缓存。

没有此插件:每次请求都按全价计费 💸

使用此插件:自动注入 user_id,启用缓存,节省费用 ✨

特点

  • 自动生成唯一 user_id - 基于项目和会话自动生成
  • 支持调试日志 - 方便排查问题
  • CLI 切换工具 - 快速切换 provider

安装

pnpm install opencode-cache-injector
# 或
npm install opencode-cache-injector

配置

1. 在 opencode.json 中添加插件

{
  "plugin": ["opencode-cache-injector"]
}

2. 设置环境变量

export OPENCODE_CACHE_PRIMARY_PROVIDER="your-provider-id"

your-provider-id 是你在 opencode.json 中配置的 provider 名称。

CLI 切换工具

全局安装 CLI 工具,快速切换 provider:

npm install -g opencode-cache-switch

使用:

cache-switch

效果:

🔄 OpenCode Cache Injector - Provider Switch

📍 Current provider: foxcode-aws

? Select provider for cache injection:
❯ foxcode-ultra
  foxcode-aws
  foxcode-droid
  ...

选择后会询问是否写入 shell 配置文件。

环境变量

| 变量名 | 说明 | 默认值 | |--------|------|--------| | OPENCODE_CACHE_PRIMARY_PROVIDER | Provider ID,必须设置 | 无 | | OPENCODE_CACHE_INJECTOR_DEBUG | 启用调试日志 | false |

工作原理

插件使用 OpenCode 的 auth.loader hook,拦截指定 provider 的 API 请求,自动注入 metadata.user_id

{
  "model": "claude-...",
  "messages": [...],
  "metadata": {
    "user_id": "user_{projectId}_account__session_{sessionId}"
  }
}

user_id 格式user_{projectId}_account__session_{sessionId}

  • projectId:当前项目的唯一标识
  • sessionId:当前会话的唯一标识

这样可以确保同一项目、同一会话的请求使用相同的 user_id,从而命中缓存。

注意事项

💡 关于 litellmProxy:当使用 LiteLLM 代理时,建议在 provider 配置中设置 litellmProxy: true

致谢

本插件的实现思路参考了 @x7yueopencode-foxcode-aws-cache 项目。

许可证

MIT