Practical guides
How to run a coding model locally with Ollama
Install Ollama on macOS, Linux or Windows, pick a model suited to code, set the context window and connect OpenCode or Cline, according to the official documentation.
Ollama downloads and runs language models on your machine, then serves them through a local API at http://localhost:11434. A coding agent can connect to it and work without sending your code to an API provider. This guide follows Ollama's documentation, verified on 2026-10-20; hardware limits are covered at the end.
Install Ollama
macOS: macOS Sonoma (v14) or newer. Apple M-series chips are supported on CPU and GPU, Intel Macs on CPU only (Ollama). The preferred method is to mount ollama.dmg and drag the app into the Applications folder; on startup, it offers to link the ollama command in /usr/local/bin. The download page also offers the command-line install, the same as on Linux.
Linux (Ollama):
curl -fsSL https://ollama.com/install.sh | sh
Windows: Windows 10 22H2 or newer, Home or Pro. The install does not need Administrator rights, goes into your home directory and takes at least 4 GB (Ollama). From PowerShell, per the download page:
irm https://ollama.com/install.ps1 | iex
Then check that the command responds:
ollama -v
Plan for disk space: models range from tens to hundreds of gigabytes according to Ollama. On Windows, the OLLAMA_MODELS variable lets you store them outside your home directory.
Choose a model suited to code
Ollama's library includes code-specialised families. Two common examples, with figures from their official pages:
- qwen3-coder (Alibaba): the
30bversion weighs 19 GB, has 30 billion parameters of which 3.3 billion are active (a mixture-of-experts architecture) and accepts 256,000 tokens of context. The480bversion weighs 290 GB and needs at least 250 GB of memory, or unified memory, to run locally (Ollama). - qwen2.5-coder: six sizes, from
0.5b(398 MB) to32b(20 GB), all with a 32,000-token context window (Ollama).
To download and run qwen3-coder 30B, the command from its official page:
ollama run qwen3-coder:30b
Models that can call tools, which an agent needs, can be filtered in the library. A model page does not always state the memory required: compare the file size with your graphics card's memory, or a Mac's unified memory.
Set the context window
This is the setting that matters most for an agent. By default, Ollama picks the context window based on available video memory (VRAM) (Ollama):
- under 24 GiB of VRAM: 4,000 tokens;
- 24 to 48 GiB: 32,000 tokens;
- 48 GiB or more: 256,000 tokens.
Ollama recommends at least 64,000 tokens for agents and coding tools. Set it with the slider in the app's settings, or when starting the server:
OLLAMA_CONTEXT_LENGTH=64000 ollama serve
A larger context uses more memory. Check where the model runs: the PROCESSOR column should read 100% GPU; a value such as 48%/52% CPU/GPU means part of the model spilled into system memory, which Ollama advises avoiding for best performance.
ollama ps
Connect a coding agent
**The simplest way: ollama launch.** From your project directory, Ollama configures and starts the chosen agent, and offers to install it if needed (Ollama):
ollama launch opencode
The same command exists for Claude Code (ollama launch claude) and for Codex CLI (ollama launch codex, once Codex CLI is installed). Then pick a model from the list.
OpenCode, manual setup (Ollama). OpenCode requires a context window of 64,000 tokens or more, so models limited to 32,000 tokens, such as qwen2.5-coder, are not enough. Install:
curl -fsSL https://opencode.ai/install | bash
npm install -g opencode-ai
Then declare Ollama as a provider in opencode.json (official example, with the qwen3.5 model):
{
"$schema": "https://opencode.ai/config.json",
"provider": {
"ollama": {
"npm": "@ai-sdk/openai-compatible",
"name": "Ollama",
"options": {
"baseURL": "http://localhost:11434/v1"
},
"models": {
"qwen3.5": {
"name": "qwen3.5"
}
}
}
}
}
Then run opencode. Note: ollama launch opencode does not overwrite ~/.config/opencode/opencode.json.
Cline, in your IDE (Ollama):
- Open Cline settings,
API Configurationsection, and setAPI ProvidertoOllama. - Select a model under
Model, or type its name. - Raise the context window to at least 32,000 tokens under
Context Window.
What about Continue? Its GitHub repository says it is no longer maintained and is going read-only (see our article on open-source coding agents on GitHub). Aider, another open-source agent, also accepts a local model according to its tool page.
Hardware limits
- NVIDIA cards: compute capability 5.0 or higher and driver 550 or newer; cards with compute capability 5.0 to 6.2 need driver 570 (Ollama). On Windows, NVIDIA driver 551.61 or newer.
- AMD cards on Windows: ROCm v7 / HIP7 stack, or a Vulkan-capable Radeon driver; Vulkan is the recommended fallback for some RX 6000 cards.
- Mac: GPU acceleration on Apple M-series chips only; an Intel Mac runs on CPU.
- Memory: for best performance, Ollama advises keeping the model, context included, from spilling out of graphics memory onto the CPU. Under 24 GiB of VRAM, the default window (4,000 tokens) is too short for an agent: you need to raise it, at the cost of more memory.
- Disk: allow several tens of gigabytes per mid-sized model (19 GB for qwen3-coder 30B).
A local model costs nothing per use, but its results do not compare directly with frontier models: see the model comparison for vendor-published scores.
Going further
- Compatible agents: OpenCode, Cline, Aider; the OpenCode, Aider and Cline comparison and the Cline vs OpenCode head-to-head.
- Open-weight models: Open-source models tool page and open weights vs open source in the glossary.
- The cost of the other options: Choosing a coding agent by budget.
Sources
- Ollama Docs: Quickstart, verified 2026-10-20
- Ollama Docs: Linux, macOS and Windows, verified 2026-10-20
- Ollama: download (install commands), verified 2026-10-20
- Ollama Docs: Context length, verified 2026-10-20
- Ollama Docs: Hardware support, verified 2026-10-20
- Ollama Docs: OpenCode and Cline, verified 2026-10-20
- Ollama: qwen3-coder and qwen2.5-coder, verified 2026-10-20
Key takeaway: Ollama installs with one command, but a coding agent needs at least 64,000 tokens of context according to Ollama, which the default settings only provide from 48 GiB of video memory.
Spotted an error in this article? Report it · Our corrections policy