OpenCode message transform plugin with The Token Company (TTC) API.
The Token Company (YC W26) builds models that process tokens based on context and semantic intent. With this plugin, you can remove context bloat from your prompts to Opencode before they hit the LLM provider.
Modern OpenCode builds also load a TTC sidebar widget. Compression still runs in the server plugin; the sidebar reads redacted per-session metrics from local state and never stores prompt text, compressed text, request bodies, or API keys.
Paste this into your coding agent:
Install @drfok/opencode-ttc-plugin by following: https://raw.githubusercontent.com/MrFok/opencode-ttc-plugin/main/README.md
- Install and register plugin:
npm install -g @drfok/opencode-ttc-plugin
opencode plugin @drfok/opencode-ttc-plugin --globalIf you are on an older OpenCode build without package plugin target support, use the legacy file installer:
opencode-ttc-plugin install- Configure auth in OpenCode:
opencode auth login- In the auth flow choose:
- provider:
the-token-company-plugin - method:
Set TTC API Key - paste key from
https://thetokencompany.com/
- Verify:
opencode-ttc-plugin doctor --verbose- Restart OpenCode. In a session, the sidebar should include
Token Compressionwith the latest message and session savings. Toasts remain as a fallback/configurable summary path.
For LLMs
-
Install @drfok/opencode-ttc-plugin with npm '''bash npm install -g @drfok/opencode-ttc-plugin '''
-
Run the installation command to place the js file into the /.config/opencode/plugins directory '''bash opencode-ttc-plugin install '''
Finally, tell the user to
-
Run
opencode auth login -
Search for
the-token-company-plugin -
Enter their TTC API key (obtain from https://thetokencompany.com/)
-
Verify by running
opencode-ttc-plugin doctor --verbose -
Tell them to restart OpenCode and watch the sidebar when they start a session
Primary control is aggressiveness. You can set it by named level (recommended) or exact numeric value.
Set by level:
opencode-ttc-plugin config set level balancedSet exact value:
opencode-ttc-plugin config set aggressiveness 0.25Inspect active config:
opencode-ttc-plugin config get
opencode-ttc-plugin doctor --verboseCompression levels:
| Level | Aggressiveness | Typical tradeoff |
|---|---|---|
low |
0.05 |
Minimal changes, conservative compression |
balanced |
0.10 |
Default; good savings with stable quality |
high |
0.20 |
Stronger compression, better token reduction |
max |
0.30 |
Most aggressive preset in this plugin |
Why these values exist:
- TTC API exposes aggressiveness on a
0.0-1.0range in their docs:https://thetokencompany.com/docs - TTC benchmark data shows quality/token tradeoffs vary by aggressiveness:
https://www.thetokencompany.com/benchmarks/accuracy
Runtime resolution order for aggressiveness:
TTC_AGGRESSIVENESSenv var (override)- plugin config file
~/.config/opencode/ttc-plugin.json - built-in default (
balanced=0.1)
| Command | What it does |
|---|---|
opencode-ttc-plugin install |
Installs plugin file into ~/.config/opencode/plugins |
opencode-ttc-plugin doctor |
Runs setup/auth checks |
opencode-ttc-plugin doctor --verbose |
Shows effective config sources, TUI entrypoint status, and sidebar state path |
opencode-ttc-plugin uninstall |
Removes installed plugin file |
opencode-ttc-plugin config get |
Prints plugin config and effective aggressiveness |
opencode-ttc-plugin config set level <low|balanced|high|max> |
Sets named aggressiveness level |
opencode-ttc-plugin config set aggressiveness <0..1> |
Sets numeric aggressiveness |
opencode-ttc-plugin config set <setting> <value> |
Sets behavior settings (see table below) |
opencode-ttc-plugin config reset |
Removes plugin config file |
Use CLI config for normal setup. Env vars are advanced overrides.
| Setting | Default | What it does | CLI command |
|---|---|---|---|
enabled |
true |
Master on/off switch for the transform hook | opencode-ttc-plugin config set enabled true |
model |
bear-1.2 |
TTC model sent to /v1/compress |
opencode-ttc-plugin config set model bear-1.2 |
minChars |
400 |
Skip compression for text shorter than this | opencode-ttc-plugin config set min-chars 400 |
timeoutMs |
2000 |
Request timeout per TTC call | opencode-ttc-plugin config set timeout-ms 2000 |
maxRetries |
1 |
Retry count for retryable TTC failures | opencode-ttc-plugin config set max-retries 1 |
retryBackoffMs |
100 |
Backoff base between retries | opencode-ttc-plugin config set retry-backoff-ms 100 |
useGzip |
true |
Sends compressed request body to TTC | opencode-ttc-plugin config set use-gzip true |
compressSystem |
false |
Also compresses eligible system messages in context |
opencode-ttc-plugin config set compress-system false |
compressHistory |
false |
Also compresses older eligible user history messages (not just latest user turn) |
opencode-ttc-plugin config set compress-history false |
debug |
false |
Emits extra plugin debug logs | opencode-ttc-plugin config set debug false |
cacheMaxEntries |
1000 |
Max in-memory dedupe cache entries | opencode-ttc-plugin config set cache-max-entries 1000 |
toastOnActive |
false |
Shows one activation toast per session when enabled; sidebar is the primary UI | opencode-ttc-plugin config set toast-on-active true |
toastOnIdleSummary |
false |
Shows idle summary toast with savings stats when enabled; sidebar is the primary UI | opencode-ttc-plugin config set toast-on-idle-summary true |
Notes on scope:
- TTC API parameters used directly by this plugin request are primarily
modelandcompression_settings.aggressiveness. - Most settings above are plugin-side controls (selection, retries, skipping, caching, and UX behavior).
- For TTC API details, see
https://thetokencompany.com/docs.
Advanced overrides (optional):
TTC_AGGRESSIVENESS,TTC_MIN_CHARS,TTC_TIMEOUT_MS,TTC_MAX_RETRIES,TTC_RETRY_BACKOFF_MSTTC_USE_GZIP,TTC_COMPRESS_SYSTEM,TTC_COMPRESS_HISTORY,TTC_DEBUGTTC_CACHE_MAX_ENTRIES,TTC_TOAST_ON_ACTIVE,TTC_TOAST_ON_IDLE_SUMMARY,TTC_MODEL,TTC_ENABLED
- Compression egress is pinned to
https://api.thetokencompany.com/v1/compress. - Custom/invalid
TTC_BASE_URLis ignored and safely falls back to pinned host. - Fetch redirects are rejected.
- Sidebar state is written under
${XDG_STATE_HOME:-~/.local/state}/opencode/ttc-pluginwith hashed session filenames. - Sidebar state contains aggregate counts and token/character savings only; it does not persist prompts, compressed output, request bodies, or API keys.
- If your firewall prompts about outbound socket traffic, that is expected on first compression request.