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
Description
opencode attach --minisilently 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
attachsubcommand's builder does not define--agentor--model, so with strict mode they're rejected as unknown options:2. Missing parameter pass-through to
runMini()Even if
args.agent/args.modelwere available,attach.tsdoes not forward them:Compare with
tui.ts(the$0default command, which handlesopencode --mini) which forwards all three correctly:Downstream consequence
runMini()→RunCommand.handler()→pickAgent(client)returnsundefined(becauseargs.agentis never set)runInteractiveMode()is called withagent: undefineddefault_agent)OPENCODE_CONFIG_CONTENTeither — that env var is client-side only and does not affect the server's session creation APIRelated: also missing
--modeland--promptThe same omission affects
--modeland--prompt— they are defined globally and used bytui.ts, but not forwarded fromattach.ts.Fix
File:
packages/opencode/src/cli/cmd/attach.ts1. Add options to builder (after the existing
.option("replay-limit", ...)line):2. Forward to
runMini()(add three fields to the existing object literal):That's it. The downstream types (
MiniCommandInputinrun.tsand all handler code) already accept these fields — they just never received them from the attach path.Impact
opencode attach http://localhost:4096 --mini --agent gitmasternow worksopencode attach http://localhost:4096 --mini --model openai/gpt-4now worksundefinedfor these fields (when omitted) is identical to current behavior