Aider Advanced Tips: Architecture Analysis and Batch Refactoring Guide
Aider's real leverage is not basic usage but repo-map token budgets, architect-mode model splitting, a four-step refactoring rhythm, CONVENTIONS.md for team style, and a test-driven loop. Each comes with commands, config snippets and five failure modes.
📜 Table of Contents
📖 Keep reading
Aider Advanced Tips: Architecture Analysis and Batch Refactoring
Aider is a terminal pair-programmer with a different model from editor plugins: it reads your repository, edits files directly, and commits every change to git. That makes changes reversible — provided you know how to reverse them.
Three setup basics
pip install aider-chat
cd /path/to/repo
aider
Pin common flags in .aider.conf.yml at the repo root so the team shares them:
model: sonnet
editor-model: sonnet
auto-commits: true
map-tokens: 2048
read:
- CONVENTIONS.md
And always run inside a git repository — without it you lose auto-commits and /undo.
Repo map: how it "sees" the project
Aider does not stuff the whole codebase into the context. It parses every file with tree-sitter, extracts signatures and references, and builds a compressed repo map, sending only that map plus the files you added.
| Flag | Effect | Advice |
|---|---|---|
--map-tokens |
Token budget for the map | 2048-4096 for large repos |
--show-repo-map |
Print the map without running | Debug "why didn't it find that function" |
The map contains signatures, not implementations. The model knows calculate_tax() exists but not what it does. For "how does this compute" questions, /add the file or you get a plausible guess.
Architect mode: plan first, code second
aider --architect --model <strong-model> --editor-model <cheap-model>
The strong model analyzes and proposes without editing; the editor model applies the plan. Toggle in-session with /architect.
Use it when the change spans several files, when you want to review the approach before code exists, or when you want a strong model to plan and a cheap one to type. Skip it for typos and one-line edits.
Batch refactoring in four steps
- Scope it.
/add src/billing/— but only what the change actually touches. More files means longer context and worse attention. - Ask for a plan, not code. "Do not change code yet. List the files, the change in each, and the blast radius."
- Execute in batches. One module per round, run tests between rounds, then
/diff. - Roll back fast.
/undoreverts the last change; every edit is a commit, which is the real reason to keep auto-commits on.
CONVENTIONS.md for team consistency
.aider.custom.md is not an Aider convention. The real mechanism is explicit read-only files:
aider --read CONVENTIONS.md
or list it under read in the config. Read-only files are visible to the model but never edited — right for style rules, architecture notes and API contracts.
# Project conventions
- Python 3.11, type hints required, no bare except
- Business logic in the service layer; no SQL in routes
- Every new function gets a docstring with params and exceptions
- Tests use pytest, files named test_*.py, no real database access
Do not put long background docs or historical decision logs in there; the longer the file, the more likely a rule gets ignored. A few dozen lines of rules that actually get violated is the right size.
Test-driven loop
aider --test-cmd "pytest -q" --lint-cmd "ruff check ."
Or in-session: /run pytest tests/test_billing.py -q. The value is the closed loop — the model sees the failure immediately and fixes it, instead of you copying tracebacks back and forth. Get the suite green before refactoring, or you cannot tell new breakage from old.
Local models
export OLLAMA_API_BASE=http://127.0.0.1:11434
aider --model ollama/qwen2.5-coder:7b
Be realistic: a 7B handles "change this function precisely" but struggles with cross-file refactors — half-applied edits, missed call sites, unrelated changes. A workable split is local for single-file edits and tests, cloud for the hard restructuring.
Cost and context
| Practice | Effect |
|---|---|
/tokens |
See current context usage |
--cache-prompts |
Cache repeated prefixes across turns |
/add only what is needed, /drop when done |
The single biggest saving |
Long context is not just expensive; it dilutes instructions. One task per session beats one long session.
Five traps
- Running outside git — nothing to undo.
- Adding too many files at once.
- No acceptance criteria — "optimize this" gets you its idea of optimized.
- Committing without reading the diff.
- Using architect mode for trivial edits.
FAQ
How is it different from Cursor or Copilot? Aider is terminal-first, operates in git commits and excels at multi-file changes; editor plugins excel at inline completion. Many people use both.
Can it edit binaries or config? Text files, mostly yes. Binaries and GUI-only operations, no.
Does it run tests automatically? With --test-cmd, after each change. Avoid unlimited auto-fix loops.
How big a local model? 7B for single-file edits; 30B+ or a cloud model for cross-file work. Quantization runs on less VRAM at lower quality.
Note: commands, flags and config fields evolve between releases, and model identifiers vary by provider. Check the official docs for current syntax.
Written by our editorial team; tools listed here are tested or verified against public sources. Links point to official sites or GitHub repos for reference only — no paid placements.