OpenCode Locally: How to Connect Ollama and Pick a Model
How to run OpenCode with a local model through Ollama, what stays on your computer, why the agent needs a big context, and how OpenCode differs from desktop Doka.
OpenCode doesn't have to run only with cloud APIs. The agent supports local models through Ollama, so code and requests to the model can stay on your own computer. But "local OpenCode" isn't a separate build — locality depends on the provider you picked and the tools you connected. Here's the setup, without overpromising.
What OpenCode is
OpenCode is an open AI agent for development. It reads a project, changes files, and runs commands. The main interface is the terminal, and the desktop app for Windows, macOS, and Linux is still marked beta by the developers.
It's the same class of program as Claude Code and Goose, not autocomplete inside an editor. The difference between the formats is covered in more detail in the article on the AI coding agent.
What you need for a local setup
The combination has three parts:
- OpenCode manages files, commands, and the steps of a task.
- Ollama runs the model and exposes a local API on
localhost. - A code model decides which actions to take and what code to write.
Install Ollama first and download a model. You can use a local LM Studio server instead — which is more convenient for which case is covered separately. For your first test, don't pick the smallest option just because it's faster: the agent needs to understand a large chunk of the project, call tools, and not lose the goal after a few steps. There's a separate breakdown on picking a size in the article on Qwen Coder locally.
How to connect Ollama to OpenCode
Per the official provider documentation,
Ollama connects as an OpenAI-compatible local server. In opencode.json, you add a
provider with the address http://localhost:11434/v1, and under models, the
exact model name from Ollama.
After that, open the model list with /models and pick the local option. If the
model answers but doesn't call tools, or quickly forgets the start of the task,
check the context size in Ollama. OpenCode's documentation recommends starting
around 16–32 thousand tokens.
Don't copy a model name from some random guide. It has to match exactly what Ollama shows on your computer. Otherwise OpenCode will be reaching for a nonexistent ID.
What actually stays local
When OpenCode talks to Ollama on localhost, the request to the model and the
code passed to it don't go to a cloud API. The project itself and the agent's work
history also stay on your machine.
But that doesn't make external services local. Add a cloud model, web search, or a GitHub MCP server, and the corresponding data goes to their providers. A local MCP client doesn't turn cloud GitHub into a local service. Before a work project, check not just the model but the entire set of tools.
Where a local model trips up
A simple edit in one file and a multi-step migration are different kinds of load. A small model can confidently write a function and then forget to check the tests or edit the wrong file. The risk grows if the project is large, the context is short, and the agent has a lot of tools.
Start with tasks that have a checkable outcome: a failing test, a build, a linter. Ask for a plan first, review the diff, and don't give the agent access to secrets unless it needs them. The same rules apply to any AI in the terminal.
OpenCode or Doka
OpenCode is a logical pick if your main work is code and you're comfortable in the terminal. It's open, supports many providers, and fits well into a familiar CLI workflow.
Doka is a more general-purpose desktop agent. It works not just with repositories but with documents, spreadsheets, and other files; a local GGUF model can be downloaded from the interface with no separate OpenCode-plus-Ollama setup. If you specifically need a CLI, OpenCode fits the format more precisely. If you want an app for a mix of work tasks, it's simpler to start with Doka.
Where to start
Take a small repository and one task with a test. Run it on a local model, watch memory use, diff quality, and how many attempts it takes to get a passing check. That test tells you more about whether a model fits than a conversation in an empty chat.
If the local model can't handle it, you don't have to swap the whole agent: pick a bigger model, or connect a cloud API for that specific case. And if you don't need the terminal, download Doka and compare the same scenario in a desktop interface.