opencode-token-saver
v0.1.1
Published
Safe Token Saver guidance and child-session no-progress watchdog for OpenCode/OpenChamber.
Maintainers
Readme
Token Saver for OpenCode and OpenChamber
This adapter preserves Token Saver's safe token-efficiency guidance while leaving OpenCode's native compaction, planning, tool calls, and tool output untouched. It additionally uses the public OpenCode event hook to abort only a child session that has had no observed progress for 120,000 ms. Root/main sessions are never armed or aborted.
Install
Install the published package into OpenCode/OpenChamber's shared plugin directory:
npx --yes opencode-token-saverIt copies the package's self-contained plugin file to the configured OpenCode plugin directory and tells you when a restart is needed. This is the recommended one-command install for OpenCode and OpenChamber.
For current OpenCode and OpenChamber 1.x, the native installer is also available:
opencode plugin opencode-token-saver --globalOn a fresh 1.18.x cache, the native installer can download the package but report
a dependency-install error on its first run; retrying the same command normally
finishes it. The npx installer above avoids that path.
For the OpenChamber-bundled OpenCode binary on macOS:
/Applications/OpenChamber.app/Contents/Resources/opencode-cli/opencode plugin opencode-token-saver --globalNewer OpenCode v2 uses its updated command form:
opencode plugin add opencode-token-saverFor local development without publishing, pass this package directory to the same 1.x installer:
opencode plugin "$(pwd)" --globalindex.js is self-contained and can also be copied directly into the shared
OpenCode plugin directory:
mkdir -p ~/.config/opencode/plugins
cp index.js ~/.config/opencode/plugins/token-saver.jsOpenCode and OpenChamber share the OpenCode engine and configuration directory, so one global installation covers both. Restart or start a new OpenCode/OpenChamber session after installing or copying it.
Controls and safety
TOKEN_SAVER_ENABLED=false,0,off, ornoreturns no active hooks.TOKEN_SAVER_STALL_TIMEOUT_MSaccepts a positive millisecond override; the default is120000.- Child status comes from
session.created/session.updatedinfo.parentID. Unknown IDs are checked throughclient.session.getbefore any timer is armed. - Message, part/tool lifecycle, todo, and permission progress reset a child timer. Idle, error, and deletion clear it.
- Abort errors are contained and cannot crash the host. The adapter does not prove a particular host runtime delivered an event or killed a live child; its replay proves the plugin's client abort decision for the recorded event shape.
Run the portable test suite with npm test (it uses Node's built-in test runner).
