To run local LLMs for coding, install Ollama (or LM Studio, or llama.cpp), download an open-weight coding model that fits in your GPU memory, raise the context length to at least 64k tokens, and point your coding agent at http://localhost:11434. Your code never leaves your machine, and there is no per-token bill.
The context step is the one people miss. Ollama’s default is often 4k tokens, too small for an agent, which then forgets your instructions halfway through a task.
What it looks like
On a machine with a 24 GB GPU:
ollama pull qwen3.8:27b
ollama launch claude --model qwen3.8:27b
The second line starts Claude Code with the local model instead of Anthropic’s. You give it a task as usual; every request goes to your GPU. Set the context length first, as shown below, or the agent will run out of room.
What hardware do I need?
Two numbers decide a local setup: capacity (GB), which sets what loads at all, and bandwidth (GB/s), which sets how fast it runs. The model’s weights plus the KV cache for your context must fit in GPU memory — or in unified memory on an Apple Silicon Mac — or part of it spills into system RAM, which carries ten to twenty times less bandwidth and runs that much slower.
Capacity: will it fit
A rule from Ollama’s own download sizes: a 4-bit model needs about 0.7 GB per billion parameters, plus room for the context.
| Model | Download | Context it supports |
|---|---|---|
qwen3.5:4b |
3.3 GB | 256k |
qwen3.5:9b |
6.6 GB | 256k |
qwen3.8:27b |
18 GB | 256k |
qwen3-coder:30b |
19 GB | 256k |
The context needs memory too, and a 64k context can add several gigabytes: about 2 GB for qwen3.5:9b, 4 GB for qwen3.8:27b. Roughly, by memory:
- No GPU: the model runs on the CPU at system-RAM speed, about 5 to 12 tokens a second on an 8B model. Fine to try the setup, too slow for agent work.
- 8 to 12 GB GPU:
qwen3.5:9bfor short, focused tasks. On 8 GB it only fits with a smaller or quantized context. - 16 GB GPU:
qwen3.5:9b-q8_0, the same model at 8 bits, with a full 64k context. - 24 GB GPU:
qwen3.8:27b. Usable for real agent tasks. - 48 GB or more of unified memory, or several GPUs: room for 8-bit weights, longer contexts and bigger models.
Best Ollama models for coding has the pick for each memory size, with the context memory worked out per model.
Bandwidth: how fast it runs
Generating a token reads the model’s weights out of memory once, so token speed is roughly memory bandwidth divided by the bytes read per token — not a matter of core count. That is why the load-bearing number on a card is its GB/s. For agentic coding the bar is higher than for chat: aim for 45 tokens a second or more, since 30 drags across an agent’s dozens of turns, and give a mid-difficulty task at least 68k tokens of context.
| Hardware | Memory | Bandwidth |
|---|---|---|
| RTX 5090 | 32 GB GDDR7 | ~1,792 GB/s |
| RTX 4090 | 24 GB | ~1,008 GB/s |
| Apple M3 Ultra | up to 512 GB unified | ~819 GB/s |
| Apple M4 Max | up to 128 GB unified | ~546 GB/s |
| Intel Arc Pro B60 | 24 GB | ~456 GB/s |
| Intel Arc B580 | 12 GB | ~456 GB/s |
| No GPU (dual-channel DDR5) | system RAM | ~90 GB/s |
Apple’s unified memory is the trade in the open: an M3 Ultra holds a model far larger than any consumer GPU can, at a bandwidth below a 5090’s. Intel’s Arc cards sell cheap VRAM per gigabyte but want IPEX-LLM and Linux to run well. Prices move; bandwidth and capacity don’t.
Mixture-of-experts: a 30B that can run like a 3B
A mixture-of-experts (MoE) model reads only the few experts its router picks per token, so it runs at the speed of its active size while taking memory for its full size. Qwen3-30B-A3B holds 30.5B parameters but activates about 3.3B a token: it generates roughly as fast as a dense 3B while needing the memory of a 30B. On local hardware that is often the best trade — more capability per token of latency than a dense model that fills the same card.
It also bends the capacity limit. Keep the shared layers on the GPU and push the expert weights into system RAM — llama.cpp does this with --n-cpu-moe — and a model too big for your VRAM runs anyway, slower, reading its experts from RAM instead of refusing to start. Because only some experts fire per token, they can even sit on different GPUs or hosts; a dense model resists that, since every token needs every weight. Disk offload stretches the limit further still, at a speed cost that makes it “it starts” rather than “it’s usable”.
Serving more than one person
One user is bound by bandwidth. A shared GPU (vLLM) is different: batching reads each weight once for the whole batch, which lifts total throughput — but each user’s KV cache is a second memory stream that doesn’t amortize, one per user, and the hot prefix cache only helps when users share a prompt prefix. Across separate conversations it is harder to keep warm, so a shared box needs capacity for many KV caches and the bandwidth to feed them. Run models locally covers the vLLM side.
Speed is mostly about reading the prompt
Measured: on an agent turn the slow part is often not writing the answer but reading the prompt — every turn resends the same system prompt, tool list and history. Contenox’s own research on local inference found a stable prefix of about 9,000 tokens took 1.77 s to process cold and 0.03 s when its cache was kept warm, on a laptop GPU with 6 GB; on the CPU the same prefix took 7.61 s cold against 73 ms warm. Editing anything early in the prompt changed the prefix and sent the next turn back to the full cold cost. A runner that keeps the prefix warm, and a harness that keeps it stable, can matter more than raw tokens per second. The mechanism is in what is the KV cache?
Which local model is best for coding?
For agent work, the model must support tool calling: that is how it reads files and runs commands. On ollama.com, look for the tools tag on the model page. A model without it can talk about code but can’t act on it.
Current picks, all tagged for tools: qwen3.8:27b for a 24 GB GPU, qwen3.5:9b for 12 to 16 GB, and qwen3-coder:30b if you want short turns without thinking (with a 64k context it needs more than 24 GB). Try your pick on a real task. New open-weight models come out often; best Ollama models for coding keeps the list by GPU size.
How fast open weights catch up is contested. The LinkedIn article The God Model Fallacy: Why the AI Future Looks Like 1987 claims an open-weight model matches a state-of-the-art one about six months later, at a fraction of the cost. One dated data point supports it only in part: Z.ai released the open-weight GLM-5.2 on 13 June 2026, about two weeks after Claude Opus 4.8, and its own published scores, as summarized by CodingFleet on 16 June, came within a point of Opus 4.8 on FrontierSWE and MCP Atlas but reached half its score on the long-horizon SWE-Marathon. On short tasks the gap closed faster than six months; on long agent runs it had not closed.
How do I set it up with Ollama?
-
Install Ollama from ollama.com for your OS.
-
Pull a model:
ollama pull qwen3.8:27b -
Try it directly:
ollama run qwen3.8:27b "Write a Python function that parses ISO dates" -
Check the server is up. It listens on port 11434:
curl http://localhost:11434/api/tagsThis lists the models you have pulled.
-
Raise the context length (next section).
-
Connect your agent (the section after that).
Why does my local agent forget things or stop making sense?
Almost always the context length. Ollama picks a default from your GPU memory: 4k tokens under 24 GB of VRAM, 32k from 24 to 48 GB, and 256k above that. Its own docs say agents and coding tools need at least 64k. The system prompt and tool definitions alone can fill much of 4k before the agent reads any code.
Three ways to raise it:
-
Ollama app: move the context length slider in Settings.
-
Server setting: on Windows, quit Ollama, run
setx OLLAMA_CONTEXT_LENGTH 64000in PowerShell and start Ollama again. On macOS or Linux:OLLAMA_CONTEXT_LENGTH=64000 ollama serve -
Per model, for agents that use the OpenAI-compatible endpoint, which has no context setting of its own. Create a file named
Modelfile:FROM qwen3.8:27b PARAMETER num_ctx 64000Then build a new model name and use that name in your agent:
ollama create qwen3.8-64k -f Modelfile
A bigger context uses more memory. After a change, run ollama ps while the model is loaded and check the PROCESSOR column. It should say the model runs fully on the GPU.
The full-offload trap: shrinking the context until the model reports
100% GPUlooks like the right fix and isn’t. A model fully on the GPU with an 8k window fails every agent task; the same model with a 64k window and a small CPU share is slower but works. Contenox’s own research on local inference was built on that rule: size GPU offload against the context the session asks for, not the other way round. Pick the context first, then fit as much of the model on the GPU as is left, and if the CPU share makes turns unbearable, pick a smaller model rather than a smaller window.
How do I connect Claude Code, Codex, OpenCode or another agent?
| Agent | Quickest way |
|---|---|
| Claude Code | ollama launch claude |
| Codex CLI | ollama launch codex, or codex --oss |
| OpenCode | A provider block in opencode.json |
| Any OpenAI-compatible agent | Base URL http://localhost:11434/v1/ |
| Contenox | On Windows x64 from 1.0.22, Use local AI during setup. For an existing Ollama server, Backends → Providers → Ollama / Ollama Cloud. |
Claude Code
ollama launch claude
Or set it up yourself:
export ANTHROPIC_AUTH_TOKEN=ollama
export ANTHROPIC_API_KEY=""
export ANTHROPIC_BASE_URL=http://localhost:11434
claude --model qwen3.8:27b
In PowerShell on Windows:
$env:ANTHROPIC_AUTH_TOKEN = "ollama"
$env:ANTHROPIC_API_KEY = ""
$env:ANTHROPIC_BASE_URL = "http://localhost:11434"
claude --model qwen3.8:27b
Codex
ollama launch codex
Or: codex --oss -m qwen3.8:27b
OpenCode
Add Ollama as a provider in opencode.json in your project, or in ~/.config/opencode/opencode.json:
{
"$schema": "https://opencode.ai/config.json",
"provider": {
"ollama": {
"npm": "@ai-sdk/openai-compatible",
"name": "Ollama (local)",
"options": { "baseURL": "http://localhost:11434/v1" },
"models": {
"qwen3.8:27b": { "name": "Qwen3.8 27B" }
}
}
}
}
Then pick the model with /models in OpenCode. Use the name of the 64k model you created above if you made one. OpenCode with local models covers this setup in detail.
Any agent with an OpenAI-compatible setting: base URL http://localhost:11434/v1/. The agent may insist on an API key; any value works, since Ollama ignores it locally.
Contenox includes local inference in Windows x64 builds from 1.0.22. Choose Use local AI → Detect my hardware, select a chat model, then Download and use. In an app you have already set up, open Backends → Providers → Local AI → Manage models. See local setup and model management.
To use the Ollama server configured above, open Backends → Providers, choose Ollama / Ollama Cloud, keep the address http://127.0.0.1:11434 and select Connect. Your pulled models then appear in the Model chip, next to any cloud providers you connected, so you can switch per session. See Ollama in Contenox.
Is a local model good enough?
For a direct comparison with hosted inference, see local AI vs cloud AI for coding. If your setup is working but slow, measure loading, prompt processing and generation separately.
For some work, yes. Be honest about the rest.
Where local models do well: focused, clearly described tasks. Writing tests for a given function, small refactors, explaining a module, boilerplate.
Where they fall short of the top hosted models:
- Long tasks. Smaller models lose track of instructions over many turns.
- Tool calls. More malformed or repeated calls.
- Hard debugging across many files. This is where the gap is largest.
The hardware is not free either: a GPU with enough memory is a real purchase, and it usually runs slower than a hosted model. Run local models because of privacy, offline work or very high volume, not to save money on light use.
A practical split: a local model for routine and private work, a hosted one for the hardest problems. See how to choose a model for coding.
Where should you run it?
For agentic coding, Contenox’s own research comes down against the laptop. A laptop GPU rarely holds a capable model together with a 68k context, and neither a laptop GPU nor its CPU has the bandwidth for 45 tokens a second across a long session — and a model running flat out for hours throttles the machine you are working on. Unless the laptop is really a workstation, the setups that keep up are a desktop with a full-size GPU, a dedicated GPU node on your network that holds the model resident and serves it to your editor, or a cloud GPU rented by the hour. Reach for one of those when a hosted model or a frontier lab is off the table — for privacy, compliance, offline work or high volume — and skip local entirely when it is not, since a hosted model is simpler and faster.
A ladder, not a switch: “local” covers more than a laptop. Shouldn’t AI Move From Cloud to Local Compute? lays it out as rungs: a laptop for small models, a workstation for serious local work, a rented GPU box for heavier jobs, a shared node for a team, and a frontier model in the cloud when the task needs it. The hardware at the desk end of that ladder has grown: NVIDIA’s DGX Spark, per NVIDIA in June 2026, has 128 GB of unified memory and runs models up to 200 billion parameters. The post’s argument for climbing the ladder at all is that hosted access can change overnight with price, policy or region, and “dependency without control is fragile”. Its comment thread adds the missing step: setting up a local model still needs to become a one-click install.
Other ways to run models locally
- LM Studio: a desktop app with a model browser and a local server mode. Good if you prefer clicking to typing commands.
- llama.cpp: the engine underneath many local tools. Its
llama-servergives you more control over every setting. - vLLM: for a shared GPU server that several people use at once.
Related guides
- How to choose a model for coding: test a local model against hosted ones on your own tasks
- AI coding costs: when local is actually cheaper
- How to keep secrets away from AI agents: local models help, but the agent can still read your files
- Best Ollama models for coding: the pick for each GPU size
- Best Ollama harness: which agent works best with small local models
- What is an AI coding agent?