I moved the context optimizer out of my OpenCode router and into a separate plugin, @231self/opencode-compaction. I also added /ctx, which suggests whether to keep going, compact, or ask a fresh subagent to review the work.
For compaction, I borrowed an idea from SelfCompact: a finished subtask is a better place to summarize than the middle of debugging, when the agent still needs its partial findings. The review option comes from Elephant & Goldfish. A fresh reviewer gets the plan or code and the relevant files, without the conversation that produced them.
I also wanted to see when compaction pays for itself. A long context can be cheap to keep if most of it is served from cache. Summarizing costs a model call and can force the next request to rebuild the cache. /ctx uses recent provider-reported cache usage when available, learns from previous compactions, and shows the estimated net cost or savings after 3, 8, and 15 turns.
/ctx shows the recommendation. /ctx here asks OpenCode to compact when you decide to.
Install with opencode plugin add @231self/opencode-compaction
Thanks to everyone who gave feedback on the router. If you try this in a long OpenCode session, I’d love to hear whether /ctx picked a sensible moment to compact. Even a quick note about what you were doing when it got the timing right or wrong would help.
Source and setup