Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 34 additions & 1 deletion packages/opencode/src/cli/cmd/tui/attach.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { cmd } from "../cmd"
import { tui } from "./app"
import { iife } from "@/util/iife"

export const AttachCommand = cmd({
command: "attach <url>",
Expand All @@ -15,16 +16,48 @@ export const AttachCommand = cmd({
type: "string",
description: "directory to run in",
})
.option("model", {
type: "string",
alias: ["m"],
describe: "model to use in the format of provider/model",
})
.option("continue", {
alias: ["c"],
describe: "continue the last session",
type: "boolean",
})
.option("session", {
alias: ["s"],
type: "string",
describe: "session id to continue",
})
.option("prompt", {
alias: ["p"],
type: "string",
describe: "prompt to use",
})
.option("agent", {
type: "string",
describe: "agent to use",
}),
handler: async (args) => {
if (args.dir) process.chdir(args.dir)

const prompt = await iife(async () => {
const piped = !process.stdin.isTTY ? await Bun.stdin.text() : undefined
if (!args.prompt) return piped
return piped ? piped + "\n" + args.prompt : args.prompt
})

await tui({
url: args.url,
args: { sessionID: args.session },
args: {
continue: args.continue,
sessionID: args.session,
agent: args.agent,
model: args.model,
prompt,
},
})
},
})
37 changes: 37 additions & 0 deletions packages/web/src/content/docs/cli.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,43 @@ opencode agent list

---

### attach

Attach to a running opencode server with a full terminal interface.

```bash
opencode attach <url>
```

This command connects to an existing `opencode serve` or `opencode spawn` instance and provides the full TUI experience, allowing you to interact with the server as if you started opencode directly.

```bash
# Start a headless server in one terminal
opencode serve

# In another terminal, attach with the TUI
opencode attach http://localhost:4096
```

This is useful when you want to:

- Connect to a long-running opencode server
- Avoid MCP server cold boot times
- Share a server instance across multiple sessions

#### Flags

| Flag | Short | Description |
| ------------ | ----- | ------------------------------------------ |
| `--dir` | | Directory to run in |
| `--model` | `-m` | Model to use in the form of provider/model |
| `--continue` | `-c` | Continue the last session |
| `--session` | `-s` | Session ID to continue |
| `--prompt` | `-p` | Prompt to use |
| `--agent` | | Agent to use |

---

### auth

Command to manage credentials and login for providers.
Expand Down