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 Request: Custom compaction threshold to trigger earlier #10017
Currently, auto-compaction only triggers when token count exceeds the model's context limit (count > usable in compaction.ts):
exportasyncfunctionisOverflow(input: {tokens;model}){// ...constcount=input.tokens.input+input.tokens.cache.read+input.tokens.outputconstusable=input.model.limit.input||context-outputreturncount>usable// Only triggers at the limit}
For models with large context windows (e.g., Claude Opus/Sonnet with 200K), this means:
Users must accumulate ~200K tokens before auto-compaction kicks in
By that point, API responses are already extremely slow (10+ minutes of waiting)
The "auto" compaction effectively becomes useless for preventing slowdowns
Proposed Solution
Add a configurable threshold option to trigger compaction earlier:
{
"compaction": {
"auto": true,
"prune": true,
"threshold": 50000// Trigger compaction when input tokens exceed this value
}
}
Implementation would be straightforward - modify isOverflow() to check against the threshold:
exportasyncfunctionisOverflow(input: {tokens;model}){constconfig=awaitConfig.get()if(config.compaction?.auto===false)returnfalseconstcount=input.tokens.input+input.tokens.cache.read+input.tokens.output// Check custom threshold firstif(config.compaction?.threshold&&count>config.compaction.threshold){returntrue}// Fall back to model limit checkconstcontext=input.model.limit.contextif(context===0)returnfalseconstoutput=Math.min(input.model.limit.output,SessionPrompt.OUTPUT_TOKEN_MAX)||SessionPrompt.OUTPUT_TOKEN_MAXconstusable=input.model.limit.input||context-outputreturncount>usable}
Use Case
After 20-30 conversation turns with many tool calls, sessions become painfully slow. Users currently must:
Notice the slowdown (often too late)
Manually run /compact
With a configurable threshold, users could set a reasonable limit (e.g., 50K-80K tokens) to maintain responsive sessions automatically.
Alternatives Considered
Manual /compact: Works but requires user vigilance; easy to forget until it's too late
Lower the percentage of context used: Less flexible than an absolute threshold
Additional Context
Related code: packages/opencode/src/session/compaction.ts
This is gonna be a great addition, Not everyone has the best rig out there for local models nor even setting a context window of 200k just to use the auto compaction feature.
Activity
github-actions commentedon Jan 22, 2026
This issue might be a duplicate of existing issues. Please check:
Feel free to ignore if none of these address your specific case.
saksham1341 commentedon Jan 23, 2026
Would it be better to compact based on context percentage threshold instead of token count threshold? Or could provide an option?
For example:
Could auto-compact whenever either of the conditions is met.
feat(compaction): add configurable threshold and model (global + per-…
FN-FAL113 commentedon Feb 16, 2026
This is gonna be a great addition, Not everyone has the best rig out there for local models nor even setting a context window of 200k just to use the auto compaction feature.
lucad87 commentedon Mar 14, 2026
up
github-actions commentedon May 14, 2026
To stay organized issues are automatically closed after 60 days of no activity. If the issue is still relevant please open a new one.