Skip to content

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

Closed

Description

@ds573949554-lab

问题

使用 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

Activity

  1. github-actions commented on Jan 20, 2026

    @github-actions
    Contributor

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

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

  2. ds573949554-lab commented on Jan 20, 2026

    @ds573949554-lab
    Author

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

    • 响应变慢
    • 开始遗忘之前的内容
    • Auto-compaction 似乎没有触发
      希望能尽快修复,长对话体验非常依赖这个功能 🙏
  3. jensenojs commented on Jan 21, 2026

    @jensenojs
    Contributor
  4. github-actions commented on Mar 28, 2026

    @github-actions
    Contributor

    To stay organized issues are automatically closed after 90 days of no activity. If the issue is still relevant please open a new one.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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