This post goes over how to set up OpenCode with Ollama.
Prerequisites
brew install opencode
brew install ollama
Ollama
Start Ollama:
ollama serve
Ollama by default uses a context window size of 4096 tokens. For tasks that require large context like web search, agents, and coding tools, set the context window to at least 64000 tokens:
OLLAMA_CONTEXT_LENGTH=64000 ollama serve
Install qwen2.5-coder:
ollama pull qwen2.5-coder:latest
OpenCode
Open OpenCode > ⌘P > Settings (⌘,) > Providers > Custom provider > + Connect.
Fill out the custom provider fields:
- Provider ID:
ollama - Display name:
Ollama - Base URL:
http://localhost:11434/v1 - Model ID:
qwen2.5-coder:latest - Model Display Name:
Qwen2.5 Coder
Click Submit.
To delete a manually configured model, edit the global config
~/.config/opencode/opencode.jsonc.
Ollama is connected and the model is ready for use!