anomalyco / anomalyco/opencode

opencode attach --mini ignores --agent/--model flags

Open
#38,483 0 comments 0 reactions 1 assignee View on GitHub

@simonklee is already working on this.

Since Jul 23, 2026.

Dominant language
TypeScript
Stars
209k
Forks
27.5k
PR merge metrics
PR metrics pending

Description

Description

opencode attach --mini silently ignores the --agent (and --model) flags. Mini-mode sessions started against a shared server always use the server's default agent (typically "build"), with no way to select a different agent.

Root Cause

Two-part bug in packages/opencode/src/cli/cmd/attach.ts:

1. Missing yargs options

The attach subcommand's builder does not define --agent or --model, so with strict mode they're rejected as unknown options:

// Current builder — no --agent, no --model
.option("dir", { ... })
.option("continue", { ... })
.option("mini", { ... })
// ...
2. Missing parameter pass-through to runMini()

Even if args.agent / args.model were available, attach.ts does not forward them:

// Current — agent, model, prompt NOT forwarded
await runMini({
    attach: args.url,
    directory,
    password: args.password,
    username: args.username,
    continue: args.continue,
    session: args.session,
    fork: args.fork,
    replay: noReplay ? false : undefined,
    replayLimit: args.replayLimit,
})

Compare with tui.ts (the $0 default command, which handles opencode --mini) which forwards all three correctly:

// tui.ts — correct, forwards agent/model/prompt
await runMini({
    directory: ...,
    model: args.model,
    agent: args.agent,
    prompt: args.prompt,
    ...
})

Downstream consequence

  • runMini()RunCommand.handler()pickAgent(client) returns undefined (because args.agent is never set)
  • runInteractiveMode() is called with agent: undefined
  • The session runs with whatever agent the server assigned at creation time (the server's own default_agent)
  • Users cannot override it via OPENCODE_CONFIG_CONTENT either — that env var is client-side only and does not affect the server's session creation API

Related: also missing --model and --prompt

The same omission affects --model and --prompt — they are defined globally and used by tui.ts, but not forwarded from attach.ts.

Fix

File: packages/opencode/src/cli/cmd/attach.ts

1. Add options to builder (after the existing .option("replay-limit", ...) line):

.option("model", {
  type: "string",
  describe: "model to use in the format of provider/model",
})
.option("agent", {
  type: "string",
  describe: "agent to use",
})

2. Forward to runMini() (add three fields to the existing object literal):

await runMini({
    attach: args.url,
    directory,
    password: args.password,
    username: args.username,
    continue: args.continue,
    session: args.session,
    fork: args.fork,
    model: args.model,
    agent: args.agent,
    prompt: args.prompt,
    replay: noReplay ? false : undefined,
    replayLimit: args.replayLimit,
})

That's it. The downstream types (MiniCommandInput in run.ts and all handler code) already accept these fields — they just never received them from the attach path.

Impact

  • opencode attach http://localhost:4096 --mini --agent gitmaster now works
  • opencode attach http://localhost:4096 --mini --model openai/gpt-4 now works
  • No regressions: passing undefined for these fields (when omitted) is identical to current behavior

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.