Skip to content

Experimental compaction improvements (prefix preservation + prompt customization) #11497

@dixoxib

Description

@dixoxib

Problem

When sessions are compacted, the system currently switches to a generic "compaction" agent, losing:

  1. Original agent's tool definitions and system prompts
  2. Specialized instructions or model-specific optimizations
    → 3. Prefix cache benefits for providers that implement caching (Claude, GPT-4, etc.)

Proposed Solution

Add experimental feature flags for:

  1. OPENCODE_EXPERIMENTAL_COMPACTION_PRESERVE_PREFIX - Preserve original agent's prefix cache during compaction
  2. additionally OPENCODE_EXPERIMENTAL_COMPACTION_PROMPT - Allow customizable compaction prompts

Benefits

  • Performance: Cache hits for providers with prefix caching reduce token usage costs and latency up to 90%
  • Flexibility: Users can customize compaction prompts for their workflow
  • Gradual rollout: Experimental flags allow testing before stabilization

Testing

export OPENCODE_EXPERIMENTAL_COMPACTION_PRESERVE_PREFIX=true
export OPENCODE_EXPERIMENTAL_COMPACTION_PROMPT="Custom prompt if needed"

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions