Feature hasn't been suggested before.
Describe the enhancement you want to request
Describe the enhancement you want to request
OpenCode's current compaction behavior compresses the whole session history when approaching context limits. This creates a painful tradeoff for exploratory tasks: you spend 80k tokens debugging or investigating something, reach a clear conclusion — and then compaction blurs it all into a generic summary.
The core issue: compaction is all-or-nothing. There's no way to say "compress just this investigation phase into its conclusion, leave everything else as-is."
Proposed behavior
A compact_scope tool that the agent calls retroactively after completing an exploration phase — no upfront marking needed:
# Agent calls this after reaching a conclusion
compact_scope(
summary="Auth bug root cause: race condition in token refresh. Fix: mutex lock.",
discard_from=5
)
# → everything from turn 5 onward is replaced with the summary; earlier context untouched
The conclusion block injected would be more precise than a global compact summary because it covers a narrow, well-defined investigation with a known outcome. The agent decides after the fact which turns to compress — no need to predict scope boundaries in advance.
Why not subagents?
Subagents solve a different problem (parallel work, isolated context). This is about the main session's own history — the agent walked down a long road, found the answer, and now needs to "squash" those turns without disturbing the surrounding context.
Analogy
git squash for context: exploratory turns collapse into one clean conclusion commit. The rest of the session log is untouched.
Additional context
Claude Code's /compact already supports custom instructions (e.g. /compact "focus on conclusions"). Scoped compaction extends this idea to sub-session granularity. It could also be exposed as an internal tool that the agent triggers autonomously when it detects a phase transition.
Feature hasn't been suggested before.
Describe the enhancement you want to request
Describe the enhancement you want to request
OpenCode's current compaction behavior compresses the whole session history when approaching context limits. This creates a painful tradeoff for exploratory tasks: you spend 80k tokens debugging or investigating something, reach a clear conclusion — and then compaction blurs it all into a generic summary.
The core issue: compaction is all-or-nothing. There's no way to say "compress just this investigation phase into its conclusion, leave everything else as-is."
Proposed behavior
A
compact_scopetool that the agent calls retroactively after completing an exploration phase — no upfront marking needed:The conclusion block injected would be more precise than a global compact summary because it covers a narrow, well-defined investigation with a known outcome. The agent decides after the fact which turns to compress — no need to predict scope boundaries in advance.
Why not subagents?
Subagents solve a different problem (parallel work, isolated context). This is about the main session's own history — the agent walked down a long road, found the answer, and now needs to "squash" those turns without disturbing the surrounding context.
Analogy
git squashfor context: exploratory turns collapse into one clean conclusion commit. The rest of the session log is untouched.Additional context
Claude Code's
/compactalready supports custom instructions (e.g./compact "focus on conclusions"). Scoped compaction extends this idea to sub-session granularity. It could also be exposed as an internal tool that the agent triggers autonomously when it detects a phase transition.