Problem
When using OpenCode with local models (MLX, Ollama, LM Studio), each new turn sends the entire conversation history as the prompt. This causes progressively slower responses as context grows:
- Turn 1: Small prompt → fast prefill (~3s)
- Turn 5: Accumulated context → slow prefill (~30s+)
- Turn 10+: Massive prompt → unusable latency (minutes)
This is especially painful with local models where prompt processing is the bottleneck. Cloud APIs handle this better due to server-side caching, but local inference has to reprocess the full context every time.
Proposed Solution
Implement automatic context compaction — similar to how Claude Code handles it. When the conversation context approaches a configurable threshold:
- Summarize the conversation history (tool call results, code snippets, prior reasoning) into a compact representation
- Replace the full history with the summary + recent turns
- Continue the conversation with a much smaller prompt
Configuration
{
"context": {
"compaction": {
"enabled": true,
"strategy": "summarize",
"threshold": 32000
}
}
}
Why This Matters
- Local models (27B-70B) have limited context windows and slow prefill
- Agentic coding tasks naturally accumulate large contexts (file reads, grep results, edits)
- Without compaction, users are forced to manually start new conversations mid-task
- Claude Code, Cursor, and other tools already implement this — OpenCode should too
Problem
When using OpenCode with local models (MLX, Ollama, LM Studio), each new turn sends the entire conversation history as the prompt. This causes progressively slower responses as context grows:
This is especially painful with local models where prompt processing is the bottleneck. Cloud APIs handle this better due to server-side caching, but local inference has to reprocess the full context every time.
Proposed Solution
Implement automatic context compaction — similar to how Claude Code handles it. When the conversation context approaches a configurable threshold:
Configuration
{ "context": { "compaction": { "enabled": true, "strategy": "summarize", "threshold": 32000 } } }Why This Matters