I Shipped My Config Fix as an OpenCode Plugin

My last post, Why My Model Provider Rejected the Word medium, ended with four lines of config.

I had written about a 400 I could not read. OpenCode was sending reasoning_effort: "medium" to my provider, and the provider refused it with a message that named no parameter and no value. The cause was a guess OpenCode makes for any model it cannot find in models.dev: with no catalog entry to read, it assumes the only reasoning levels are low, medium, and high. I declared the variants each model accepts, and the provider stopped rejecting me.

That fix only helped me.

Anyone else on a provider missing from the catalog, a private gateway, a fresh model, a self-hosted endpoint, walks into the same wall. They either learn the variants machinery or they give up and blame the tool. The catalog entry is the real fix for everyone, and I sent that too. But the catalog will always lag, and a private endpoint will never appear in it at all. So I built the net that sits underneath the config fix.

It is called opencode-reasoning-effort-guard, it is on npm, and this is how it works.

What the config fix left behind

The config fix is a promise I made by hand. I told OpenCode the truth about one model, then another, then another. Every new model is another promise, and every promise is a chance to forget one.

There is also a quieter problem. The variants block tells OpenCode which values to offer. It does not stop a value from arriving some other way, from an older config, a per-request override, an experiment, or a default that changed underneath me. The setting that reaches the provider is the last one written, not the one I meant.

The guard is a last look before the request leaves. If the effort is one the model does not accept, it puts back the nearest value the model does.

The guard, in plain words

You give it the values each model accepts, keyed the same way you already name your providers and models. It watches the effort on the way out and corrects it when it is wrong.

{
  "plugins": [
    {
      "package": "opencode-reasoning-effort-guard",
      "options": {
        "models": {
          "river/deepseek-ai/DeepSeek-V4.1-Flash": ["none", "high", "max"],
          "river/zai-org/GLM-5.3-Flash": ["low", "high", "max"]
        },
        "onUnsupported": "warn"
      }
    }
  ]
}

A model I have not listed is left completely alone. The guard only touches what I have described to it, which keeps the blast radius at zero: it cannot break a model it has never heard of.

The rule is a nearest value, not a nearest guess:

RequestedModel acceptsSent
highnone, high, maxhigh (unchanged)
mediumnone, high, maxhigh
lownone, high, maxhigh
minimalnone, maxnone

Two judgement calls are baked in. Ties go to the higher level, so a graded request never falls down to an off value when both are equally close. And an unrecognised level resolves to the lowest graded value, never to off, because silently turning reasoning off is worse than reasoning too little.

With onUnsupported set to warn, a corrected call says so:

[reasoning-effort-guard] river/deepseek-ai/DeepSeek-V4.1-Flash: "medium" is not supported, using "high"

The part that took the afternoon

The clamping rule is ten lines. Finding the value to clamp took the whole afternoon, and this is the part of the plugin worth reading about.

A plugin gets a hook that runs just before a request is dispatched. The obvious place to look for the reasoning effort is the request options, and that is the trap. For a model with no catalog entry, that field is empty. The level OpenCode chose is not there.

It arrives somewhere else: on the model, as the selected variant. When OpenCode synthesises low, medium, and high for a model it cannot read, it applies the chosen level as a model default rather than as a per-request option. A guard that only read the request options would load cleanly, match cleanly, and change nothing, and I would have shipped a plugin that does nothing while looking like it does.

The way out is to treat the variant as the starting point and write the corrected value back to the request options. A per-request value wins over a model default, so the corrected one is what the provider receives. That is the entire trick, and it only shows itself on a live request. Unit tests cannot find it, because the thing that is missing is the OpenCode side.

Keeping the logic honest

None of the decision logic lives near OpenCode. It is one file, src/guard.ts, with no imports from the tool at all: it takes an effort and a list of accepted values and returns a value to send.

That split is the reason the rules can be read like the table above and tested like a table. The order of levels, the tie toward the higher one, the fallback that never lands on off: each is a straight line of code with a test beside it, twenty-six of them, and a type check on top.

The part that talks to OpenCode is thin, a hook adapter and nothing else. If the tool changes how it calls plugins, that is the only file that has to move.

Testing it against the thing that broke

I did not trust the unit tests for this one, because the bug they cannot catch was exactly the bug I was worried about.

First I built a sealed test: a throwaway config directory, a provider pointed at the same endpoint, the guard installed, and the real provider on the other end. Three cases, run through the real agent:

  • guard on, #high: no warning, the call works
  • guard on, #medium: warns once and corrects to high, the call works
  • guard off, #medium: Invalid inference request. Check the model's supported parameters and input limits.

Then I ran it on my own machine, with my real config and my real key, because a sealed test only proves the test is sealed. The middle case is the whole point:

[reasoning-effort-guard] river/deepseek-ai/DeepSeek-V4.1-Flash: "medium" is not supported, using "high"

Same request, no 400, and a line telling me what happened. I put the config back exactly as it was when I finished.

Shipping it

opencode plugin add opencode-reasoning-effort-guard
opencode plugin list

It is MIT, it has no build step, and the test command is npm test.

Publishing had one moment worth remembering, because it taught me something I keep reusing. The install failed with a message that read like a bug in my package: Plugin package has no server or TUI entrypoint. That is the kind of error that sends you straight into your own packaging, checking entry points and export maps.

It was not my package. OpenCode caches the copy it unpacks, and the cached copy was npm’s temporary placeholder, a package.json with no code in it, left behind while the real version sat in npm’s new staged-publishing queue. The tarball I had published was fine the whole time. Clearing the cache and installing again worked.

The error pointed at my package. The cause was a stale copy on my disk. An error message is a claim, not a diagnosis, and that cost me more time than the actual bug it pretended to describe.

What I took from it

The smallest useful thing here is a guard, not a rewrite. It does not fix OpenCode. It refuses to let OpenCode’s guess reach a provider that would have rejected it, and it says so when it steps in. Small, and enough.

The hard part is rarely the logic. Which value to send is a table and ten lines. Where the value lives, and how to change it so the change survives to the wire, is where the afternoon went.

And a guard is only as good as its honesty about what it does not know. It stays out of models I did not describe. It never turns reasoning off by accident. It tells me when it corrects something instead of hiding it. Most of the design is that, not the arithmetic of picking the nearest level.

One note on method, in the same spirit as the last post. I worked this alongside OpenCode’s own agent, the source on one side and the live provider on the other, until the behaviour was the same on every run. The tests, the rules, the tie-breaks, and the reasons behind them are mine to defend, and I can explain every line.

If you run a provider that is not in the catalog, this sits under your config and catches the guess before it reaches anyone. If you are on a catalogued model, you do not need it, and with any luck the catalog catches up and it becomes unnecessary for everyone.


Package: npm - opencode-reasoning-effort-guard
Source: GitHub - mmestiyak/opencode-reasoning-effort-guard

Written by . Software engineer from Bangladesh. I ship products end to end, from the browser to the board: code generation, firmware and PCB tooling at IDEEZA, and my own products ProcureIndex, Akhra and Kommercly. Also farms, cycles and fights MMA.

Published

Get new logs by email. No spam, unsubscribe anytime.