Skip to content

Commit 6dc6bea

Browse files
committed
docs: require explicit plugin config and highlight gateway gains
1 parent 90cf78c commit 6dc6bea

1 file changed

Lines changed: 29 additions & 36 deletions

File tree

README.md

Lines changed: 29 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -16,27 +16,20 @@ Observed result from a real run: input cache hit rate improved from a near-zero
1616

1717
## Installation
1818

19-
### Recommended: directory-based auto-loading
19+
### Required: explicit config loading
2020

21-
OpenCode automatically loads local plugins from:
21+
In this repository's verified setup, the plugin only takes effect when it is listed in the
22+
`plugin` field of `opencode.jsonc`. Copying the file into a plugins directory alone is not
23+
enough in this environment.
2224

23-
- Project-level: `.opencode/plugins/`
24-
- Global: `~/.config/opencode/plugins/`
25-
26-
Copy or symlink `plugins/opencode-context-cache.mjs` into one of those directories.
27-
28-
Example (project-level):
25+
1. Put plugin file in a stable local path (example: global plugin dir):
2926

3027
```bash
31-
mkdir -p .opencode/plugins
32-
cp plugins/opencode-context-cache.mjs .opencode/plugins/opencode-context-cache.mjs
28+
mkdir -p ~/.config/opencode/plugins
29+
cp plugins/opencode-context-cache.mjs ~/.config/opencode/plugins/opencode-context-cache.mjs
3330
```
3431

35-
Restart OpenCode after adding the plugin.
36-
37-
### Optional: explicit config loading
38-
39-
If you prefer explicit loading via config:
32+
2. Add plugin entry in `opencode.jsonc`:
4033

4134
```jsonc
4235
{
@@ -47,18 +40,18 @@ If you prefer explicit loading via config:
4740
}
4841
```
4942

50-
For global config, `./plugins/...` is resolved relative to `~/.config/opencode/`.
43+
For global config (`~/.config/opencode/opencode.jsonc`), `./plugins/...` is resolved
44+
relative to `~/.config/opencode/`.
5145

52-
If the file is already inside an auto-loaded plugin directory, this explicit entry is usually unnecessary.
46+
3. Restart OpenCode after editing config.
5347

5448
### Activation prerequisites (important)
5549

5650
This plugin only takes effect after OpenCode actually loads the plugin file.
5751

58-
Use one of the two methods below:
52+
Required method:
5953

60-
1. Put `opencode-context-cache.mjs` into an auto-loaded plugin directory.
61-
2. Add it explicitly in `opencode.jsonc` with the `plugin` field.
54+
1. Add it explicitly in `opencode.jsonc` with the `plugin` field.
6255

6356
`setCacheKey` / model cache flags only control cache behavior. They do not load the plugin by themselves.
6457

@@ -92,6 +85,7 @@ Interpretation:
9285

9386
- Most prompt input was served from cache after key stabilization.
9487
- Compared with a near-zero-hit baseline, this indicates a major cache reuse improvement.
88+
- The effect is often stronger behind AI API relay/gateway services, where unstable upstream session identifiers can otherwise reduce cache reuse.
9589
- Actual latency/cost gains depend on model/provider pricing and cache policy.
9690

9791
## Compatibility
@@ -115,18 +109,14 @@ OpenCode sessions can lose cache efficiency when session identifiers vary betwee
115109
- Stable cache key precedence with environment overrides
116110
- SHA256 hashing for privacy (raw key is not sent to server)
117111
- Digest detection to avoid double-hashing existing SHA256 values
112+
- Especially effective with AI API relay/gateway setups that benefit from stable cache/session identity
118113
- Optional debug logging to a local log file
119114

120115
## OpenCode loading behavior
121116

122-
OpenCode can load this plugin in two ways:
123-
124-
1. **Automatic local plugin loading** (recommended)
125-
- Global: `~/.config/opencode/plugins/`
126-
- Project: `.opencode/plugins/`
127-
2. **Explicit `plugin` entry** in `opencode.json` / `opencode.jsonc`
128-
129-
To avoid confusion and accidental duplicate execution, use one loading method per plugin.
117+
For this project, use explicit `plugin` entry in `opencode.json` / `opencode.jsonc` as the
118+
source of truth. Directory auto-loading behavior may vary by runtime/version, so do not rely
119+
on file placement alone for activation.
130120

131121
## Repository layout
132122

@@ -174,7 +164,7 @@ OpenCode config flags (often required for expected cache behavior):
174164
- `provider.<id>.models.<id>.options.cache`: if your provider/model exposes this flag and it is set to `false`, upstream prompt caching is effectively disabled.
175165
- `provider.<id>.models.<id>.options.store`: this is separate from prompt caching; for example, `store: false` controls response storage and does not replace `setCacheKey`.
176166

177-
Minimal working `opencode.jsonc` example (explicit plugin loading + cache flags):
167+
Minimal working `opencode.jsonc` example (required explicit plugin loading + cache flags):
178168

179169
```jsonc
180170
{
@@ -202,7 +192,7 @@ Minimal working `opencode.jsonc` example (explicit plugin loading + cache flags)
202192
}
203193
```
204194

205-
If the plugin file is already in `.opencode/plugins/` or `~/.config/opencode/plugins/`, the `plugin` field above can be omitted.
195+
Do not omit the `plugin` field above in this setup.
206196

207197
Environment variables:
208198

@@ -231,10 +221,12 @@ The log prefix is `[context-cache]`.
231221

232222
Use this checklist:
233223

234-
1. Start or restart OpenCode.
235-
2. Ensure `OPENCODE_CONTEXT_CACHE_DEBUG=1` is set.
236-
3. Open the log file in your plugin directory.
237-
4. Confirm entries like:
224+
1. Confirm `opencode.jsonc` contains `"plugin": ["./plugins/opencode-context-cache.mjs"]`
225+
(or the equivalent valid path in your setup).
226+
2. Start or restart OpenCode.
227+
3. Ensure `OPENCODE_CONTEXT_CACHE_DEBUG=1` is set.
228+
4. Open the log file in your plugin directory.
229+
5. Confirm entries like:
238230
- `Plugin initialized`
239231
- `Using cache key from ...`
240232
- `Set final cache key (hashed): ...`
@@ -248,14 +240,15 @@ If these lines appear, the plugin is loaded and processing requests.
248240
- Confirm `OPENCODE_CONTEXT_CACHE_DEBUG` is `1` or `true`.
249241
- Plugin not loading:
250242
- Verify filename and extension (`opencode-context-cache.mjs`).
251-
- Verify plugin location (`~/.config/opencode/plugins/` or `.opencode/plugins/`).
243+
- Verify `opencode.jsonc` includes a valid `plugin` entry for this file.
244+
- Verify the `plugin` path is resolved relative to the config file location.
252245
- Restart OpenCode after changes.
253246
- Unexpected cache key changes:
254247
- The default key includes absolute working directory.
255248
- Moving or renaming the project path changes the key.
256249
- Use `OPENCODE_PROMPT_CACHE_KEY` for a fixed identity.
257250
- Potential duplicate execution:
258-
- Avoid enabling both auto-loading and explicit `plugin` entry for the same file.
251+
- If your runtime also auto-loads plugin directories, avoid loading the same file twice.
259252

260253
## Security recommendations
261254

0 commit comments

Comments
 (0)