---
title: OpenCode
description: Use OpenKnowledge with OpenCode — including fully local models via Ollama, LM Studio, or any OpenAI-compatible endpoint.
icon: custom/OpenCode
---

OpenKnowledge plugs into [OpenCode](https://opencode.ai) through MCP. OpenCode is a terminal-based coding agent that works with any model — cloud or fully local — so you can run an entirely local edit-your-knowledge-base loop.

## Install

<McpInstall editor="OpenCode" />

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. OpenCode also picks up the OpenKnowledge skill from the shared `.agents/skills/` directory 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:

<VerifyExec subject="OpenCode" />

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 couldn't parse your `opencode.json` safely and left it untouched — fix the config and re-run `ok init`.
