# OpenCode CLI

OpenCode CLI offers a single CLI with multiple provider backends.

## Requirements

* `opencode` installed.
* Provider credentials (Anthropic/OpenAI/Google/etc).
* Default model configured or explicit `--model` in command.

## Setup

1. Install OpenCode CLI.
2. Set provider API keys.
3. Verify local command works.
4. Configure in **AI Backend** settings tab.

Example environment setup:

```bash
export ANTHROPIC_API_KEY="sk-ant-..."
export OPENAI_API_KEY="sk-..."
export GOOGLE_API_KEY="..."
```

## Configuration

| Setting                  | Value                                          |
| ------------------------ | ---------------------------------------------- |
| **Preferred Backend**    | `OpenCode CLI`                                 |
| **OpenCode CLI Command** | `opencode --model anthropic/claude-sonnet-4-5` |

Other model examples:

```
opencode --model openai/gpt-4o
opencode --model google/gemini-1.5-pro
```

## Notes

### Model Configuration

If no default model is configured and no `--model` is provided, embedded runs can fail with `process has not exited`.

### Output Parsing

The extension filters OpenCode CLI output to extract the actual AI response:

* **Status/metadata lines**: All lines starting with `>` (under 120 characters) are treated as OpenCode status output and filtered. This includes `> thinking`, `> loading`, `> building`, and similar status messages.
* **Prompt echo removal**: Only long prompt lines (40+ characters) are used for dedup filtering, preventing false positives where short common terms (e.g., "SQL Injection", "Analyze") would incorrectly match real response content.
* **Version banners**: Lines starting with `opencode v` or `session:` are filtered.

### Idle Timeout

OpenCode has two timeouts that can end a run:

* **Idle timeout** (`OPENCODE_IDLE_TIMEOUT_MS = 30_000`, 30 seconds): the process is force-killed if it produces no new stdout after initial status lines. Runs that take longer than 30 s to start producing output will look blank.
* **Hard CLI timeout** (120 seconds, shared with other CLI backends): an overall ceiling that terminates the process regardless of output activity.

Both are intentionally short to prevent runaway processes in the chat UI. For very large prompts, prefer a faster model or split the request.

### Windows

npm-installed CLI shims are resolved automatically on Windows. The extension detects `.cmd` siblings and uses them instead of shell script shims that cannot be executed directly by Java.

## Troubleshooting

{% hint style="info" %}

* `command not found`: use full binary/shim path.
* Windows: npm shim paths are resolved automatically. If auto-resolution fails, use the full `.cmd` path: `C:\\Users\\<you>\\AppData\\Roaming\\npm\\opencode.cmd`.
* Provider errors: verify the API key for selected provider.
* `process has not exited`: configure a default model or add `--model`.
* Blank responses: check that the model is producing output by running the same command in a terminal. If the model takes longer than 30 seconds to start producing output, the process may time out.
* Unrendered responses: ensure the response is not being filtered by the output parser. Check the extension output tab for raw process output.
  {% endhint %}

## Related Pages

* [Backends Overview](/backends/overview.md)
* [Troubleshooting](/reference/troubleshooting.md)


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://burp-ai-agent.six2dez.com/backends/opencode-cli.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
