Skip to content

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

Closed

Description

@Ron-RONZZ-org

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

Activity

  1. github-actions commented on Sep 23, 2026

    @github-actions
    Contributor

    To stay organized issues are automatically closed after 60 days of no activity. If the issue is still relevant please open a new one.

  2. simonklee commented on Sep 23, 2026

    @simonklee
    Member

    this issue is solved.

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

Metadata

Metadata

Assignees

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