opencode
opencode copied to clipboard
Fix: Add --attach flag to opencode run (Fixes #3188)
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 ofbootstrap(). Subscribes to SSE event stream and processes events identically to local mode. - cli.mdx - Added
--attachflag 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.
I think ideally we wouldn't need to duplicate so much logic
@rekram1-node reused some logic, check again