AD SPACE AVAILABLE · BRAND PARTNERS WELCOME

How to Configure Aider with Local LLMs via Ollama for Private, Offline AI Pair Programming

小森夏平 · 365Finds Editorial
Indexed 88,650 Wiki articles

Put 365 Wiki to work with your AI

Copy the prompt below, paste it into the AI you already use, then ask your question.

Download full Skill

Try it with the prompt first. If you use 365 Wiki often, install the full 365Wiki Skill so you do not have to paste it again. No regular AI? Gemini or Microsoft Copilot on the web will work.

365Wiki Skill

Software engineers facing strict enterprise data governance, intellectual property boundaries, or recurring commercial API costs do not have to abandon terminal AI pair programming. Connecting Aider to local large language models (LLMs) through Ollama creates a completely offline, zero-telemetry development loop. Code never leaves your workstation, API keys are unnecessary, and development proceeds uninterrupted without internet access.

At 365Finds, our verdict is clear: Aider paired with Ollama is the premier open-source stack for private, offline pair programming. While heavyweight IDE extensions frequently choke on local models by flooding small context windows with noisy prompts, Aider's lean architecture—built around a compact Abstract Syntax Tree (AST) repository map and automated Git commits—allows open-weights models to punch far above their weight class. Achieving commercial-grade reliability requires configuring the connection string, resolving Ollama's default context truncation trap, choosing the right model tier for your VRAM, and dialing in the correct edit format.


Why Pair Aider with Ollama?

Aider operates directly in the terminal, parsing codebases and submitting precise file edits into a local Git history. Ollama manages model serving, quantizations, and GPU inference across macOS, Linux, and Windows. Together, they solve three critical pain points:

  1. Zero Data Exfiltration: Strict compliance environments (such as defense, healthcare, fintech, or proprietary core infrastructure) prohibit sending source code to third-party cloud APIs.
  2. Deterministic Operating Costs: Local inference eliminates monthly subscription fees and per-token API charges.
  3. Air-Gapped Reliability: Work continues seamlessly on airplanes, remote environments, or during corporate network outages.

Hardware Sizing: Choosing the Right Local Coding Model

Local pair programming demands models that excel at strict instruction following, syntactical accuracy, and structural diff generation. Running a model that is too small produces broken diffs; running one too large leads to extreme latency or GPU out-of-memory (OOM) crashes.

365Finds recommends benchmarking your setup against three distinct hardware tiers:

Hardware TierAvailable VRAM / MemoryRecommended ModelPractical Performance & Role
Entry / Laptop8 GB – 12 GB VRAMqwen2.5-coder:7bFast completions; single-function edits; requires strict scoping and whole-file edit format.
Mid-Range Workstation16 GB – 24 GB VRAMqwen2.5-coder:14b or deepseek-coder-v2:16bBalanced refactoring; handles multi-file context; capable of producing reliable diffs.
High-End / Studio24 GB – 32 GB+ VRAM (or Apple Silicon 36 GB+)qwen2.5-coder:32b365Finds Top Recommendation; benchmarked at 72.9% on Aider leaderboards; rivals commercial APIs.

365Finds Pick: If your hardware has at least 24 GB of unified memory or dedicated VRAM, install qwen2.5-coder:32b immediately. On Aider's standardized coding benchmarks, this model achieves commercial-grade results while executing completely on local silicon.


Step-by-Step Configuration Guide

Step 1: Install Ollama and Pull Your Model

Install Ollama according to your operating system's standard packaging, then pull your selected coding model:

# Recommended 32B model for 24GB+ VRAM workstations
ollama pull qwen2.5-coder:32b

# Or lightweight 7B model for laptops with 8GB-12GB VRAM
ollama pull qwen2.5-coder:7b

Verify that the model runs locally:

ollama run qwen2.5-coder:32b "Write a Python function to check for prime numbers."

Step 2: Fix Ollama's Hidden 2K Context Window Trap

