Skip to content

opencode adapter strips custom provider prefix from --model, breaking ohm/ and other user-defined providers #171

Open

Description

@doink-kindo

Summary

The opencode adapter unconditionally strips the first /-segment of an explicit --model argument before invoking opencode. This breaks any user-defined custom provider in ~/.config/opencode/opencode.json (e.g. a local ohm proxy), because the resulting model string drops the provider that opencode actually needs to look up.

For us this manifested as every agentctl launch opencode --model "ohm/moonshotai/Kimi-K2.6" dying within 30s on 2026-05-04, with the wrapper log showing:

ProviderModelNotFoundError: ProviderModelNotFoundError
 data: {
  providerID: "moonshotai",
  modelID: "Kimi-K2.6",
  suggestions: [],
}
Error: Model not found: moonshotai/Kimi-K2.6.

agentctl had stripped ohm/ and then passed moonshotai/Kimi-K2.6 to opencode, which interpreted moonshotai as a (non-existent) provider.

Root cause

dist/adapters/opencode.js ~line 138 inside resolveOpenCodeModel:

if (opts.model) {
    if (isModelCompatible(opts.model)) {
        return opts.model;
    }
    validateApiKeyForModel(opts.model, env);
    // 👇 strips first `/` segment unconditionally
    return opts.model.split("/").slice(1).join("/");
}

The strip assumes the prefix is one of the standard provider IDs (openai/, anthropic/, ...) that opencode auto-recognises and would reject. But opencode's provider map in opencode.json is user-extensible — ohm/..., togetherai/..., etc. are valid <provider>/<model> pairs that opencode resolves correctly when passed through verbatim.

When the workspace config supplies the model (no explicit --model), the adapter takes a different path (readWorkspaceModel) that does not strip, and everything works. So the inconsistency is: explicit --model ohm/... ❌, workspace-config ohm/... ✅.

Reproduction

  1. Configure ~/.config/opencode/opencode.json with a custom provider, e.g. an ohm block pointing at a local OpenAI-compatible gateway with models: { "moonshotai/Kimi-K2.6": {...} }.
  2. agentctl launch opencode --model "ohm/moonshotai/Kimi-K2.6" --cwd /tmp -p "say hi" — dies fast.
  3. agentctl launch opencode --cwd /tmp -p "say hi" (no --model, workspace config value "ohm/moonshotai/Kimi-K2.6") — works.

Wrapper diff:

  • Failing: opencode 'run' '--model' 'moonshotai/Kimi-K2.6' '--' 'say hi' (prefix stripped)
  • Working: opencode 'run' '--model' 'ohm/moonshotai/Kimi-K2.6' '--' 'say hi' (prefix preserved, sourced from workspace config)

Suggested fix

Don't strip when the prefix is a known opencode provider in the user's workspace opencode.json. Concretely:

  1. Parse the workspace opencode.json (already read by readWorkspaceModel) and extract Object.keys(cfg.provider || {}) as a known-custom-provider set.
  2. In the explicit-opts.model branch, if the prefix is in that set, skip the strip and return opts.model verbatim.
  3. Optionally: if the prefix matches a built-in opencode provider ID (openai, anthropic, google, ...) keep current strip behaviour so the existing API-key validation path still applies.

A minimal alternative is to flip the default — pass --model through verbatim and only strip when explicitly opted in. The current behaviour silently breaks any custom provider workflow.

Side-by-side: codex adapter

For consistency, note that the codex adapter does the opposite — it passes --model through verbatim, with no stripping. So agentctl launch codex --model "openai/gpt-5.4" reaches OpenAI's API as model: "openai/gpt-5.4" and is rejected (The requested model 'openai/gpt-5.4' does not exist). Users have to know to pass the bare model name gpt-5.4. This is also footgun-y but at least surfaces a clean upstream error.

Workaround

Per our updated docs:

  • opencode: omit --model, let agentctl resolve from ~/.config/opencode/config.json.
  • codex: pass bare model name (gpt-5.4, not openai/gpt-5.4).

Environment

  • agentctl: /Users/ms/personal/agentctl/dist/cli.js (build from ~/personal/agentctl)
  • opencode: 1.2.11
  • codex: 0.104.0
  • macOS Darwin 25.4.0 arm64

Related memory

  • 2026-04-30: daemon env validation bug — validateApiKeyForModel() only sees the daemon process env, not ~/.zshenv. Workaround: start daemon from a login shell.
  • 2026-04-30: codex [agents] integer-fields rejection — max_threads/max_depth/job_max_runtime_seconds at top level under [agents] is rejected by Codex 0.104.0.
  • 2026-05-04: this issue (model-prefix strip).

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions