Compaction Model
OpenCode V2 plugin that summarizes checkpoints with a dedicated compaction model and variant.
5
近 30 天 +2
866
近 7 天 131
47.6
生态多维模型
2 小时前
2026-10-21
快速安装与配置
opencode.json写入当前项目的 opencode.json,只对这个仓库生效。
opencode.json
{
"$schema": "https://opencode.ai/config.json",
"plugin": ["@madsoftwaredev/opencode-compaction-model@0.1.3"]
}写入 ~/.config/opencode/opencode.json,对所有项目生效。
~/.config/opencode/opencode.json
{
"$schema": "https://opencode.ai/config.json",
"plugin": ["@madsoftwaredev/opencode-compaction-model@0.1.3"]
}若你要在本地改造这个插件,先装到项目里再从本地路径引用。
shell
pnpm add -D @madsoftwaredev/opencode-compaction-modelOpenCode 启动时会通过内嵌运行时自动加载 npm 依赖并缓存至本地目录,无需手动在全局环境执行安装。
OpenCode Plugins
Ten maintained plugins for OpenCode V2.
Persistent goals, chat usage, terminal customization, background subagents, lint feedback, direnv, and compaction, each in its own package.
[!NOTE] Built and maintained by MAD Software.
How It Works
OpenCode V2 loads plugins from two places. Server plugins extend sessions, tools, and shell behavior through opencode.json. TUI plugins extend the terminal interface through cli.json. Each package is independent, so install only what you want.
%%{init: {'theme': 'base', 'themeVariables': {'primaryColor': '#f6f8fa', 'primaryBorderColor': '#57606a', 'primaryTextColor': '#24292f', 'lineColor': '#57606a'}}}%%
flowchart LR
S["Server plugins (opencode.json)"] --> A["goal · background-subagent · lint-feedback · direnv · compaction-model"]
T["TUI plugins (cli.json)"] --> B["goal · chat-title · sidebar-resize · usage · subagent-sidebar · stats"]
Plugins
| Plugin | Surface | What It Does |
|---|---|---|
| Background subagent · npm | Server | Runs subagents in the background by default; explicit foreground calls still wait. |
| Subagent sidebar · npm | TUI | Shows live child and nested subagent sessions; click a row to open it. |
| Stats · npm | TUI | Shows token speed and session-wide turn and step counts in the prompt footer; toggle each in the TUI. |
| Lint feedback · npm | Server | Appends project-local ESLint diagnostics after successful edits. Checks only, never fixes. |
| direnv · npm | Server | Applies the approved direnv environment to each shell command's working directory. |
| Compaction model · npm | Server | Summarizes checkpoints with a selectable model and reasoning variant. |
| Goal · npm | Server + TUI | Keeps a persistent goal across compaction, resumes work within a nudge budget, and shows goal state above the composer. |
| Chat title · npm | TUI | Keeps the current chat title visible above the transcript while the sidebar is hidden. |
| Sidebar resize · npm | TUI | Adds a draggable sidebar edge and saves the chosen width. |
| Usage · npm | TUI | Shows chat and subagent tokens, cache efficiency, recorded cost, and API-equivalent cost in the sidebar and /usage popup. |
Each plugin README documents its behavior, setup, and limitations.
Deprecated
@madsoftwaredev/opencode-btw (/btw) is deprecated
and no longer maintained. Remove it from your OpenCode plugins configuration.
Its source remains available for reference.
[!WARNING] Upgrading from
0.1.0? Background subagent, subagent sidebar, lint feedback, and direnv dropped thelocal.prefix from their plugin IDs in0.1.1. npm package names are unchanged, but update any config rules that reference the old IDs (local.direnvis nowdirenv, and so on).
What This Looks Like
Session Stats in the Footer
44.4 tok/s · 3 turns · 8 steps
The stats plugin appends live token speed and session-wide turn and step counts to the prompt footer. Enable or disable each stat in cli.json, or save overrides with /stats.
Background Subagents by Default
| Without the plugin | With the plugin |
|---|---|
Every delegated task pauses the parent turn. |
Explicit |
Install
Requires OpenCode V2. Install each package you want with opencode plugin add:
# Server plugins (opencode.json)
opencode plugin add @madsoftwaredev/opencode-background-subagent
opencode plugin add @madsoftwaredev/opencode-lint-feedback
opencode plugin add @madsoftwaredev/opencode-direnv
opencode plugin add @madsoftwaredev/opencode-compaction-model
# TUI plugins (cli.json)
opencode plugin add @madsoftwaredev/opencode-subagent-sidebar
opencode plugin add @madsoftwaredev/opencode-stats
opencode plugin add @madsoftwaredev/opencode-chat-title
opencode plugin add @madsoftwaredev/opencode-sidebar-resize
opencode plugin add @madsoftwaredev/opencode-usage
# Server + TUI
opencode plugin add @madsoftwaredev/opencode-goal
Restart the OpenCode TUI after installing a TUI plugin.
Stats and usage are separate: stats adds speed, turns, and steps to the footer;
usage adds token and cost accounting to the sidebar and /usage popup. Install
either or both. Goal needs its server plugin running for its TUI to show state.
Each package has its own version line, so opencode plugin update moves only the
packages that changed.
Managing installed packages
opencode plugin list
opencode plugin check
opencode plugin update
The CLI checks and updates installed packages; exact version pins remain pinned.
Configure Compaction
The compaction plugin defaults to
opencode-go/deepseek-v4.1-flash#max. To use a different connected model, set
options.model in its entry in opencode.json. Replace the package's string
entry with the object form below, preserving your other plugins:
{
"$schema": "https://opencode.ai/config.json",
"plugins": [
{
"package": "@madsoftwaredev/opencode-compaction-model",
"options": {
"model": "provider/model#variant"
}
}
]
}
Use provider/model from a connected provider; #variant is optional. On
failure, the plugin logs a diagnostic and lets OpenCode use its normal session
model for compaction. See the full compaction guide
for details and a working configuration example.
Requirements
| Plugin | Requires |
|---|---|
| direnv | direnv installed where the OpenCode server runs, plus an approved .envrc per project (direnv allow). |
| Lint feedback | Node on the shell's PATH, project-installed ESLint 9 or 10, and a flat eslint.config.* file. |
| Subagent sidebar, stats, chat title, sidebar resize, usage | The OpenCode terminal UI. |
| Goal, chat title, sidebar resize, usage | OpenCode V2 with the 2.0.27 plugin API and OpenTUI 0.5.17 or later. Goal also requires its server plugin. |
Develop
Development and tests require Bun, Node.js 22+, and direnv:
git clone https://github.com/madsoftwaredev/opencode-plugins.git
cd opencode-plugins
bun install --frozen-lockfile
bun run check
bun run check runs the entrypoint build check and all package and release-script tests.
The test command preloads the OpenTUI Solid JSX transform for rendered TUI tests. Tests use
temporary projects and do not require a live OpenCode server.
To try a package directly from the latest source before a release:
opencode plugin add 'github:madsoftwaredev/opencode-plugins#main::path:packages/direnv'
Replace direnv with the package directory you want to try.
Issues and ideas are welcome in the GitHub issue tracker.
Maintainers: Publishing Releases
Each package versions and releases on its own. Decide the bump per package, then update only the manifests you changed and refresh the lockfile:
bun install
bun run check
For a package's first npm release, sign in with npm login and publish that
package once locally, for example:
bun scripts/publish.ts packages/goal --expected-version 0.1.0
Then configure that new package's Trusted Publisher to use release.yml, as
described below. Existing packages' Trusted Publisher settings do not change.
Subsequent releases use the tag-triggered workflow.
Preview what a tag would publish before pushing it (the planned version must already be in the manifest):
bun run release:plan packages/stats --expected-version 0.1.3 --dry-run
Stage the version bumps, commit them, and push a tag named after the package
directory. For example, after changing stats to 0.1.3:
git add packages/stats/package.json bun.lock
git commit -m "release: stats 0.1.3"
git tag 'stats@0.1.3'
git push origin main 'stats@0.1.3'
The release workflow verifies that package and publishes it with provenance; packages whose version did not change are not touched. A tag for an already-published version is a no-op, so a re-run is safe. Release more than one package by pushing one tag per package.
Configure npm Trusted Publishing for each package with GitHub organization
madsoftwaredev, repository opencode-plugins, workflow filename release.yml,
and direct npm publish enabled. Trusted Publishing requires Node.js 22.14.0+
and npm 11.5.1+ on the runner.
License
同类生态推荐
Better Compact
better-compact
OpenCode plugin that improves long-session context with boundary-time pruning
Compaction Guard
opencode-compaction-guard
OpenCode plugin that prevents and auto-recovers from the 'tool_use ids were found without tool_result blocks' error that makes sessions unrecoverable after auto-compaction or interrupted tool calls.
Context Pruner
opencode-context-pruner
Continuous verbatim context pruning for OpenCode, powered by TypeSafe Jev. Port of fast-jev-compaction adapted to OpenCode's context hook.