Back to blog
Context
Opencode

How do you free context room across models without counting tokens?

Thắng Đoàn
Thắng Đoàn

Setting aside context for compaction by token count means re-tuning per model, and a wrong guess stalls sessions. opencode now lets you set compaction.buffer as a percentage of the model's context window so one config fits every model.

What it is

The compaction.buffer setting in opencode.json accepts a percentage like "20%" in addition to a raw token count. The buffer keeps that share of the model's context window free, and token counts still work.

Applied case

A developer bouncing between a small-window model and a large-window one no longer maintains two buffer values. They write "compaction": { "buffer": "20%" } once, and the same fraction applies whichever model is active. Compaction also now caps its prompt at the model's context window when the input limit is larger, and LiteLLM context window errors trigger compaction instead of stopping the session.

  • One percentage buffer replaces per-model token tuning across small and large context windows
  • Try it in 2 minutes: add the buffer line to one project's opencode.json and resume a session

When to use it

Use when you swap models with different context sizes or hit mid-session context errors.
Skip when you already know your exact token headroom for a single fixed model. Note: a percentage buffer reserves room, it does not stop context filling before compaction triggers.

"compaction": { "buffer": "20%" }

Read more

opencode release v2.2.5

pull 60647

pull 60692

Share:

Recommended for you

Enjoyed this article?

Subscribe for new articles. No spam. Unsubscribe anytime.

By subscribing you agree to receive the newsletter. No spam, and you can unsubscribe anytime.