# OpenCode (https://openknowledge.ai/docs/integrations/opencode)

Use OpenKnowledge with OpenCode.

[OpenCode](https://opencode.ai) is an open-source AI coding agent.

## Install

There are two ways to connect OpenCode, depending on how you run OpenKnowledge:

- **Desktop app** (macOS, Windows, Linux). The first time you open a project, a consent dialog detects OpenCode and configures it for you. To re-trigger the dialog, choose **File → Set up OpenKnowledge integrations…**.
- **Web app / terminal** (any platform, including Intel Macs — see the [web app guide](https://openknowledge.ai/docs/get-started/quickstart#ok-install-web-app)). Run `ok init` in your project: it registers the OpenKnowledge MCP server with OpenCode and the other editors it detects. Every `ok start` repairs the entry if it has drifted (it never adds one you removed).

OpenCode reads MCP servers from `opencode.json` in the project root, or `~/.config/opencode/opencode.json` for a global install. `ok init` writes the `open-knowledge` server under the top-level `mcp` key in both, using the same resilient launcher every other editor gets. It also installs the OpenKnowledge skill to `.opencode/skills/open-knowledge/`, which OpenCode scans automatically.

## Use a local model

OpenCode is model-agnostic and talks to any OpenAI-compatible endpoint, so you can pair OpenKnowledge with a model running entirely on your machine — no cloud round-trip. Point OpenCode at [Ollama](https://ollama.com), [LM Studio](https://lmstudio.ai), or a self-hosted server in the same `opencode.json` that holds the OpenKnowledge MCP entry:

```jsonc
{
  "$schema": "https://opencode.ai/config.json",
  // Added by `ok init` — connects OpenCode to your knowledge base.
  "mcp": {
    "open-knowledge": { "type": "local", "enabled": true, "command": ["..."] }
  },
  // Your local model, via any OpenAI-compatible endpoint (Ollama shown).
  "provider": {
    "ollama": {
      "npm": "@ai-sdk/openai-compatible",
      "options": { "baseURL": "http://localhost:11434/v1" },
      "models": { "qwen3-coder:30b": {} }
    }
  }
}
```

Pick the model in OpenCode with `/models`. **The model must support tool/function calling** — that's how it drives OpenKnowledge's `exec` / `write` / `edit` tools; a chat-only model will connect but never call them. See OpenCode's [models](https://opencode.ai/docs/models/), [providers](https://opencode.ai/docs/providers/), and [MCP servers](https://opencode.ai/docs/mcp-servers/) docs for the authoritative provider schema.

## Verify

Open the project in OpenCode and ask:

> List the first 5 documents you come across in this project.

OpenCode should call the OpenKnowledge `exec` tool and respond with some of your documents.

If OpenCode doesn't use the OpenKnowledge `exec` tool, restart it so it picks up the new MCP entry, and make sure the model you selected supports tool calling. If it's still missing and `ok init` reported your config was `left unchanged`, OpenKnowledge declined to edit your `opencode.json` for the reason shown in parentheses — an unreadable file, a duplicate `mcp` block, or a config too large to edit safely. Fix that and re-run `ok init`.