You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
[FEATURE] Add auto-compact threshold for long sessions #40113
Currently opencode TUI has no automatic context compression. After long sessions, context grows uncontrollably (observed 160K+ tokens), forcing manual compact command.
Hi! Building a plugin that addresses this differently: instead of waiting for an auto-compact threshold, the agent compacts its own context proactively, mid-task.
It exposes compact_context() as a tool — non-blocking, between steps, then the agent continues from a fresh summary. No waiting for the context to grow to 160K+, no manual compact at the wrong moment. Zero custom logic — just the built-in compaction wrapped as a tool.
This is needed when using APIs and having long sessions / runs. If a runs grows large and you don't notice ... then you notice the bill at the end of the month !
V2 automatically compacts long sessions by default, and compaction.buffer lets you set how many tokens before the model's usable input limit compaction starts. You can also configure how much recent context is retained with compaction.keep.tokens. To get v2: npm i -g @opencode/cli@latest or curl -fsSL https://opencode.ai/v2/install | bash (desktop: update the app). If you still see this on v2, please open a new issue with the details.
Though, "compaction.buffer lets you set how many tokens before the model's usable input limit compaction starts" does not seem to really fit the need.
If I understood correctly, it depends on the model selected and its maximum input token budget ... which usually you would rather define "I want compaction starting at X amount of token"...
Activity
github-actions commentedon Aug 2, 2026
This issue might be a duplicate of existing issues. Please check:
autoCompactThresholdideaIf your request is meaningfully different from these, please clarify what's distinct.
coyc commentedon Aug 2, 2026
Hi! Building a plugin that addresses this differently: instead of waiting for an auto-compact threshold, the agent compacts its own context proactively, mid-task.
It exposes compact_context() as a tool — non-blocking, between steps, then the agent continues from a fresh summary. No waiting for the context to grow to 160K+, no manual compact at the wrong moment. Zero custom logic — just the built-in compaction wrapped as a tool.
Details: https://github.com/coyc/opencode-agent-compaction
ndeybach commentedon Sep 30, 2026
+1
This is needed when using APIs and having long sessions / runs. If a runs grows large and you don't notice ... then you notice the bill at the end of the month !
neriousy commentedon Oct 19, 2026
V2 automatically compacts long sessions by default, and
compaction.bufferlets you set how many tokens before the model's usable input limit compaction starts. You can also configure how much recent context is retained withcompaction.keep.tokens. To get v2:npm i -g @opencode/cli@latestorcurl -fsSL https://opencode.ai/v2/install | bash(desktop: update the app). If you still see this on v2, please open a new issue with the details.ndeybach commentedon Oct 20, 2026
Hi @neriousy ,
Thanks for the headsup and informations.
Though, "
compaction.bufferlets you set how many tokens before the model's usable input limit compaction starts" does not seem to really fit the need.If I understood correctly, it depends on the model selected and its maximum input token budget ... which usually you would rather define "I want compaction starting at
Xamount of token"...