By default, Ollama initializes model instances with a restrictive 2,048-token context window (num_ctx). In a coding session where Aider loads the repository structure, file contents, and chat history, a 2K window will silently truncate prompts. When context is discarded, the model produces hallucinated variable names and invalid code locations.

You must expand the context length when running Ollama.

Option A: Set Environment Variable at Server Launch

When starting the Ollama background daemon, expand the server context length:

# Linux / macOS
OLLAMA_CONTEXT_LENGTH=32768 ollama serve

# Windows (PowerShell)
$env:OLLAMA_CONTEXT_LENGTH="32768"
ollama serve

Option B: Configure Fixed Context in Aider Model Settings

Create or edit .aider.model.settings.yml in your user home directory or project root:

- name: ollama_chat/qwen2.5-coder:32b
  extra_params:
    num_ctx: 32768
- name: ollama_chat/qwen2.5-coder:7b
  extra_params:
    num_ctx: 16384

Step 3: Configure Endpoint and Launch Aider

Aider interacts with Ollama over HTTP via its default endpoint (http://127.0.0.1:11434). Set the base URL in your shell environment:

# Linux / macOS
export OLLAMA_API_BASE=http://127.0.0.1:11434

# Windows (PowerShell)
$env:OLLAMA_API_BASE="http://127.0.0.1:11434"

# Windows (Command Prompt - permanent)
setx OLLAMA_API_BASE http://127.0.0.1:11434

Navigate to your Git repository and start Aider using the ollama_chat/ model prefix:

cd /path/to/your/project
aider --model ollama_chat/qwen2.5-coder:32b

Critical Distinction: Always launch with ollama_chat/<model> rather than ollama/<model>. The ollama_chat/ prefix instructs Aider to utilize Ollama's native chat completion endpoint, which automatically structures conversation templates and supports dynamic context management.


Dialing in Edit Formats: diff vs. whole

Aider relies on specific edit formats to translate LLM responses into disk writes. Selecting the right format is critical when dealing with local models.

       ┌────────────────────────┐
       │   Local Model Output   │
       └───────────┬────────────┘
                   │
         Does model understand
        SEARCH/REPLACE anchors?
                   │
          ┌────────┴────────┐
         YES                NO
          │                 │
          ▼                 ▼
   [ diff format ]   [ whole format ]
   Fast, low token   Full file overwrite,
   usage, 32B models  reliable for 7B models

1. The diff Format (Best for 32B Models)

2. The whole Format (Essential Fallback for 7B / 14B Models)

How to Force an Edit Format:

If a 7B or 14B model fails to apply search/replace blocks cleanly, force the whole-file format at launch:

aider --model ollama_chat/qwen2.5-coder:7b --edit-format whole

Best Practices for Offline Terminal Pair Programming

  1. Keep Scoped Context with /add and /drop: Local models degrade when flooded with irrelevant files. Use /add <file> only for files requiring edits, and /read <file> for reference-only headers or documentation.
  2. Rely on the Repository Map: Aider automatically generates an AST-based map of class definitions and function signatures. This gives the local model global awareness across your repository without consuming raw token limits.
  3. Automate Offline Linting and Tests: Configure Aider's test and lint commands (aider --test-cmd "pytest" --auto-test). When a local model introduces a minor syntax typo, Aider automatically feeds the compiler or test error back to Ollama, allowing the model to repair its own mistake without manual intervention.
  4. Leverage Git Safety Nets: Every edit applied by Aider is committed to Git automatically. If a local model hallucinates, type /undo in the chat to instantly roll back your working tree.

Conclusion & 365Finds Recommendation

Developers no longer need to sacrifice workflow speed for privacy compliance. By combining Aider with Ollama, software teams can run a hardened, zero-outbound pair programming environment on local workstations.

For production use, 365Finds strongly advises running qwen2.5-coder:32b over ollama_chat/ with a context window expanded to at least 32,768 tokens. If hardware constraints force you onto a 7B or 14B model, pair it with --edit-format whole to eliminate patch parsing failures. This setup delivers high autonomy, total data ownership, and zero operational costs.


References