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

Open
opened 2026-02-16 18:09:17 -05:00 by yindo · 1 comment
Owner

Originally created by @dixoxib on GitHub (Jan 31, 2026).

Originally assigned to: @thdxr on GitHub.

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"
Originally created by @dixoxib on GitHub (Jan 31, 2026). Originally assigned to: @thdxr on GitHub. ## 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 ```bash export OPENCODE_EXPERIMENTAL_COMPACTION_PRESERVE_PREFIX=true export OPENCODE_EXPERIMENTAL_COMPACTION_PROMPT="Custom prompt if needed" ```
Author
Owner

@github-actions[bot] commented on GitHub (Jan 31, 2026):

This issue might be a duplicate of existing issues. Please check:

  • #6535: Subagent loses original context and system prompt during compaction
  • #3032: Soft compaction / AI global workspace metabolism - proposes alternative compaction strategy to preserve context
  • #4659: Sliding window context management for long-running sessions - addresses context preservation across compactions
  • #7351: Add systemPrompt option to SDK - relates to the customizable compaction prompt aspect

Feel free to ignore if none of these address your specific case.

@github-actions[bot] commented on GitHub (Jan 31, 2026): This issue might be a duplicate of existing issues. Please check: - #6535: Subagent loses original context and system prompt during compaction - #3032: Soft compaction / AI global workspace metabolism - proposes alternative compaction strategy to preserve context - #4659: Sliding window context management for long-running sessions - addresses context preservation across compactions - #7351: Add systemPrompt option to SDK - relates to the customizable compaction prompt aspect Feel free to ignore if none of these address your specific case.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: anomalyco/opencode#8155