How aider-ai/aider works
Purpose and Entry Points
Aider is a Python terminal-based AI pair-programming tool. It operates inside a user’s code repository, sends contextualized requests to cloud or local LLMs, applies model-produced code edits, and can validate and commit them. CLI startup is through aider/__main__.py, with application orchestration in aider/main.py; argument parsing and startup configuration live in aider/args.py.
Session Orchestration and User Interface
aider/main.py constructs the interactive session: repository access, model selection, I/O, chat history, coder mode, and optional integrations. Terminal interaction, command dispatch, and chat persistence are separated into aider/io.py, aider/commands.py, and aider/history.py. Optional alternate interaction surfaces include browser/copypaste support in aider/gui.py and voice input in aider/voice.py.
Coder Strategy Layer
The aider/coders/ package is the core behavior boundary between a conversation and concrete filesystem edits. aider/coders/base_coder.py provides the common chat/edit lifecycle, while specialized subclasses select distinct response and patch protocols: whole-file, search/replace, unified diff, edit blocks, and architect/editor workflows. Key implementations include aider/coders/editblock_coder.py, aider/coders/udiff_coder.py, and aider/coders/architect_coder.py; paired *_prompts.py files define each protocol’s model contract.
LLM and Model Integration
Model abstraction, capability/settings resolution, and request routing are centralized in aider/models.py and aider/llm.py. aider/sendchat.py manages sending and streamed model responses; aider/openrouter.py is a provider-specific integration. Model metadata/settings are bundled in aider/resources/model-metadata.json and aider/resources/model-settings.yml. The external-service boundary is LLM provider APIs, including OpenAI-compatible endpoints, Anthropic, DeepSeek, OpenRouter, and local model servers.
Repository Context and Git Boundary
aider/repo.py encapsulates the working repository and Git-facing operations. aider/repomap.py builds a token-budgeted structural map of the codebase so the model can reason about files beyond those explicitly added to chat. Language-aware symbol extraction is driven by Tree-sitter query assets such as aider/queries/tree-sitter-language-pack/python-tags.scm. This layer reads and changes the local filesystem/Git worktree; coder output must pass through it rather than directly representing trusted edits.
Edit Application and Validation Loop
A typical turn flows: user request → selected coder assembles prompts from chat history, selected files, repository map, and attachments → model response streams back → coder parses and applies edits → diffs are presented → optional lint/test commands run. Patch and diff handling is concentrated in aider/diffs.py, aider/coders/search_replace.py, and format-specific coder classes. aider/linter.py and aider/run_cmd.py execute validation commands, whose output can be fed back into another repair turn.
Supporting Context Inputs and Automation
Aider can incorporate URLs/web content and images through aider/urls.py and aider/scrape.py, and monitor files/comments for IDE-adjacent workflows through aider/watch.py. Analytics is isolated in aider/analytics.py, avoiding coupling core edit execution to telemetry. Docker packaging is defined by docker/Dockerfile; the separate benchmark/ subsystem evaluates coding/model performance rather than serving the interactive application.
Main entry points: main.py Session orchestration · base_coder.py Coder lifecycle · repo.py Repository & Git worktree · repomap.py Repository map
Components 20
Session & UI
- CLI entry point
aider/__main__.py - Session orchestration · Constructs the interactive coding session.
aider/main.py - Arguments & startup config
aider/args.py - Terminal I/O
aider/io.py - Command dispatch
aider/commands.py - Chat history
aider/history.py
Coding & Repository
- Coder lifecycle · Builds context, requests responses, and coordinates edits.
aider/coders/base_coder.py - Edit protocol coders · Edit blocks, unified diffs, and architect/editor workflows.
aider/coders/editblock_coder.py - Repository & Git worktree · The trusted boundary for local file and Git operations.
aider/repo.py - Repository map · Builds a token-budgeted structural codebase map.
aider/repomap.py - Tree-sitter symbol queries
aider/queries/tree-sitter-language-pack/python-tags.scm - Diff & patch handling
aider/diffs.py - Validation runner
aider/linter.py
LLM Integration
- Model resolution · Resolves capabilities and provider settings.
aider/models.py - LLM request routing
aider/llm.py - Streaming chat transport
aider/sendchat.py - LLM provider APIs · Cloud and local OpenAI-compatible model endpoints.
Inputs & Automation
- Web & image context
aider/urls.py - File/comment watch
aider/watch.py - Analytics · Isolated from core edit execution.
aider/analytics.py
Connections 26
- CLI entry point → Session orchestration: starts
- Arguments & startup config → Session orchestration: configures
- Session orchestration → Terminal I/O: runs interaction
- Terminal I/O → Command dispatch: dispatches commands
- Session orchestration → Chat history: loads and persists chat
- Session orchestration → Coder lifecycle: selects and drives
- Session orchestration → Repository & Git worktree: opens worktree
- Session orchestration → Model resolution: selects model
- Session orchestration → Web & image context: adds external context
- Session orchestration → File/comment watch: optional monitoring
- Session orchestration → Analytics: optional telemetry
- Coder lifecycle → Edit protocol coders: uses protocol strategy
- Coder lifecycle → Chat history: assembles conversation
- Coder lifecycle → Repository & Git worktree: uses selected files
- Coder lifecycle → Repository map: adds codebase map
- Coder lifecycle → Streaming chat transport: sends prompt
- Repository map → Repository & Git worktree: reads repository
- Repository map → Tree-sitter symbol queries: extracts symbols with
- Streaming chat transport → LLM request routing: routes request
- Model resolution → LLM request routing: supplies settings
- LLM request routing → LLM provider APIs: calls
- LLM provider APIs → Streaming chat transport: streams response
- Edit protocol coders → Diff & patch handling: parses edits
- Diff & patch handling → Repository & Git worktree: applies through
- Repository & Git worktree → Validation runner: validates changed worktree
- Validation runner → Coder lifecycle: feeds repair output