[PR #3889] Fix: Add --attach flag to opencode run (Fixes #3188) #10798

Closed
opened 2026-02-16 18:15:32 -05:00 by yindo · 0 comments
Owner

Original Pull Request: https://github.com/anomalyco/opencode/pull/3889

State: closed
Merged: Yes


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.

**Original Pull Request:** https://github.com/anomalyco/opencode/pull/3889 **State:** closed **Merged:** Yes --- # 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:** ```bash # 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.
yindo added the pull-request label 2026-02-16 18:15:32 -05:00
yindo closed this issue 2026-02-16 18:15:32 -05:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: anomalyco/opencode#10798