Aider Advanced Tips: Architecture Analysis and Batch Refactoring Guide

📘 Tutorials 2026-07-19 · Updated 2026-11-13 4 min read

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

  1. Scope it. /add src/billing/ — but only what the change actually touches. More files means longer context and worse attention.
  2. Ask for a plan, not code. "Do not change code yet. List the files, the change in each, and the blast radius."
  3. Execute in batches. One module per round, run tests between rounds, then /diff.
  4. Roll back fast. /undo reverts 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

  1. Running outside git — nothing to undo.
  2. Adding too many files at once.
  3. No acceptance criteria — "optimize this" gets you its idea of optimized.
  4. Committing without reading the diff.
  5. 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.

Related Articles
2026-08-13
Run LLM on Android 2026: 5 Ways to Get a Local Model on Your Phone
2026-08-14
Ollama Models List 2026: Families, Sizes and a Pick-by-VRAM Table
2026-08-07
AI Meeting Summarizer: Free Local Pipeline with Whisper and Ollama
2026-08-07
AI Video Summarizer: Skip to the Good Part of Any YouTube Video
2026-08-06
Awesome ChatGPT Prompts (166,781 Stars) 2026: The 200,000-Star Prompt Library and How to Use It
2026-07-23
Vector Database Performance Benchmarks 2026: Chroma vs Qdrant vs Pinecone

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.

💬 Comments (0)

No comments yet. Be the first!

Login to comment