Skip to main content

Documentation Index

Fetch the complete documentation index at: https://developer.upsun.com/llms.txt

Use this file to discover all available pages before exploring further.

This is Part 2 of the OpenCode on Upsun series. If you haven’t deployed your OpenCode server yet, start with How to Host OpenCode on Upsun.
Running an AI coding agent in server mode is powerful — but token costs add up quickly. Every API call sends tool schemas, conversation history, and file contents to the model. On a busy session with multiple file reads and command outputs, you can easily burn 3x the tokens you actually need. This guide walks you through installing three community plugins that significantly reduce token usage on your existing OpenCode deployment on Upsun, with minimal changes to your configuration.

Why tokens accumulate

Before diving into the fixes, it helps to understand where the waste comes from:
  • Tool descriptions — OpenCode ships with many built-in tools. Their full descriptions are sent with every API call, even when most tools are unused in a given step. This compounds across multi-step tasks.
  • Bash output floods — Commands like pytest, npm install, or docker build dump hundreds of lines into the context. The model processes all of it, including passing test names, deprecation warnings, and progress bars.
  • Stale context — In long sessions, the model replays conversation history and re-reads files that are no longer relevant, inflating context size over time.
Three plugins address each of these root causes independently.
These plugins are community-maintained and not officially endorsed by OpenCode.Always: Check their GitHub repositories for the latest updates and compatibility with your OpenCode version. Test in a staging environment before deploying to production.

The plugins

Token reduction percentages are sourced from each plugin’s official documentation and may vary based on session length, model, and usage patterns.

OpenSlimedit — tool description compression

OpenSlimedit aggressively shortens all built-in tool descriptions, compacts file read output, and adds line-range editing support. Because tool schemas are sent with every API call, compressing them saves thousands of input tokens per step — and this compounds across multi-step tasks. Benchmarks show 11-45% token reduction across tested models, with zero regressions on Claude Opus 4.6. It works by modifying descriptions of existing tools only, which avoids the model confusion that affects approaches using custom tool schemas.

opencode-dcp — dynamic context pruning

opencode-dcp manages the conversation context between turns. It exposes a compress tool to the model that replaces stale, closed content with high-fidelity technical summaries before sending requests to the LLM — without modifying your actual session history. Unlike OpenCode’s built-in compaction (which triggers statically when the context hits its limit), DCP lets the model decide when to compress and which specific messages to target. This results in 50-70% token reduction on long sessions.

opencode-snip — bash output filtering

opencode-snip automatically prefixes shell commands with snip, a CLI proxy that filters command output before it reaches the LLM context window. It handles git, go, cargo, npm, docker, and more — keeping errors and summaries while dropping noise. This delivers 60-90% reduction on bash-heavy sessions.

Important considerations

While these plugins are widely used and tested, they may:
  • Modify tool behavior: OpenSlimedit alters tool descriptions.
  • Affect session history: opencode-dcp compresses context, which may remove details the model needs.
  • Introduce latency: snip adds a small overhead to shell commands.
Recommendation: Start with one plugin at a time, monitor token usage and model behavior, and gradually add others. Pin plugin versions in opencode.json to avoid breaking changes.

Installation

OpenCode loads npm plugins automatically via Bun at startup — no manual npm install needed for the plugins themselves. The only exception is snip, a standalone Go binary that must be installed separately during the build.

Step 1 — Declare the plugins in opencode.json

Add the three plugins to the plugin array in your opencode.json:
opencode.json
{
  "plugin": [
    "openslimedit@latest",
    "@tarquinen/opencode-dcp@latest",
    "opencode-snip@latest"
  ],
  "mcp": {
    "upsun": {
      "type": "remote",
      "url": "https://mcp.upsun.com/mcp",
      "headers": {
        "upsun-api-token": "${UPSUN_CLI_TOKEN}",
        "enable-write": "true"
      },
      "enabled": true
    }
  }
}
OpenCode will install and cache these packages automatically via Bun on the next startup.

Step 2 — Deploy

Commit and push:
Terminal
git add .upsun/config.yaml opencode.json
git commit -m "Add token optimization plugins"
upsun push
Upsun will rebuild the container, install the snip binary during the build hook, and restart OpenCode. The three npm plugins are fetched and cached by OpenCode on first startup.

Which plugin for which problem?

ProblemPluginReduction
High token cost per step (all sessions)OpenSlimedit11-45%
Long sessions with growing contextopencode-dcp50-70%
Bash-heavy sessions (npm, pytest, docker)opencode-snip60-90%
All three can run together — they address different layers of token waste and do not conflict with each other.

Verify the plugins are loaded

Once deployed, connect to your OpenCode instance and press Ctrl+PView Status (System category). You should see all three plugins listed as active. For opencode-dcp specifically, you can check savings at any point during a session by running:
OpenCode prompt
/dcp stats

Troubleshooting

snip binary not found at runtime

If OpenCode logs show snip: command not found, the binary was not installed correctly during the build. Check the build output with:
Terminal
upsun activity:log
Look for the install-github-asset.sh step. The asset name pattern is snip_VERSION_linux_amd64.tar.gz — if a new release changes the naming convention, update the pattern accordingly in your build hook.

Check installed plugin

To check installed plugins, connect to your opencode container and run the following command:
Terminal
upsun ssh -- cat .local/share/opencode/log/2026-05-26T132215.log | grep "loading plugin"

  INFO  2026-05-26T13:25:04 +20ms service=plugin path=openslimedit@latest loading plugin
  INFO  2026-05-26T13:25:04 +19ms service=plugin path=@tarquinen/opencode-dcp@latest loading plugin
  INFO  2026-05-26T13:25:04 +0ms service=plugin path=opencode-snip@latest loading plugin 

opencode-dcp increases token usage on short sessions

DCP is most effective on sessions longer than 15-20 turns. On short sessions, the overhead of the compress tool itself can outweigh the savings. Remove it from the plugin array if your typical sessions are short:
opencode.json
{
  "plugin": [
    "openslimedit@latest",
    "opencode-snip@latest"
  ]
}

A plugin causes unexpected tool behavior

Pin to a specific version instead of @latest to stabilize your deployment:
opencode.json
{
  "plugin": [
    "openslimedit@1.2.0",
    "@tarquinen/opencode-dcp@1.2.3",
    "opencode-snip@1.6.1"
  ]
}

What’s next?

With token costs under control, you can monitor per-session usage with opencode-tokenscope, which provides a breakdown of which tools and skills consume the most tokens — useful for identifying further optimization opportunities.

Resources

Last modified on June 2, 2026