blob: 5a8e4892dce147e000bf492f1a85d5feac829787 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
|
# Spawning OpenCode Agents via CLI
## Non-interactive (headless) run
`opencode run` streams output to stdout and exits — no TUI opens.
```bash
opencode run "your prompt here"
```
## Key flags
| Flag | Short | Purpose |
|------|-------|---------|
| `--dir` | | Working directory for the agent |
| `-m provider/model` | `--model` | Which model to use |
| `-f path/to/file` | `--file` | Attach a file to the message |
| `--agent` | | Which agent profile to use |
| `--format json` | | Raw JSON events instead of formatted text |
| `--dangerously-skip-permissions` | | Auto-approve all permissions (dangerous!) |
## Examples
### Run with a specific model and CWD
```bash
opencode run --dir /path/to/project -m opencode-go/qwen3.7-max "your prompt"
```
### Attach a file as context
```bash
opencode run --dir /path/to/project -m opencode-go/qwen3.7-max -f prompt.md "follow the instructions in the attached file"
```
### Pipe file content as the prompt itself
```bash
opencode run --dir /path/to/project -m opencode-go/qwen3.7-max "$(cat prompt.md)"
```
### Use a specific agent profile
```bash
opencode run --dir /path/to/project --agent my-agent -f prompt.md "do it"
```
### JSON output for scripting
```bash
opencode run --dir /path/to/project -m opencode-go/qwen3.7-max -f prompt.md "do it" --format json
```
## API key configuration
- **Env var:** `ANTHROPIC_API_KEY=sk-... opencode run ...` (provider-specific)
- **Persisted:** `opencode auth login --provider anthropic`
- **Project `.env`:** opencode reads `.env` on startup
## Listing available agents
```bash
opencode agent list
```
|