OpenCode plugin that keeps long-running sessions usable with staged, pruning-first context management.
Better Compact preserves raw user intent, prunes old tool-heavy context first, writes transcript references for exact recall, and summarizes old assistant turns only when lighter pruning is not enough.
Requires OpenCode 1.17.13 or a newer 1.x release. Install globally with OpenCode's built-in plugin manager:
opencode plugin better-compact --globalInstall an explicit version:
opencode plugin better-compact@0.1.4 --globalOpenCode downloads the prebuilt package with its embedded package manager and updates both plugin configurations:
~/.config/opencode/opencode.json
~/.config/opencode/tui.json
OpenCode also preserves and updates existing opencode.jsonc and tui.jsonc files.
No separate Node.js, Bun, pnpm, npm, curl, or tar installation is required.
Restart OpenCode after installation.
/better-compactruns staged pruning immediately./better-compact-settingsopens global compaction and summary-effort settings.
Better Compact applies a virtual context plan to OpenCode's outgoing model request. It does not rewrite OpenCode's durable session history.
Default light mode:
- Prunes loaded skill context.
- Prunes old tool calls/results while preserving recent tool context.
- Prunes thinking/reasoning only if needed.
- Prunes remaining tool calls/results only if needed.
- Summarizes high-value old assistant turns only if needed.
- Writes raw transcripts under
.opencode/better-compact/sessions/...for exact recall.
The TUI shows live progress, context-window bars, stages completed, and final savings.
Better Compact searches config files in this order:
~/.config/opencode/better-compact.jsoncorbetter-compact.json$OPENCODE_CONFIG_DIR/better-compact.jsoncorbetter-compact.json.opencode/better-compact.jsoncorbetter-compact.json
Example:
Compaction strength:
- Gentle (
light): waits longer and preserves more recent tool output. - Balanced (
moderate): compacts earlier and keeps a moderate recent tool window. - Aggressive (
max): frees the most working room and keeps less old tool output verbatim. - Custom: choose the automatic trigger, deep-summary goal, and recent tool-output budget.
Summary effort is configured separately. inherit uses the model default. Low, medium, high, and max are applied only when the active model advertises a matching variant; unsupported levels safely fall back to the model default.
The settings panel saves global behavior to ~/.config/opencode/better-compact.jsonc, preserving comments and unrelated settings. Changes apply to subsequent manual and automatic runs without restarting OpenCode.
Remove better-compact from the plugin arrays in the JSON or JSONC equivalents of:
~/.config/opencode/opencode.json
~/.config/opencode/tui.json
Restart OpenCode.
pnpm install
pnpm run typecheck
pnpm test
pnpm run buildFor local development, point OpenCode at this checkout:
{
"plugin": ["file:///path/to/opencode-better-compact/index.ts"]
}For the TUI plugin, add this to ~/.config/opencode/tui.json:
{
"plugin": ["file:///path/to/opencode-better-compact/tui.tsx"]
}Restart OpenCode after changing plugin config.
CI uses pnpm and verifies every push/PR with:
- typecheck
- tests
- host-shaped OpenTUI visual/runtime tests under Bun
- production build
- package verification
Tag releases as v*:
git tag v0.1.4
git push origin v0.1.4The release workflow verifies that the tag matches package.json, builds and tests the compiled server and TUI artifacts, publishes the package to npm with provenance, and creates the GitHub Release.
Better Compact is forked from Opencode-DCP/opencode-dynamic-context-pruning, originally published as @tarquinen/opencode-dcp by tarquinen and contributors.
This fork keeps the upstream AGPL-3.0-or-later license and builds on the original plugin architecture while changing the product direction to boundary-time context pruning and Better Compact branding.
AGPL-3.0-or-later
{ "$schema": "https://raw.githubusercontent.com/AshishKumar4/opencode-better-compact/master/better-compact.schema.json", "enabled": true, "autoUpdate": false, "debug": false, "compaction": { "automatic": true, "preset": "light", "summaryEffort": "inherit", }, }