14 min read July 14, 2026

OpenCode Ollama Setup: Run a Local Coding Agent Step by Step

Connect OpenCode to local or Ollama Cloud models without confusing the coding interface, model runtime, context window, and repository permissions.

Odysseus AI Wiki
Odysseus AI Wiki
Fan-made technical guidance for Odysseus AI, Ollama, OpenCode, and private local coding workflows.

Short answer: Install OpenCode and Ollama, open the repository you want to inspect, then run ollama launch opencode. The launcher can select a model, prepare the integration, set a coding-friendly context window, and start OpenCode. Use manual opencode.json configuration when you need explicit provider, model, or endpoint control.

OpenCode with Ollama is a practical local coding-agent stack: OpenCode handles the terminal interface and agent workflow, while Ollama serves the model. The fastest supported path is ollama launch opencode, but a dependable setup still requires enough context, a model that fits your hardware, a clear working directory, and conservative command permissions. This guide separates those layers so you can diagnose the right problem instead of reinstalling everything.

Quick start: launch OpenCode through Ollama

Confirm that both applications are installed and that ollama list works. In a terminal, change into the repository you want OpenCode to see. Run ollama launch opencode and choose a suitable local or cloud model.

The launcher is the best first attempt because Ollama documents it as the direct integration path. It pulls a required model when needed, configures the integration, prepares a 64K context setting for coding work, and launches OpenCode.


What each layer does before you configure it

OpenCode is the coding agent and terminal interface. Ollama is the model runtime or cloud-model gateway. Your repository remains a separate trust boundary: the model can propose changes, but OpenCode permissions determine whether commands and edits can run.

Start inside a small test repository. Keep Git clean, create a backup or branch, and avoid granting broad shell access until read-only inspection and a simple patch work correctly.


What ollama launch changes for OpenCode

The interactive ollama launch menu lists supported coding integrations and their suggested models. Selecting OpenCode prepares the connection so the interface can send repository context and prompts to an Ollama-backed model.

A successful launch does not prove that every model fits your machine. Local inference consumes RAM or VRAM and context cache; cloud models reduce local hardware pressure but require internet access and send prompts to the selected remote service.


Manual opencode.json configuration

Use manual configuration when the launcher cannot find your model, you need a non-default endpoint, or you want the provider definition committed as a reviewed project setting. OpenCode documents an Ollama provider using the OpenAI-compatible adapter and the local v1 endpoint.

Replace the example model ID with a model already shown by ollama list. Keep the model identifier identical in the provider model key and name so selection is predictable.

{
  "$schema": "https://opencode.ai/config.json",
  "provider": {
    "ollama": {
      "npm": "@ai-sdk/openai-compatible",
      "name": "Ollama (local)",
      "options": { "baseURL": "http://localhost:11434/v1" },
      "models": { "your-model": { "name": "your-model" } }
    }
  }
}

Set enough context for repository work

OpenCode documentation warns that a small Ollama context window can produce poor tool behavior or out-of-memory errors. Ollama recommends at least 64K tokens for coding tools and agents.

The launcher handles this automatically for supported integrations. For a manual model, create a Modelfile with a larger num_ctx value, build a named variant, and reference that variant in OpenCode. Reduce context only when your hardware cannot sustain it, then limit the files and task scope.

FROM your-model
PARAMETER num_ctx 65536

Choose a model by workload, not by leaderboard

The correct model is the one that stays responsive after the editor, repository index, terminal, tests, and context cache are loaded. Begin with a smaller coding-capable model, test a real patch, and move upward only when quality gains justify slower responses or memory pressure.

Cloud models available through Ollama can handle larger tasks without consuming local model memory, but they change the privacy and connectivity tradeoff. Treat the choice as a deployment decision, not only a benchmark score.

Situation Best first choice Reason
Limited RAM or integrated graphics Smaller local coding model Leaves headroom for context, editor, and tests
Strong GPU or ample unified memory Larger local coding model Better reasoning may be practical when latency stays acceptable
Large repository or difficult refactor Ollama cloud model Avoids local model memory limits; requires internet
Sensitive repository Local model with narrow permissions Keeps inference local and reduces command risk

Troubleshoot the connection in the right order

If OpenCode shows no Ollama models, first confirm that the Ollama service is running and ollama list returns the expected model. Then verify that the manual base URL is http://localhost:11434/v1 and that the model key exactly matches the installed tag.

If responses stop during repository analysis, reduce the selected files, close memory-heavy applications, or test a smaller model. If tool calls are malformed, increase context and use a model suited to coding-agent workflows. If commands fail, inspect OpenCode permissions and the working directory rather than changing the endpoint.


Use a safe first coding task

Ask OpenCode to explain the repository and propose a plan before allowing edits. Review the file list, then permit one bounded change and run a specific test. Inspect git diff before accepting more work.

Do not expose the Ollama endpoint publicly without authentication and network controls. Do not paste secrets into prompts. Local inference improves data control, but the agent can still read files and run commands that its interface is allowed to access.

OpenCode Ollama FAQ

Install both tools, open your repository in a terminal, and run ollama launch opencode. Choose a model and let the launcher prepare the integration. Use opencode.json only when you need manual endpoint or model control.

Check that Ollama is running, confirm the exact tag with ollama list, and make sure the provider model key matches it. For manual setup, verify http://localhost:11434/v1 as the base URL.

It can work offline with a model already downloaded locally. Ollama Cloud models and any package installation, web search, or remote repository operation still require internet access.

Ollama and OpenCode guidance recommends at least a 64K context window for coding tools. If your hardware cannot support that comfortably, use a smaller model and narrower repository scope.

OpenCode and local Ollama usage can run with open-source software and local models, but hardware and electricity still have costs. Cloud models may have separate account, quota, or pricing terms.

Official setup sources

  1. Ollama OpenCode integration - Official quick launch, manual provider configuration, and context guidance.
  2. Ollama launch announcement - Official launcher behavior and supported coding integrations.
  3. OpenCode Ollama provider docs - Official provider configuration and troubleshooting.
  4. Ollama context length docs - Official context sizing guidance for coding tools and agents.

Related local AI guides

Last updated: July 14, 2026

Back to Odysseus AI Wiki