Skip to content

[FEATURE]: Scoped compaction — compress exploratory context segments without touching the rest #17603

@cyborg42

Description

@cyborg42

Feature hasn't been suggested before.

  • I have verified this feature I'm about to request 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.

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions