Skip to content

Auto-compact infinite loop with claude-opus-4.7-1m (GitHub Copilot) due to wrong context window #28543

@pushp1997

Description

@pushp1997

Description

Summary

When using github-copilot/claude-opus-4.7-1m (1M token context window), OpenCode reports context usage against what appears to be a ~200K denominator. Once real usage crosses ~200K, the TUI shows >100% (e.g. 236.9K (118%)) and auto-compaction fires repeatedly in a loop — compact runs, post-compact context is still "over limit" per the same wrong denominator, compact fires again. Burns Copilot tokens and blocks all work in the session.

Environment

  • OpenCode 1.14.40
  • Windows (pwsh)
  • Provider: GitHub Copilot (built-in)
  • Model: github-copilot/claude-opus-4.7-1m (1,000,000 token context)
  • Small model: github-copilot/claude-sonnet-4.6

Expected

  • OpenCode reads the actual model context window (1M for this model) and computes the percentage against it. At 236.9K usage the display should be ~24%, not 118%.
  • Auto-compact should not fire (well under threshold), and even if a model's limit is genuinely unknown, auto-compact must not re-fire immediately after a no-op compaction.

Actual

  • Context window for claude-opus-4.7-1m-internal is misread as roughly 200K.
  • Auto-compact loops indefinitely once real usage crosses that wrong threshold.

Workaround

Disable auto-compaction in ~/.config/opencode/opencode.json:
```json
{
"compaction": { "auto": false }
}
```
This breaks the loop but leaves the wrong percentage display.

Suggested fixes

  1. Map claude-opus-4.7-1m-internal (and any other *-1m-* Copilot variants) to a 1M context window in the github-copilot provider definition. Or pull the real limit from the Copilot API where possible.
  2. Add a loop guard to auto-compact: if a compaction run does not reduce token count below the threshold, do not fire again in the same session without user action.

Plugins

No response

OpenCode version

1.14.40

Steps to reproduce

  1. Configure OpenCode with model: github-copilot/claude-opus-4.7-1m.
  2. Leave compaction.auto at its default (true).
  3. Make a long conversation and let it hit auto-compaction.
  4. Use the session until real token usage exceeds ~200K (well below the model's real 1M limit).
  5. TUI shows context as e.g. 236.9K (118%).
  6. Auto-compact fires. After it completes, the percentage is still >100% against the wrong denominator, so it fires again. Loop.

Screenshot and/or share link

Image

Operating System

windows 11

Terminal

Windows Terminal

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions