OpenCode
Run opencode against your own endpoint (vLLM, llama.cpp, Ollama, a LiteLLM or llama-swap gateway) with a declared provider, safe key handling, correct model limits and capability flags, and a verified endpoint.
Scope: the OpenCode CLI/TUI and its config. Two config generations exist: OpenCode 1 (latest GitHub release v1.19.0 at write time; provider key, npm package names) and OpenCode 2 (providers key, package names, local auto-discovery). Detect which is installed before editing.
Work through the steps in order. Load a reference only when a step names it.
Discover first
Read-only. Never print keys.
command -v opencode && opencode --version
ls -l ~/.config/opencode/opencode.json* opencode.json* 2>/dev/null
jq -r '(.provider // .providers // {}) | keys | join(", ")' ~/.config/opencode/opencode.json 2>/dev/null
opencode auth list # provider names only, from ~/.local/share/opencode/auth.json
env | grep -E '^(OPENCODE|OPENAI|ANTHROPIC|LITELLM)_' | sed -E 's/=.*/=<set>/'
A top-level provider object means v1 config; providers means v2.
Decision flow
- OpenAI-compatible endpoint (chat completions) (vLLM, llama.cpp, Ollama, llama-swap, LiteLLM): v1
@ai-sdk/openai-compatible provider. -> references/custom-providers.md
- Endpoint serves Responses, or Anthropic Messages:
@ai-sdk/openai or @ai-sdk/anthropic. -> references/custom-providers.md
- OpenCode 2 installed: ->
references/opencode-2.md
- Limits, capability flags, small model, reasoning, images: ->
references/models-and-limits.md
- Tool calls, streaming, timeouts misbehave: ->
references/compatibility.md
- Install, upgrade, storage, logs: ->
references/install-and-update.md
- Error text: ->
references/troubleshooting.md
Rules
- Ask before changing the system. Installs, editing
opencode.json, shell profile exports and exposing a gateway need approval and an undo path (copy the file first).
- Secrets never touch output or git. Use
"apiKey": "{env:NAME}" or "{file:~/.secrets/key}", or /connect (stores in ~/.local/share/opencode/auth.json). Never paste a key into a committed opencode.json. Check by name with opencode auth list or [ -n "${NAME:-}" ].
- Pick the package by wire format.
@ai-sdk/openai-compatible = /v1/chat/completions; @ai-sdk/openai = /v1/responses; @ai-sdk/anthropic = /v1/messages. Model IDs must equal what GET /v1/models returns.
- Declare limits and capabilities. Custom models need
limit.context and limit.output (both required by the schema); set tool_call, reasoning, attachment, modalities truthfully.
- Provider ID consistency. The ID used with
/connect must equal the key in opencode.json.
- Test the endpoint first.
scripts/check-endpoint.sh before blaming OpenCode.
- Verify upstream. Fields and defaults come from opencode.ai docs and the JSON schema read on the writing date.
Workflows
Connect to a self-hosted endpoint
Tools or context misbehave
Reference index
| File |
Read when |
references/custom-providers.md |
v1 provider blocks, keys, headers, timeouts, per-engine setup |
references/models-and-limits.md |
Limits, capability flags, variants, small_model, compaction |
references/compatibility.md |
Tools, streaming, reasoning fields, engine caveats |
references/opencode-2.md |
OpenCode 2 providers config and local discovery |
references/install-and-update.md |
Install paths, upgrade, v1/v2 conflict, storage, logs |
references/troubleshooting.md |
Symptom to cause to fix |
references/combos/litellm-gateway.md |
LiteLLM in front of local engines |
Templates: templates/opencode.json (v1), templates/opencode-v2.jsonc. Script: scripts/check-endpoint.sh (probes a chat-completions endpoint, prints status codes only).
Companion skills
Install any with npx skills add ScaleDockHQ/llm-skills --skill <name>.
litellm, llm-gateway: gateway to bridge and manage endpoints.
vllm, llama-cpp, ollama, llama-swap: the endpoints OpenCode talks to.
tool-calling-parsers: make tool calls parse on the engine side.
llm-clients: other clients (IDEs, chat UIs, SDKs).
1---2name: opencode3description: OpenCode, the open-source terminal coding agent (anomalyco/opencode, formerly sst), pointed at self-hosted or gateway models through custom OpenAI-compatible or Anthropic-compatible providers. Use to install or upgrade `opencode`, write opencode.json provider blocks (baseURL, apiKey {env:}, models limit, tool_call) for vLLM, llama.cpp, Ollama, LiteLLM or llama-swap, handle keys, v1 vs v2 config, fix tool calls, context, image paste. Not Claude Code, Codex, Aider.4license: MIT5compatibility: Needs bash, curl and jq for the check script, and an endpoint serving OpenAI chat completions, Responses or Anthropic messages. Installs, upgrades, config edits and exposing a gateway need the user's explicit approval.6metadata:7 source: https://skillmd.com/skills/scaledockhq/opencode8 author: ScaleDockHQ9 version: "0.1.0"10---1112# OpenCode1314Run `opencode` against your own endpoint (vLLM, llama.cpp, Ollama, a LiteLLM or llama-swap gateway) with a declared provider, safe key handling, correct model limits and capability flags, and a verified endpoint.1516**Scope:** the OpenCode CLI/TUI and its config. Two config generations exist: OpenCode 1 (latest GitHub release v1.19.0 at write time; `provider` key, `npm` package names) and OpenCode 2 (`providers` key, `package` names, local auto-discovery). Detect which is installed before editing.1718Work through the steps in order. Load a reference only when a step names it.1920## Discover first2122Read-only. Never print keys.2324```bash25command -v opencode && opencode --version26ls -l ~/.config/opencode/opencode.json* opencode.json* 2>/dev/null27jq -r '(.provider // .providers // {}) | keys | join(", ")' ~/.config/opencode/opencode.json 2>/dev/null28opencode auth list # provider names only, from ~/.local/share/opencode/auth.json29env | grep -E '^(OPENCODE|OPENAI|ANTHROPIC|LITELLM)_' | sed -E 's/=.*/=<set>/'30```3132A top-level `provider` object means v1 config; `providers` means v2.3334## Decision flow35361. **OpenAI-compatible endpoint (chat completions)** (vLLM, llama.cpp, Ollama, llama-swap, LiteLLM): v1 `@ai-sdk/openai-compatible` provider. -> `references/custom-providers.md`372. **Endpoint serves Responses, or Anthropic Messages:** `@ai-sdk/openai` or `@ai-sdk/anthropic`. -> `references/custom-providers.md`383. **OpenCode 2 installed:** -> `references/opencode-2.md`394. **Limits, capability flags, small model, reasoning, images:** -> `references/models-and-limits.md`405. **Tool calls, streaming, timeouts misbehave:** -> `references/compatibility.md`416. **Install, upgrade, storage, logs:** -> `references/install-and-update.md`427. **Error text:** -> `references/troubleshooting.md`4344## Rules4546- **Ask before changing the system.** Installs, editing `opencode.json`, shell profile exports and exposing a gateway need approval and an undo path (copy the file first).47- **Secrets never touch output or git.** Use `"apiKey": "{env:NAME}"` or `"{file:~/.secrets/key}"`, or `/connect` (stores in `~/.local/share/opencode/auth.json`). Never paste a key into a committed `opencode.json`. Check by name with `opencode auth list` or `[ -n "${NAME:-}" ]`.48- **Pick the package by wire format.** `@ai-sdk/openai-compatible` = `/v1/chat/completions`; `@ai-sdk/openai` = `/v1/responses`; `@ai-sdk/anthropic` = `/v1/messages`. Model IDs must equal what `GET /v1/models` returns.49- **Declare limits and capabilities.** Custom models need `limit.context` and `limit.output` (both required by the schema); set `tool_call`, `reasoning`, `attachment`, `modalities` truthfully.50- **Provider ID consistency.** The ID used with `/connect` must equal the key in `opencode.json`.51- **Test the endpoint first.** `scripts/check-endpoint.sh` before blaming OpenCode.52- **Verify upstream.** Fields and defaults come from opencode.ai docs and the JSON schema read on the writing date.5354## Workflows5556### Connect to a self-hosted endpoint5758- [ ] Run discovery; back up the config file.59- [ ] `OPENCODE_BASE_URL=http://HOST:PORT/v1 OPENCODE_MODEL=<served-name> scripts/check-endpoint.sh` returns ok for models, plain, stream and tools.60- [ ] Put the key in `0600` file or env var; add the provider block from `templates/opencode.json`.61- [ ] `opencode models` lists `<provider>/<model>`; `opencode run -m <provider>/<model> "say ok"`; then one real edit in the TUI.6263### Tools or context misbehave6465- [ ] Tool calls not executing: engine parser/template first, then `tool_call: true`. -> `references/compatibility.md`66- [ ] Window mismatch or compaction late: fix `limit.context` and the server's window. -> `references/models-and-limits.md`6768## Reference index6970| File | Read when |71| -------------------------------------- | ------------------------------------------------------------- |72| `references/custom-providers.md` | v1 provider blocks, keys, headers, timeouts, per-engine setup |73| `references/models-and-limits.md` | Limits, capability flags, variants, small_model, compaction |74| `references/compatibility.md` | Tools, streaming, reasoning fields, engine caveats |75| `references/opencode-2.md` | OpenCode 2 `providers` config and local discovery |76| `references/install-and-update.md` | Install paths, upgrade, v1/v2 conflict, storage, logs |77| `references/troubleshooting.md` | Symptom to cause to fix |78| `references/combos/litellm-gateway.md` | LiteLLM in front of local engines |7980Templates: `templates/opencode.json` (v1), `templates/opencode-v2.jsonc`. Script: `scripts/check-endpoint.sh` (probes a chat-completions endpoint, prints status codes only).8182## Companion skills8384Install any with `npx skills add ScaleDockHQ/llm-skills --skill <name>`.8586- `litellm`, `llm-gateway`: gateway to bridge and manage endpoints.87- `vllm`, `llama-cpp`, `ollama`, `llama-swap`: the endpoints OpenCode talks to.88- `tool-calling-parsers`: make tool calls parse on the engine side.89- `llm-clients`: other clients (IDEs, chat UIs, SDKs).