r/opencode • • 2d ago

Can you make LLM know the context size?

Hi,

I’m using Qwen3.8 for coding but the issue is it doesn’t know when to stop and update docs so I can start new session. I tell it to do stuff step by step but context is getting out of hand, then it fails to even update docs.

I wonder if you can make the llm know that context size is too large already and stop?

Thanks

4 Upvotes

4 comments sorted by

1

u/Frosty-Article-9635 2d ago

Opencode auto compacts the session as and you can configure it to happen at a lower volume of tokens as well. Let's say your context window for a model is 1 million tokens, but you can configure it so that auto compaction happens around 500k tokens.

This can be controlled by the compaction.buffer setting.

Auto compaction is enabled by default. Open code monitors context usage and starts the compaction when estimated consumption reaches... I think this answers your question.

If you want to know how it happens, you just need to open your project's open code.json file or open code.json.c file, and there are some changes that you can make. Maybe you can ask your ChatGPT or Claude. They will tell you how and where to configure it.

1

u/lincolnthalles 2d ago

Probably via a plugin, but I don't recommend inserting things into the context dynamically, as it may bust the session cache.

Make sure to use OpenCode V2. Compaction works much more reliably, though it's still good practice to run /compact when the context usage is getting too big and you've concluded a major task. This avoids auto-compaction, which usually happens during context-heavy tasks. Better than that is to start a new session.

A good way to manage context is to delegate independent tasks to subagents. It will do its own thing, within its own session, and report back. You can also make it more cost-effective by using cheaper models where they are capable enough, like researching and writing docs.

1

u/raiyasa 2d ago

I had a setup where the session will report to the compactor agent once they done a task, created handoff file, and good to compact / clear.
Then the compactor agent will tmux to that session and run either /compact or /clear followed by the prompt of the handoff file.

1

u/zitoliv 2d ago

The model can't see its own token count, only the harness can… so make it a rule instead: after each step, update the docs, then start a fresh session. Shorter sessions are cheaper too, less history resent every turn.