Problem
When sessions are compacted, the system currently switches to a generic "compaction" agent, losing:
- Original agent's tool definitions and system prompts
- 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:
OPENCODE_EXPERIMENTAL_COMPACTION_PRESERVE_PREFIX - Preserve original agent's prefix cache during compaction
- 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"