# Connect a local model to a coding agent (Aider + Ollama)

> Install Aider with aider-install, point it at Ollama with OLLAMA_API_BASE, pull a coding model such as qwen3-coder:30b, start Ollama with a larger context, and run aider --model ollama_chat/<model> inside a git repository.

Canonical: https://thelocalbench.com/how-to/local-model-coding-agent-aider · The Local Bench (thelocalbench.com), data as of 2026-10-13, CC BY 4.0

- Difficulty: Intermediate
- Time: about 30 minutes
- Cost: $0 (free software; a 24 GB GPU or 32 GB+ unified memory for 30B-class coding models)
- Hardware: 24 GB GPU or 32 GB+ unified memory for qwen3-coder:30b; 12–16 GB GPU for smaller coding models, with weaker results
- OS: Linux, macOS, Windows
- Prerequisites: Python 3 with pip; git, and a project that is a git repository; Ollama installed (see "Run your first local model")
- Parts: Aider (terminal coding agent); Ollama (model server); qwen3-coder:30b (MoE coding model, about 3B active per token)
- Status: Sourced, not yet tested. Commands are copied from the Aider and Ollama documentation (checked 2026-10-13). We have not yet run this guide on our bench, and we have not yet measured how well local models do in Aider.
- Tested on: not yet tested
- Last tested: never
- Reviewed: 2026-10-13

## Not yet tested by us

- The whole guide end to end
- Edit quality of qwen3-coder:30b in Aider
- The .aider.model.settings.yml example with this model name

## Step 1: Install Aider

```sh
python -m pip install aider-install
aider-install
```

`aider-install` sets Aider up in its own isolated environment, so it won't clash with your other Python packages.



## Step 2: Tell Aider where Ollama is

On macOS or Linux:

```sh
export OLLAMA_API_BASE=http://127.0.0.1:11434
```

On Windows (restart the shell afterwards):

```powershell
setx OLLAMA_API_BASE http://127.0.0.1:11434
```



## Step 3: Pull a coding model and start Ollama with more context

```sh
ollama pull qwen3-coder:30b
OLLAMA_CONTEXT_LENGTH=8192 ollama serve
```

Leave that terminal running. On a 12–16 GB card, pick a smaller coding model from the Ollama library instead.

> **Tip: Context and Aider**
>
Aider's docs say it sizes Ollama's context window for each request (your request plus 8K tokens for the reply), so files aren't silently cut off. You can pin a fixed size instead with a settings file (see troubleshooting).




## Step 4: Start Aider in your project

In a second terminal:

```sh
cd /to/your/project
aider --model ollama_chat/qwen3-coder:30b
```

Aider recommends the `ollama_chat/` prefix over `ollama/`. It may print warnings about models it doesn't know; the Aider docs explain these and they're usually safe to ignore.

> **Warning: Aider edits and commits**
>
Aider writes changes to your files and commits them to git. Work on a branch, and review with `git diff` or `/undo` inside Aider if a change is wrong.




## Step 5: Verify it works

Add a file to the chat and ask for a small, checkable change:

```text
/add README.md
Add a one-line "Requirements" section that says Python 3.10 or newer.
```

Aider should show a diff, apply it, and make a commit. Confirm with:

```sh
git log --oneline -1
```

The latest commit should be Aider's, describing the README change.





## Troubleshooting

### Aider can't connect to Ollama

Check that `ollama serve` is running and that `curl http://127.0.0.1:11434` replies "Ollama is running". On Windows, open a new terminal after `setx` so the variable is loaded.



### Edits are malformed or ignored

Smaller and heavily quantized models struggle with Aider's edit formats. Try a larger model, or a higher-precision tag. Model choice matters more here than in plain chat.



### Pin a fixed context window

Create `.aider.model.settings.yml` in your project or home directory. The Aider docs give this shape (use your model's name):

```yaml
- name: ollama/qwen2.5-coder:32b-instruct-fp16
  extra_params:
    num_ctx: 65536
```

A larger `num_ctx` needs more memory for the KV cache.



### Prefer an editor extension?

Continue brings the same local model into VS Code or JetBrains: autocomplete, chat and edits. Its docs have a dedicated Ollama guide.

## Sources

- [Aider docs: connecting to Ollama](https://aider.chat/docs/llms/ollama.html)
- [Ollama library: qwen3-coder](https://ollama.com/library/qwen3-coder)
- [Ollama docs: context length](https://docs.ollama.com/context-length)
- [Continue docs: using Ollama (alternative for VS Code / JetBrains)](https://docs.continue.dev/guides/ollama-guide)
