Feature Request: Auto Context Compression (like Claude Code) #6956

Open
opened 2026-02-16 18:05:42 -05:00 by yindo · 3 comments
Owner

Originally created by @ds573949554-lab on GitHub (Jan 20, 2026).

Originally assigned to: @thdxr on GitHub.

问题

使用 OpenCode 进行长对话时,上下文窗口会填满(Claude 的 200K token 限制)。与 Claude Code 不同,OpenCode 会将完整对话历史发送给 API,没有压缩。

当前行为

  • 所有消息直接发送给 Claude API,无压缩
  • 达到 ~80% 容量时,响应变慢/不可靠
  • 用户必须手动开新对话,丢失上下文

建议方案

实现类似 Claude Code 的自动上下文管理:

1. 滑动窗口

  • 只保留最近 N 条消息(如 20 条)完整内容
  • 旧消息压缩成摘要

2. 自动摘要

  • 当上下文超过阈值(如 70%)时自动:
    1. 生成旧消息的结构化摘要
    2. 用摘要替换旧消息
    3. 无缝继续对话

3. 用户命令

  • /compact - 手动触发压缩
  • /context - 显示当前 token 使用情况

收益

  • 用户可以「一个对话用到底」
  • 更好的长时间编程会话体验
  • 与 Claude Code 功能对齐

环境

  • OpenCode v1.1.20
  • macOS
Originally created by @ds573949554-lab on GitHub (Jan 20, 2026). Originally assigned to: @thdxr on GitHub. ## 问题 使用 OpenCode 进行长对话时,上下文窗口会填满(Claude 的 200K token 限制)。与 Claude Code 不同,OpenCode 会将完整对话历史发送给 API,没有压缩。 ## 当前行为 - 所有消息直接发送给 Claude API,无压缩 - 达到 ~80% 容量时,响应变慢/不可靠 - 用户必须手动开新对话,丢失上下文 ## 建议方案 实现类似 Claude Code 的自动上下文管理: ### 1. 滑动窗口 - 只保留最近 N 条消息(如 20 条)完整内容 - 旧消息压缩成摘要 ### 2. 自动摘要 - 当上下文超过阈值(如 70%)时自动: 1. 生成旧消息的结构化摘要 2. 用摘要替换旧消息 3. 无缝继续对话 ### 3. 用户命令 - `/compact` - 手动触发压缩 - `/context` - 显示当前 token 使用情况 ## 收益 - 用户可以「一个对话用到底」 - 更好的长时间编程会话体验 - 与 Claude Code 功能对齐 ## 环境 - OpenCode v1.1.20 - macOS
Author
Owner

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

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

  • #4659: [FEATURE] Sliding window context management for long-running sessions - Comprehensive solution for context preservation during long sessions
  • #6152: [FEATURE]: Session context usage (similar to /context in Claude) - Proposes the same /context command to display token usage
  • #6034: [FEATURE]: Prompt Compression - Earlier feature request for prompt compression
  • #8089: Auto-compaction enabled by default, but context_length_exceeded errors still occur in agent workflows - Discusses issues with current auto-compaction implementation
  • #6068: [BUG]: Auto compaction not triggering reliably with Anthropic models - Reports bugs with existing auto-compaction

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

@github-actions[bot] commented on GitHub (Jan 20, 2026): This issue might be a duplicate of existing issues. Please check: - #4659: [FEATURE] Sliding window context management for long-running sessions - Comprehensive solution for context preservation during long sessions - #6152: [FEATURE]: Session context usage (similar to /context in Claude) - Proposes the same `/context` command to display token usage - #6034: [FEATURE]: Prompt Compression - Earlier feature request for prompt compression - #8089: Auto-compaction enabled by default, but context_length_exceeded errors still occur in agent workflows - Discusses issues with current auto-compaction implementation - #6068: [BUG]: Auto compaction not triggering reliably with Anthropic models - Reports bugs with existing auto-compaction Feel free to ignore if none of these address your specific case.
Author
Owner

@ds573949554-lab commented on GitHub (Jan 20, 2026):

+1 遇到同样问题
使用 OpenCode v1.1.20 + Claude,对话到 ~70-80% token 时:

  • 响应变慢
  • 开始遗忘之前的内容
  • Auto-compaction 似乎没有触发
    希望能尽快修复,长对话体验非常依赖这个功能 🙏
@ds573949554-lab commented on GitHub (Jan 20, 2026): +1 遇到同样问题 使用 OpenCode v1.1.20 + Claude,对话到 ~70-80% token 时: - 响应变慢 - 开始遗忘之前的内容 - Auto-compaction 似乎没有触发 希望能尽快修复,长对话体验非常依赖这个功能 🙏
Author
Owner

@jensenojs commented on GitHub (Jan 21, 2026):

@jensenojs commented on GitHub (Jan 21, 2026): - https://opencode.ai/docs/config/#compaction
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: anomalyco/opencode#6956