OpenCode is an open-source coding agent that can read your project, edit files and run commands, and it can use a model running on your own PC through Ollama. With a local model there is no per-token API bill, and prompts are processed by the model on your own PC. This guide follows Ollama's and OpenCode's official documentation. Forge PC hasn't benchmarked OpenCode with different models or graphics cards, so there are no speed figures here; how well it works depends on the model you choose and how much VRAM you have.
What you need
Ollama installed and running. If you haven't set it up yet, start with our guide to running AI models locally with Ollama and LM Studio.
A model with a large context window. Ollama's OpenCode page says OpenCode requires a context length of 64k tokens or more. A bigger context uses more memory, so this is the main hardware hurdle.
A graphics card with enough VRAM for your chosen model plus that context. Our guides to how much VRAM you need and the best GPU for local LLMs cover this.
Method 1: let Ollama launch OpenCode (easiest)
Ollama has a built-in launcher for OpenCode. According to Ollama's documentation:
Open a terminal (PowerShell or Windows Terminal on Windows).
Change to your project folder, for example cd C:\code\my-project.
Run ollama launch opencode.
Pick a model when asked. Ollama starts OpenCode with an inline configuration for that model.
Ollama says ollama launch opencode doesn't overwrite your OpenCode configuration file, so any existing OpenCode settings still apply. If you only want to set up the configuration without starting a session, Ollama lists ollama launch opencode --config.
One limitation: models defined only in OpenCode's own config file won't appear in the ollama launch model picker.
Method 2: install OpenCode and let it find Ollama
You can also install OpenCode yourself. OpenCode's current documentation offers several options:
Desktop app or standalone binary: OpenCode offers downloads for Windows x64 and ARM64, as well as macOS and Linux. OpenCode notes that Windows package managers aren't supported, so on Windows use the download or npm.
npm: npm install -g @opencode/cli (you'll need Node.js installed).
Linux and macOS install script: OpenCode's docs list a curl install script.
Then:
Make sure Ollama is running and you've downloaded a model, for example with ollama pull followed by the model name.
Start OpenCode in your project folder.
Use /models to choose a model. OpenCode's providers documentation says it checks http://127.0.0.1:11434 for a running Ollama server and adds its models automatically, without an account. Embedding-only models don't appear.
If your Ollama server runs on another PC on your network, OpenCode's docs explain how to point it at that server with a baseURL setting that ends in /v1. Our guide to sharing Ollama on your local network explains the server side.
Note that Ollama's own OpenCode page still shows an older manual setup using an opencode.json provider block, while OpenCode's current docs describe automatic discovery. If one doesn't work, follow the instructions for the OpenCode version you installed.
Set the context length to at least 64k
This is the step most likely to trip you up. Ollama's documentation says its default context length depends on VRAM: 4k tokens on GPUs with less than 24GiB, 32k for 24 to 48GiB and 256k for 48GiB or more. Ollama recommends at least 64,000 tokens for agents and coding tools.
To raise it:
Ollama app: drag the context length slider in Settings.
Command line: start the server with OLLAMA_CONTEXT_LENGTH=64000 ollama serve (on Windows, set OLLAMA_CONTEXT_LENGTH as an environment variable and restart Ollama).
Then run ollama ps while OpenCode is working. Ollama says that for best performance the model should show 100% GPU under PROCESSOR. If part of it has spilled onto the CPU, responses will be much slower, so try a smaller model or a lower quantisation. Our full guide to setting the context length in Ollama goes into more detail, and you can watch memory use with our guide to checking VRAM usage in Windows.
Choosing a model
Pick a model built for code or agent work, and make sure it supports the context length you need. A longer context uses more memory, so a model that fits your VRAM at a short context may spill onto the CPU at 64k; check with ollama ps after changing it. Our best local LLM models round-up is a good starting point.
If you'd rather use a different tool, we also cover Claude Code with Ollama, Continue in VS Code and Aider.
Our verdict
The quickest way to try OpenCode locally is ollama launch opencode in your project folder. Whichever setup you use, raise Ollama's context length to at least 64k tokens and check with ollama ps that the model still runs fully on your GPU. Do that, pick a coding model that fits your VRAM, and you have a coding agent running on your own hardware with no per-token fees.