AI coding assistants are great, but relying on cloud APIs like Claude 3.5 Sonnet or GPT-4o for every single terminal command gets expensive fast. Plus, you might not want to send your proprietary codebase to the cloud.
Enter Aider. Itβs a CLI-based AI pair programmer that actually edits files and commits changes directly to your Git repo.
While most people use Aider with OpenAI or Anthropic APIs, you can run it completely offline using local models via Ollama. It's the ultimate privacy-first, zero-cost pair programming setup.
Here is my guide to making Aider work flawlessly with local models (like qwen3.5-coder:14b or llama3) without losing context or breaking your code.
1. The Core Setup: Connecting Aider to Ollama
Starting Aider with a local model is straightforward. If you have Ollama running, just point Aider to it:
aider --model ollama/qwen3.5-coder:14b
However, running it out of the box often leads to frustration. Local models might forget your instructions halfway through or output broken markdown. Here is how to fix that.
2. The Secret Sauce: .aider.model.settings.yml
This is the most critical step for local LLMs. By default, Ollama models might load with a restricted context window, causing "silent data drops" where the AI forgets the beginning of the file.
Create a .aider.model.settings.yml file in your project root to explicitly tell Aider how to handle your specific local model:
- name: ollama/qwen3.5-coder:14b
num_ctx: 32768 # Expand the context window to prevent amnesia
edit_format: whole # Force the model to output the entire file if search/replace fails
Tip: If your local model struggles with partial code edits (diffs), forcing edit_format: whole ensures you get clean, working files, even if it takes a bit longer to generate.
3. Preventing "Design Drift"
When pair programming with AI, sometimes the model tries to be too helpful and starts refactoring unrelated files. To maintain control and prevent your repo from drifting into chaos, master these CLI commands:
π’ Use /read-only for Context
Don't add every file to the chat. Only /add the files you want to edit. For documentation or reference files, use /read-only. This prevents the AI from accidentally modifying your API docs or configs.
> /add app.py
> /read-only api_docs.md
π The Magic /undo
Because Aider is Git-native, every change is committed automatically. If the local model hallucinates or writes garbage code, simply type /undo to instantly roll back the commit and the file changes.
π§ Architect Mode for Complex Refactoring
If you want to use a heavy model (like Claude 3.7 Sonnet) for planning but a local model for writing, use Architect Mode. The "Architect" model creates the blueprint, and your local "Editor" model executes the changes. It's a great way to save API costs while maintaining high code quality.
Conclusion
Aider isn't just a code generator; it's a Git-aware workflow tool. By pairing it with a strong local model like qwen3.5-coder or llama3, you get an autonomous, private, and free pair programmer right in your terminal.
Give it a try, tweak your context windows, and let me know which local models you find work best with Aider!
Top comments (0)