r/opencode • • 27d ago

OpenCode Native Auto Compaction Not Triggering Automatically, Any Solution?

I'm having an issue with OpenCode's native auto compaction feature. It doesn't seem to trigger automatically even when context usage gets close to the limit.

I've already enabled auto compaction and configured it as follows:

"compaction": {
  "auto": true,
  "keep": {
    "tokens": 40000
  },
  "buffer": 20000
}

However, the session continues consuming context without triggering automatic compaction as expected.

I'm not sure whether this is caused by an incorrect configuration, the compaction trigger threshold, or a potential issue with OpenCode itself.

A few questions:

  1. Is my current configuration correct for ensuring native auto compaction works reliably?
  2. Are there any known issues with auto compaction failing to trigger with certain models or providers?
  3. Is there a reliable solution without having to run /compact manually?

I'd prefer to keep using OpenCode's built-in native compaction rather than relying on external scripts or manual intervention.

If anyone has experienced the same issue and found a reliable solution, I'd really appreciate your insights.

Thanks!

1 Upvotes

1 comment sorted by

View all comments

1

u/CreativeSympathy8293 27d ago

For V2, 40000 isn't the automatic trigger. keep.tokens is the approximate recent conversation retained beside the summary. buffer: 20000 reserves headroom below the model's limit; a larger buffer starts compaction earlier: https://opencode.ai/v2/docs/compaction/

I'd check the limit OpenCode knows for your selected model/provider. If it exceeds what the endpoint actually accepts, the provider can reject a request before OpenCode expects to compact. For a custom model, verify its configured limits against the actual server/provider. The current model docs warn that fallback limits aren't detected capabilities: https://opencode.ai/v2/docs/models/

Please share the OpenCode version, model/provider, and displayed context used/limit at the problem point. Also note whether compaction never starts or starts and produces an error; those need different investigations. Share only that small redacted detail, not your conversation or full configuration.

AI-assisted from current V2 docs; I haven't reproduced this or verified a fix.