Can I run a coding agent on a local model?
Yes. Most popular coding agents accept a local endpoint, and a mid-class model on a 24 GB machine runs them. Two settings decide whether it works: the model class and the context length.
Which agents accept a local endpoint
An agent is a loop. It reads your code, asks the model what to do, runs a tool such as "edit file" or "run tests", feeds the result back, and repeats. The model is the only part that has to be smart, and you can swap it for a local one.
| Agent | Where it runs | How you point it at a local model |
|---|---|---|
| Claude Code | Terminal | Set ANTHROPIC_BASE_URL to a local server that speaks the Anthropic Messages API |
| Codex | Terminal | Its open-source mode talks to Ollama or LM Studio, or add a provider in its config file |
| OpenCode | Terminal | Add a provider with a local base URL in its config file |
| Cline | VS Code | Pick Ollama, LM Studio or "OpenAI Compatible" as the API provider in settings |
| Aider | Terminal | Pass a model name with an ollama_chat/ or openai/ prefix |
| pi | Terminal | Add a local provider to its models config |
Claude Code is the odd one out. It speaks the Anthropic API, not the OpenAI one, so the runtimeRuntimeThe software that loads a model file and runs it.Read more has to offer an Anthropic-compatible endpoint. Ollama does, and others are adding it, so check How do I call a local model from code? for what your runtime supports.
Superfluid, a server from Base Compute, speaks both formats and has a command that starts the server if none is running and opens the agent pointed at it.
superfluid launch claude --model basecompute/Qwen3.8-27BIts README lists Codex, pi, OpenCode, Hermes Agent, Cline and OpenClaw as well. On a Mac, the Local app from the same maker also edits and runs code in a project folder, without a terminal. Which tools run a model across machines? covers Superfluid and Which chat app should I use? covers Local.
The two things that break local agents
Context set too small
An agent's prompt is huge before you type a word. The system promptSystem promptStanding instructions placed before the conversation.Read more and tool definitions alone can run to 10K tokensTokenA chunk of text, usually part of a word. Models read and write in tokens.Read more. Add the files it reads and the tool output it collects, and a real task passes 30K fast.
Many runtimes default to a context of a few thousand tokens. When the prompt overflows, the runtime cuts the oldest part, which is usually the instructions. The agent then forgets what tools it has, loops or stops mid-task with no error.
Set the context to at least 32K tokens for any agent. 64K tokens is comfortable if your memory allows it.
The setting lives in the runtime, not the agent. In Ollama it is one environment variable when you start the server.
OLLAMA_CONTEXT_LENGTH=32768 ollama serveIn LM Studio it is the context length slider when you load the model. How much can the model keep in mind? explains what that memory costs.
Models that claim tool calling and do it badly
A tool callTool callingA model asking the app to run a function, such as a search or a shell command.Read more is the model writing a structured request, such as a JSON object naming a function and its arguments. Many model cards say "supports tool calling", but small models often produce calls with a wrong field name, a missing bracket or an invented tool. Each bad call wastes a turn, and a few in a row derail the task.
The runtime matters too. If it does not parse the model's tool-call format correctly, a good model looks broken. Use a recent runtime build and the model's official chat templateChat templateThe exact wrapper of tags a model expects around each message.Read more. Why does my agent forget things or fail tool calls? lists the symptoms and fixes.
Minimum model class
An agent loop holds together from 27B and up. Below that, models can write good code in a single reply but lose the thread over twenty tool calls.
| Model | Parameters | 4-bit | 8-bit | Footprint | Licence |
|---|---|---|---|---|---|
| gpt-oss-20b | 21B / 3.6B active | 13 GB* | – | Apache 2.0 | |
| Mistral Small 3.x | 24B | ~14 GB | 25 GB | Apache 2.0 | |
| Gemma 4 26B A4B | 26B / 4B active | ~16 GB | 29 GB | Apache 2.0 | |
| Qwen3.8-27B | 27B | 16 GB | 30 GB | Apache 2.0 | |
| Muse Glimmer 30B | 30B | 17 GB | 34 GB | Apache 2.0 | |
| Gemma 4 31B | 31B | 19 GB | 34 GB | Apache 2.0 |
~ means the figure is approximate. * means the model ships in its own low-precision format, so no Q8 build applies.
As of 27 Nov 2026
A mid-class model at 4-bit is about 16 to 19 GB. Add 32K of context and you need a 24 GB GPU or a Mac with 32 GB or more. Will it fit? does the sums for your machine.
Mixture-of-experts models with a small active size are fast, which agents love, but some are weaker at long tool chains than dense modelsDense modelA model where every parameter runs for every token.Read more of similar total size. Test on a real task from your own repo before you commit.
End to end walkthrough
This uses Aider and Ollama because both install in a minute and need no config file. Swap the model tag for any mid-class model from the table above.
Step 1: Start Ollama with a big enough context
OLLAMA_CONTEXT_LENGTH=32768 ollama serveLeave this running in its own terminal. If Ollama already runs as a background app, quit it first so the setting takes effect.
Step 2: Download a mid-class coder model
ollama pull qwen3-coder:30bThis is a 30B mixture-of-experts coder model, about 19 GB at 4-bit. Any tag from the mid class works.
Step 3: Install Aider and point it at Ollama
python -m pip install aider-install aider-install export OLLAMA_API_BASE=http://127.0.0.1:11434The
exportline tells Aider where Ollama listens. On Windows PowerShell, use$env:OLLAMA_API_BASE="http://127.0.0.1:11434"instead.Step 4: Run it in a git repo
cd your-project aider --model ollama_chat/qwen3-coder:30bThe
ollama_chat/prefix tells Aider to use Ollama's chat API. Ask for one small change, such as adding a test for an existing function, and watch the diff it proposes. Aider commits each change it makes, sogit logshows exactly what it did.
Read the README and the main entry file. Then list the three functions with no tests, and write a test for the simplest one.If it edits the wrong file or repeats itself, check the context first, then try a bigger model.
Honest expectations versus cloud agents
A mid-class local model does well at contained tasks. Writing tests, explaining code, small refactors and fixing a failing build in one module all work. It is slower than a cloud agent, and it gives up or loops more often on long tasks.
Frontier cloud models are still far ahead on large, multi-file changes and on judgement about what not to touch. We think the right split for most people is local for routine and private work, cloud for the hard jobs.
Speed is the cost you feel most. An agent sends long prompts on every turn, and on a laptop each turn can take tens of seconds to start. A task that takes a cloud agent two minutes can take twenty locally.
Go deeperThat's enough
Why prefill dominates agent speed
Every agent turn sends the whole conversation again, often 20K tokens or more. The model must read all of it before writing the first word. That reading step, prefill, is limited by compute, not memory bandwidthMemory bandwidthHow fast data moves out of memory, in GB per second. It sets decode speed.Read more, so a Mac that writes quickly can still pause for a long time before each turn.
Runtimes with prompt caching keep the already-read part and only process what is new. It makes a big difference for agents. How do I make it faster? covers which runtimes do this and how to turn it on.
Quantization hits agents first
Tool calls must be exact. A slight loss of precision that is invisible in chat can turn into a malformed argument once in fifty calls, and agents make hundreds. If you have the memory, try Q6 or Q8 before moving up a model class, as Which quantization should I download? explains.
Tool-call formats
Each model family wraps tool calls in its own tags or JSON layout, and the runtime translates that into the standard API format the agent expects. When the runtime's parser lags behind a new model, calls arrive as plain text and the agent ignores them. Updating the runtime fixes most of these, and How do tools and MCP work with local models? explains the full round trip.