Aider — AI Coding Tool Guide

Git-native AI pair programming in your terminal. Map-refine architecture, polyglot support, edit formats, and multi-model configuration for focused, high-quality edits.

aidergitterminal-agentpair-programming

Aider

Aider is a terminal-based AI pair programming tool deeply integrated with Git. It automatically commits changes with meaningful messages, works with most LLMs, and excels at focused, high-quality edits with its map-refine architecture.

What Makes Aider Different

  • Git-native — Every change is automatically committed with descriptive, conventional commit messages
  • Map-Refine architecture — Creates a repository map (full codebase structure), then refines targeted changes against it. This lets Aider understand your entire project while only editing the relevant files
  • Edit formats — Uses structured search/replace blocks for precise, verifiable edits (not free-form code generation)
  • Polyglot — Recognizes and edits most programming languages via tree-sitter
  • Swe-bench leader — Top performer on the SWE-bench benchmark for real-world bug fixing

Getting Started

pip install aider-chat
export ANTHROPIC_API_KEY="sk-ant-..."
cd my-project
aider

Multi-Model Configuration

Aider supports different models for different tasks:

# .aider.conf.yml
model: claude-sonnet-4-20250514          # Primary model
weak-model: claude-haiku-4-20250514      # Cheap model for simple tasks
editor-model: claude-sonnet-4-20250514   # Model used for editing

Prompt Patterns

Aider works best with focused, specific prompts:

Scoped Feature

Add input validation to the signup form in src/forms/signup.tsx.
Fields: email (required, valid format), password (8+ chars,
1 uppercase, 1 number), name (required, 2+ chars).
Use zod schemas matching the pattern in src/lib/validators.ts.

Multi-File Refactoring

Refactor the database layer:
1. Move all raw SQL from src/routes/ into src/db/queries/
2. Create typed query functions with proper parameterization
3. Update route files to use the new query functions
4. Keep the existing test suite passing

Bug Fix with Context

The user search endpoint at src/api/users/search.ts returns
duplicate results when multiple search terms overlap.

Trace the query construction (starts at line 47), identify why
duplicates occur, and fix while maintaining the existing sort order.

Documentation Generation

Read src/services/payment.ts and generate:
1. JSDoc comments for all exported functions
2. A markdown doc at docs/payment-service.md covering:
   - Architecture overview
   - Function reference (signatures, parameters, returns)
   - Error handling patterns
   - Example usage

Configuration

.aider.conf.yml at project root or ~/.aider.conf.yml:

# Model settings
model: claude-sonnet-4-20250514
weak-model: claude-haiku-4-20250514

# Git settings
git: true
auto-commits: true
dirty-commits: true
attribute-author: true

# Edit settings
edit-format: search_replace         # Structured search/replace edits
dark-mode: true

# File handling
read: [CONVENTIONS.md, README.md]   # Files to read every session
auto-test: true                      # Run tests after edits
test-cmd: npm test                   # Test command

Key Edit Formats

FormatBehavior
search_replaceStructured find-and-replace (default, most reliable)
diffUnified diff patches
wholeRewrite entire file
udiffUnified diff with fuzz matching

Map-Refine Architecture

Aider's two-phase approach:

  1. Map — Scans and indexes the entire repo structure. Understands which files import which, where functions are defined, and how modules connect. This gives Aider a mental model of your project without reading every file.

  2. Refine — For each prompt, Aider selects the most relevant files from the map, reads them, and generates precise edits. The map ensures it doesn't miss cross-file impacts.

This is why Aider excels at tasks like "rename this function everywhere" or "change this type across the codebase" — the map tells it every place the function/type is used.