opencode-cashback is an OpenCode plugin that reduces prompt size before messages are sent to the LLM, then shows the saved-character total live in the TUI.
It is built around one constraint: compression must be deterministic. The same input history should compress the same way every time, so you get smaller prompts without introducing cache-hostile randomness or paying for an extra model pass.
Install:
opencode plugin opencode-plugin-snip --global --forcePublic package and source:
- npm:
opencode-plugin-snip - GitHub:
https://github.com/disrei/opencode-cashback - Release:
https://github.com/disrei/opencode-cashback/releases/tag/v0.1.0
What you get immediately:
- Deterministic prompt compression before LLM submission.
- A live
snipindicator in the OpenCode TUI. - Per-session saved-character tracking that starts from
0.0kin every new session.
- Deterministic compression. No LLM rewriting step, no probabilistic summarization, no drifting history.
- Zero extra model cost. Compression is done with fixed rules over message parts and text.
- Session-scoped savings. Every session tracks its own saved-character total and starts from
0.0k. - Live TUI feedback. The current mode and cumulative savings are visible in the prompt row.
- Tool-aware cleanup. Tool payloads are normalized instead of blindly dumped back into history.
- Protected-block safe.
<system-reminder>...</system-reminder>blocks are preserved. - Three compression levels. Choose
pro,max, ormax++depending on how aggressive you want to be.
- Removes framework control events such as
[step-start]and[step-finish]when they appear in framework-event form. - Removes historical reasoning content in
max++mode while keeping the current turn's reasoning intact. - Preserves non-framework user text that merely contains similar markers.
- Preserves
<system-reminder>...</system-reminder>blocks. - Normalizes tool output in
maxandmax++modes. - Replaces historical tool output bodies with a compact placeholder in
max++mode while keeping the current turn's tool output intact. - Tracks saved characters per session, not globally.
- Adds a bright yellow
sniplabel tohome_prompt_rightandsession_prompt_right. - Keeps optional request logging off by default.
In the TUI, the plugin shows a label like this:
snip max 107.3k
Meaning:
snipis the plugin label.maxis the active compression mode.107.3kis the cumulative characters saved for the current session only.
Install or upgrade from npm through OpenCode:
opencode plugin opencode-plugin-snip --global --forceOpenCode detects the plugin package from these exports:
exports["./server"]exports["./tui"]
After install, OpenCode patches the relevant config files for you.
Use --force even on first install so the same command also works for upgrades. This avoids keeping an older configured plugin version when OpenCode reports the plugin as already configured.
- The plugin checks npm for newer stable releases in the background.
- When a newer version is available, it pins your config to that exact version and invalidates the currently loaded package instance.
- Restart OpenCode to let it load the new version.
Recommended upgrade flow:
opencode plugin opencode-plugin-snip --global --forceIf OpenCode has already loaded the old version in the current process, restart after the install command so the pinned version is picked up on the next launch.
If you previously used a local prototype plugin under ~/.config/opencode/plugins/, remove old files there before testing the npm package. OpenCode can auto-discover plugins from that directory, and stale files like log-llm.js can end up running alongside the npm-installed plugin and overwrite the same stats file.
Default behavior:
- Global install writes to
~/.config/opencode/opencode.json - Global install writes to
~/.config/opencode/tui.json
Using plain npm install opencode-plugin-snip is not enough. The package must be installed through opencode plugin ... so OpenCode can patch the config files.
After install, OpenCode writes plugin entries into opencode.json and tui.json.
The server plugin supports these options:
{
"mode": "max",
"logEnabled": false,
"logPath": "C:/path/to/opencode-llm.log",
"omitThreshold": 1500
}logEnabled defaults to false. When enabled, the log also includes hashes for the system prompt, original messages, compressed messages, plus which historical rounds were compacted, which is useful for diagnosing prompt-cache misses. System prompt logging is paired to the same session/request flow used by the message transform; when that pairing is unavailable, the log prints SYSTEM PROMPT unavailable for this request instead of reusing stale data. omitThreshold controls the cumulative character budget for compressible historical tool output within each completed historical round. Once a round's eligible historical tool output exceeds this value, that round's eligible tool output is replaced with placeholders. Defaults to 1500. Set to 0 to always compact eligible historical tool output.
Smallest behavior change. Best when you want minimal compression.
| Operation | Scope | Effect |
|---|---|---|
| Remove framework events | All rounds | Removes step-start and step-finish control events |
| Tool output | All rounds | Preserved as-is (only trailing whitespace trimmed) |
| Reasoning | All rounds | Preserved intact |
<system-reminder> |
All rounds | Protected from removal |
Balanced compression for everyday use. Normalizes tools, keeps reasoning.
| Operation | Scope | Effect |
|---|---|---|
| Remove framework events | All rounds | Removes step-start and step-finish control events |
| Tool output | All rounds | Normalized to compact [tool:name][status] format |
| Reasoning | All rounds | Preserved intact |
<system-reminder> |
All rounds | Protected from removal |
Same as max, but also compresses historical tool output and reasoning. Only the current turn (after the most recent user message) keeps full detail.
| Operation | Scope | Effect |
|---|---|---|
| Remove framework events | All rounds | Removes step-start and step-finish control events |
| Tool output | Current turn | Normalized to compact [tool:name][status] format (same as max) |
| Tool output | Historical rounds | Replaced with [historical-tool-output-omitted] (N lines, N chars, hint) placeholder, when the round's cumulative tool output exceeds omitThreshold (default 1500 chars) |
| Reasoning | Current turn | Preserved intact |
| Reasoning | Historical rounds | Removed entirely |
<system-reminder> |
All rounds | Protected from removal |
Notes:
- Each completed historical round is evaluated independently for tool output compression, so old rounds stay stable instead of being re-expanded by later turns.
- Historical tool output that contains
<system-reminder>is always kept intact, regardless of threshold. - Set
omitThresholdto0to always compact eligible historical tool output. - Risk: if the model still needs exact details from an older tool result or previous reasoning chain,
max++can remove information that would otherwise still be available in history.
- The mode label comes from the server plugin config.
- The number is the cumulative saved characters for the current session only.
- A brand-new session starts at
0.0k. - The home screen shows
0.0kbecause savings are session-based.
The plugin writes per-user runtime data under the OpenCode config directory:
~/.config/opencode/snip-stats.json~/.local/state/opencode/snip-version-check.json
Optional log output defaults to:
~/opencode-llm.log
Server side:
- Hooks
experimental.chat.system.transform - Hooks
experimental.chat.messages.transform - Compresses message parts deterministically.
- Removes control-event parts and matching framework-event text lines.
- Rewrites tool payloads into a smaller, stable format.
- Updates per-session saved-character stats.
TUI side:
- Registers
home_prompt_right. - Registers
session_prompt_right. - Polls the stats file and renders live saved-character counts.
You can also use this package source directly as a local plugin during development.
Do not keep local-source mode and npm-installed mode active at the same time. Pick one path per test run.
Replace /absolute/path/to/opencode-cashback with your own local checkout path.
Example opencode.json:
{
"plugin": [
[
"/absolute/path/to/opencode-cashback/src/server.js",
{
"mode": "max",
"logEnabled": false
}
]
]
}Example tui.json:
{
"$schema": "https://opencode.ai/tui.json",
"plugin": [
"/absolute/path/to/opencode-cashback/src/tui.tsx"
]
}This directory is ready to become a GitHub repository.
Typical steps:
git init
git add .
git commit -m "Initial plugin package"
gh repo create opencode-cashback --public --source . --remote origin --pushAfter the GitHub repo is ready and the package name is available:
npm publish --access publicIf the package name is already taken, rename the name field in package.json first.
- Do not publish your personal
opencode.jsonwith provider credentials. - This package only contains the plugin code and documentation.
- The stats file is intentionally session-scoped so session totals do not bleed into each other.