74 lines
1.9 KiB
Markdown
74 lines
1.9 KiB
Markdown
# OpenCode CLI — Detailed Integration Guide
|
|
|
|
[OpenCode](https://opencode.ai) is a provider-agnostic, open-source AI coding agent. This reference covers binary resolution, session management, and key pitfalls.
|
|
|
|
## Binary Resolution
|
|
|
|
Shell environments may resolve different OpenCode binaries. Check:
|
|
|
|
```bash
|
|
terminal(command="which -a opencode")
|
|
terminal(command="opencode --version")
|
|
```
|
|
|
|
If needed, pin an explicit binary path: `$HOME/.opencode/bin/opencode run '...'`
|
|
|
|
## Interactive Sessions (Background)
|
|
|
|
```bash
|
|
# Start TUI in background
|
|
terminal(command="opencode", workdir="~/project", background=true, pty=true)
|
|
|
|
# Send a prompt
|
|
process(action="submit", session_id="<id>", data="Implement OAuth refresh flow")
|
|
|
|
# Monitor
|
|
process(action="log", session_id="<id>")
|
|
|
|
# Exit — use Ctrl+C, NOT /exit
|
|
process(action="write", session_id="<id>", data="\x03")
|
|
```
|
|
|
|
**Important:** Do NOT use `/exit` — it opens an agent selector instead. Use Ctrl+C (`\x03`) or `process(action="kill")`.
|
|
|
|
## TUI Keybindings
|
|
|
|
| Key | Action |
|
|
|-----|--------|
|
|
| Enter | Submit message |
|
|
| Tab | Switch between agents |
|
|
| Ctrl+P | Command palette |
|
|
| Ctrl+X L | Switch session |
|
|
| Ctrl+X M | Switch model |
|
|
| Ctrl+X N | New session |
|
|
| Ctrl+C | Exit |
|
|
|
|
## PR Review
|
|
|
|
```bash
|
|
terminal(command="opencode pr 42", workdir="~/project", pty=true)
|
|
```
|
|
|
|
Or review in a temporary clone for isolation.
|
|
|
|
## Session & Cost Management
|
|
|
|
```bash
|
|
opencode session list
|
|
opencode stats
|
|
opencode stats --days 7 --models anthropic/claude-sonnet-4
|
|
```
|
|
|
|
## Common Flags
|
|
|
|
| Flag | Use |
|
|
|------|-----|
|
|
| `run 'prompt'` | One-shot execution and exit |
|
|
| `-c` / `--continue` | Continue last session |
|
|
| `-s <id>` | Continue a specific session |
|
|
| `--agent <name>` | Choose agent (build or plan) |
|
|
| `--model provider/model` | Force specific model |
|
|
| `--thinking` | Show model thinking blocks |
|
|
| `--format json` | Machine-readable output |
|
|
| `-f <path>` | Attach file(s) to the message |
|