oc-plugin-caching
v0.1.0
Published
OpenCode plugin that applies prompt cache breakpoints and displays cache hit stats in the sidebar
Readme
oc-plugin-caching
OpenCode plugin that applies prompt cache breakpoints for supported providers and displays real-time cache hit statistics in the TUI sidebar.
What it does
Server — inserts cache control markers into tool definitions and messages so providers like Anthropic, Bedrock, and OpenRouter can cache prompt prefixes. Tools are sorted alphabetically for stable prefix matching.
TUI — adds a sidebar panel showing:
- Cache hit ratio (progress bar)
- Read / write token counts
- Estimated cost savings
Supported providers
| Provider | Strategy | | ------------------ | ------------------------------------ | | Anthropic (Claude) | Explicit breakpoints | | Amazon Bedrock | Explicit breakpoints | | OpenRouter | Passthrough | | OpenAI / Azure | Automatic prefix (no markers needed) | | DeepSeek | Automatic prefix | | Google Gemini | Automatic prefix |
Install
opencode plugin add oc-plugin-cachingOr manually add to both config files:
opencode.json (server hooks):
{
"plugin": ["oc-plugin-caching"]
}tui.json (sidebar component):
{
"plugin": ["oc-plugin-caching"]
}Configuration
The server export accepts an enabled option (default true):
{
"plugin": [["oc-plugin-caching", { "enabled": true }]]
}Requirements
- A fork of OpenCode with two additional plugin hooks: nazriel/opencode
This plugin relies on two experimental hooks that are not yet in upstream OpenCode:
experimental.chat.tools.transform— allows plugins to reorder tools and setproviderOptionsfor cache breakpointsexperimental.chat.model-messages.transform— allows plugins to setproviderOptionson messages inside the AI SDK middleware
Until these hooks are merged upstream, you need to build OpenCode from the fork above.
Background
This plugin is based on the work of:
- johnnymo87/opencode-cached — original caching patch for OpenCode
- anomalyco/opencode#5422 — PR proposing the caching logic as a core patch
The goal of this plugin is to provide the same caching functionality without maintaining a patch against the OpenCode core. Patches are cumbersome and fragile — they break on every upstream update and require constant rebasing. A plugin can evolve independently and stay compatible across versions through the stable hook API.
License
MIT
