Edited and maintained by Claude. Provided as-is.
Staged context pruning for OpenCode 1.17.13 and newer.
opencode plugin better-compact --globalRestart OpenCode after installation.
The installer updates:
~/.config/opencode/opencode.json
~/.config/opencode/tui.json
JSONC files are preserved when present.
| Command | Action |
|---|---|
/better-compact |
Run Better Compact now |
/better-compact context |
Show context usage |
/better-compact stats |
Show the active plan |
/better-compact help |
List commands |
/better-compact-settings |
Open settings |
Better Compact reads these files in order:
~/.config/opencode/better-compact.jsoncor.json$OPENCODE_CONFIG_DIR/better-compact.jsoncor.json.opencode/better-compact.jsoncor.json
Project settings override global settings.
| Preset | Trigger | Target | Recent tool budget |
|---|---|---|---|
light |
85% | 35% | 40k tokens |
moderate |
75% | 25% | 30k tokens |
max |
60% | 15% | 12k tokens |
Changes made in /better-compact-settings apply to later runs without restarting OpenCode.
Use an explicit version to force a fresh OpenCode package cache entry:
opencode plugin better-compact@0.2.6 --globalIf the plugin is missing after a failed or stale install, clear its cache and restart OpenCode:
rm -rf ~/.cache/opencode/packages/better-compact*Remove better-compact from the plugin arrays in:
~/.config/opencode/opencode.json
~/.config/opencode/tui.json
Restart OpenCode.
From the repository root:
pnpm install
pnpm --filter better-compact typecheck
pnpm --filter better-compact test
pnpm --filter better-compact build
pnpm --filter better-compact check:packageUse the checkout directly:
{
"plugin": ["file:///path/to/better-compact/packages/opencode/index.ts"]
}Add the TUI entry to ~/.config/opencode/tui.json:
{
"plugin": ["file:///path/to/better-compact/packages/opencode/tui.tsx"]
}OpenCode runs Better Compact through two bundled entrypoints:
dist/index.js server hooks and pruning runtime
dist/tui.js commands, settings, reports, progress UI
The server applies a virtual plan to each outgoing request. OpenCode session history remains unchanged.
The pruning order is:
- Remove loaded skill text.
- Supersede repeated reads and remove stale failed-tool inputs.
- Replace old tool calls and results with action stubs.
- Remove old reasoning if more space is needed.
- Remove remaining old tool traffic if more space is needed.
- Collapse selected assistant runs and summarize them.
- Use a rolling prefix summary as a last resort.
Raw history for each planned range is stored under:
.opencode/better-compact/sessions/<session-id>/<range-hash>.md
The model receives a reference to that file. Plans are range-hashed and replayed until prefix edits or context regrowth require a new plan.
AGPL-3.0-or-later
{ "$schema": "https://raw.githubusercontent.com/AshishKumar4/better-compact/main/packages/opencode/better-compact.schema.json", "enabled": true, "compaction": { "automatic": true, "preset": "light", "summaryEffort": "inherit", }, }