opencode icon indicating copy to clipboard operation
opencode copied to clipboard

Fix: Add --attach flag to opencode run (Fixes #3188)

Open monke-yo opened this issue 3 weeks ago • 2 comments

Add --attach flag to opencode run

Fixes #3188

Changes

Added --attach <url> option to opencode run that connects to a running opencode serve instance via the SDK client, avoiding MCP server cold boot times on every invocation.

Modified files:

  • run.ts - Added attach mode that uses createOpencodeClient() to connect to remote server instead of bootstrap(). Subscribes to SSE event stream and processes events identically to local mode.
  • cli.mdx - Added --attach flag documentation with usage example.

Usage:

# Terminal 1
opencode serve

# Terminal 2
opencode run --attach http://localhost:4096 "Explain closures"

All existing flags (--model, --agent, --file, --command, --continue, --session, --share, --format, --title) work with --attach. Output format is identical to local execution.

monke-yo avatar Nov 04 '25 11:11 monke-yo

I think ideally we wouldn't need to duplicate so much logic

rekram1-node avatar Nov 04 '25 14:11 rekram1-node

@rekram1-node reused some logic, check again

monke-yo avatar Nov 04 '25 15:11 monke-yo