How do you free context room across models without counting tokens?
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
Recommended for you
- ContextClaude Code
Why is the MCP you connected invisible to your spawned agent?
MCPs you wire into your main session do not cross into spawned sub-agents. The agent reports Linear unavailable and invents its scope from prompt text.
- ContextClaude Code
Why show your codebase to the agent instead of describing it?
You described your project in English. The agent produced generic code that matches none of it. Stop describing. Mention the file. Run the command.
- ContextClaude Code
How do you set up Claude Cowork so it can actually do real work?
A simple setup guide for Claude Cowork. Connect your files, tools, and preferences so Claude can do real work alongside you.
- ContextClaude Code
Why does your AI agent ignore your team's conventions?
You typed the rule in chat three times and the agent still broke it. Chat is for the current task. Project rules live in AGENTS.md. Yours is empty.
Enjoyed this article?
Subscribe for new articles. No spam. Unsubscribe anytime.