anomalyco / anomalyco/opencode
opencode attach --mini ignores --agent/--model flags
@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)returnsundefined(becauseargs.agentis never set)runInteractiveMode()is called withagent: 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_CONTENTeither — 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 gitmasternow worksopencode attach http://localhost:4096 --mini --model openai/gpt-4now works- No regressions: passing
undefinedfor these fields (when omitted) is identical to current behavior
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Assessment
This issue has not been assessed yet.