How to Run Aider with Ollama: Local AI Coding Agent
Why pair Aider with Ollama
Cloud coding agents charge per token and send your codebase to someone else's servers. Aider plus Ollama removes both costs. Aider is an open-source AI pair programmer in your terminal that edits files in your local git repo and commits each change so you can undo anything. Ollama serves the model on your own machine. Together they make a coding agent that works offline and never uploads your code.
Aider is not a chatbot with a file attachment. It maps your repository, so the model sees how files connect before editing. It proposes changes as diffs, applies them only after you confirm, and records each one as a git commit.
What you need
- Python 3.10 or newer, git, and Ollama. If Ollama is not installed yet, see How to Run an Open Model Locally with Ollama in 20 Minutes.
- A GPU with at least 12 GB of VRAM for a 14B model, or 24 GB for a 30B model. CPU-only runs work but are slow.
- A git repository. Aider tracks and commits changes and reads git history.
How the pieces fit together
Your terminal runs Aider. Aider sends prompts to Ollama on http://127.0.0.1:11434, Ollama runs the local model, and the model replies with code edits that Aider applies to your git repo and commits.
Step 1: Pull a coding model with Ollama
Code-specialized models follow edit instructions far better than general chat models. Two solid picks:
- qwen3-coder:30b, the pick for a 24 GB GPU. Mixture-of-experts: 30.5B total parameters, about 3.3B active per token, 256K context, roughly a 19 GB download.
- qwen2.5-coder:14b, the pick for a 12–16 GB GPU. Qwen's blog reported 73.7% on Aider's polyglot coding benchmark for its larger 32B sibling; the 14B keeps most of that ability in a smaller package.
ollama pull qwen3-coder:30b
On a smaller card, pull qwen2.5-coder:14b instead and use that tag below.
Step 2: Raise Ollama's context window before you start
This is the step most tutorials skip, and it decides whether the setup works at all. Ollama's own docs say coding tools and agents need at least 64,000 tokens of context. The default depends on your GPU memory: under 24 GiB you get 4K, 24–48 GiB gets 32K, and only 48 GiB and up gets 256K. With a 4K window, Aider sees only the first few files of your repo.
Set the window when you start the server:
OLLAMA_CONTEXT_LENGTH=65536 ollama serve
A larger window uses more VRAM, so check the model still fits. In ollama ps, PROCESSOR should read 100% GPU. Anything else means part of the model spilled into system RAM; drop to 32768 or pick a smaller model.
Step 3: Install Aider
Aider's docs recommend the installer package, which puts Aider in its own isolated environment:
python -m pip install aider-install
aider-install
Then point Aider at Ollama. On Mac or Linux:
export OLLAMA_API_BASE=http://127.0.0.1:11434
On Windows, run setx OLLAMA_API_BASE http://127.0.0.1:11434 and restart your shell.
Step 4: Start your first session
Change into a git repo and launch Aider with the model you pulled, using the ollama_chat/ prefix. Aider's docs recommend it over ollama/ because it routes through Ollama's chat endpoint, where the model follows instructions far better.
cd ~/projects/my-app
aider --model ollama_chat/qwen3-coder:30b
At the prompt, describe a change in plain language:
> add a /health endpoint to the API that returns {"status": "ok"}
Aider shows you a diff and asks before applying it. Say yes and the change lands as a git commit with a sensible message. That confirm-before-apply loop is the whole safety model: the agent proposes, you approve.
The daily workflow: five commands that cover most sessions
Five slash commands cover most of a working day:
/add <file>— add files to the chat so the model can read and edit them. Add only what the task touches./ask— switch to question mode: the model discusses code without editing anything. Use it to understand a codebase before changing it./architect— switch to architect mode: the model plans first, then edits. Good for multi-file changes./diff— review the uncommitted changes from this session./undo— roll back the last change Aider made, including its git commit.
On a capable machine, split the work between two models: --architect runs a strong model for planning and a cheaper one for edits:
aider --model ollama_chat/qwen3-coder:30b --architect --editor-model ollama_chat/qwen2.5-coder:14b
Save it in .aider.conf.yml in your project or home directory:
model: ollama_chat/qwen3-coder:30b
auto-commits: true
Troubleshooting
Edits come back garbled or empty. You probably used the ollama/ prefix instead of ollama_chat/. Restart with the chat prefix and the model will follow Aider's edit format.
Aider seems to forget files you added. The context window is too small. Raise OLLAMA_CONTEXT_LENGTH to 65536, restart Ollama, and confirm the window grew with ollama ps.
Everything is slow. In ollama ps, PROCESSOR below 100% GPU means the model or its KV cache no longer fits in VRAM. Lower the context length or switch to the 14B model.
Where this setup falls short
A local 14B or 30B model will not match a frontier cloud model on hard problems. On multi-file refactors and vague requests, it may edit the wrong file, loop on a failing fix, or produce code that looks right and breaks tests. Keep tasks small and concrete, run tests after each change with /run or /test, and review everything like you would a junior developer's work.
OpenCode vs Cline vs Aider vs OpenHands Compared puts Aider next to three other terminal agents, and How to Run OpenCode with Ollama covers the same local setup for a different agent.
The bottom line
Aider with Ollama is the cheapest way to get a real coding agent: free, private, and running on hardware you already own. The install is a few commands, the model choice comes down to your GPU, and the one setting that matters is the 64K window. Get that right, start with small edits, and confirm every diff. The agent types, you judge.


Comments
Post a Comment