Aider: AI Pair Programming in Your Terminal
AI coding tools have split into two camps: IDE plugins that work inside your editor (Cursor, GitHub Copilot, Windsurf) and terminal-based agents that operate on your entire codebase from the command line. Aider is the most mature tool in the second category.
Aider talks to an LLM, understands your codebase structure, makes targeted edits to files, and commits the changes to git — all from a chat interface in your terminal. It's particularly useful for larger refactors, adding features that span multiple files, and code tasks you'd rather describe than type.
How Aider Works
Aider reads the files you specify (or that it discovers through /add commands), sends them as context to an LLM, and applies the model's edits back to your files. It handles the prompt engineering for code modification: asking the model to return diffs, applying them, validating syntax, and committing.
$ aider src/auth.ts src/users.ts
Aider v0.61.0, model claude-3-5-sonnet-20241022
> Add JWT refresh token support to the auth module
I'll add refresh token support to the auth module. I need to:
1. Add a refresh token generation function
2. Store refresh tokens with expiry
3. Add a token refresh endpoint
4. Update the middleware to handle refresh token rotation
[edits apply to src/auth.ts and src/users.ts]
src/auth.ts
src/users.ts
Tokens: 3.2k sent, 891 received. Cost: $0.01
Installation
pip install aider-chat
# Or with pipx for isolated installation
pipx install aider-chat
Configuration
Set your API key in the environment or .env file:
# For Claude (recommended)
export ANTHROPIC_API_KEY=sk-ant-...
# For OpenAI
export OPENAI_API_KEY=sk-...
# For local models via Ollama
export OLLAMA_API_BASE=http://localhost:11434
Aider supports 100+ models through LiteLLM integration.
Basic Usage
# Start with specific files
aider src/components/Button.tsx src/styles/button.css
# Start with a directory
aider src/
# Start with a git repo (aider auto-adds relevant files)
aider --auto-commits
Inside the chat:
> /add src/api/users.ts # add a file to context
> /drop src/old-file.ts # remove from context
> /ls # show files in context
> /diff # show uncommitted changes
> /undo # revert last change + commit
> /run pytest tests/ # run a command and paste output
Choosing the Right Model
Model choice significantly affects quality:
| Model | Best for | Cost |
|---|---|---|
claude-3-5-sonnet-20241022 |
Complex refactors, good at diffs | ~$3/M input |
claude-3-opus-20240229 |
Hardest reasoning tasks | ~$15/M input |
gpt-4o |
General coding, good context handling | ~$5/M input |
gpt-4o-mini |
Simple tasks, fast and cheap | ~$0.15/M input |
deepseek/deepseek-coder |
Code-specialized, cheaper | ~$0.14/M input |
ollama/codellama:34b |
Local, no API cost | Free (GPU required) |
# Use a specific model
aider --model claude-3-5-sonnet-20241022
# Use Opus for complex tasks
aider --model claude-3-opus-20240229
# Local Ollama model
aider --model ollama/codellama:34b
Architect Mode for Large Changes
Aider's architect mode uses a two-model approach: a strong model designs the changes, a cheaper model implements them:
aider --architect --model claude-3-5-sonnet-20241022 \
--editor-model gpt-4o-mini
This is useful for large refactors where you want high-quality planning but cheaper execution.
Git Integration
Aider creates a git commit for each completed change. Commit messages are auto-generated:
feat: add JWT refresh token support with automatic rotation
- Added refreshToken generation in generateTokens()
- RefreshTokenStore tracks tokens with 7-day expiry
- POST /auth/refresh validates and rotates tokens
- Middleware handles expired access tokens transparently
aider
To disable auto-commits:
aider --no-auto-commits
Undo the last change (reverts commit):
> /undo
Aider vs. IDE-Based AI Tools
| Aspect | Aider | Cursor / Copilot |
|---|---|---|
| Interface | Terminal chat | IDE inline |
| Multi-file changes | Explicit context management | Auto-context |
| Git integration | Built-in, creates commits | Manual |
| Refactor across codebase | Strong | Moderate |
| Quick inline completions | Weak | Strong |
| Reproducibility | Commits as checkpoints | Limited history |
| Cost | Pay-per-token | Subscription |
Aider wins for planned, multi-file changes. IDE tools win for flow-state coding where you want AI completing lines as you type.
Useful Workflows
Explain then Implement
> /read-only docs/architecture.md
> Based on the architecture doc, add a rate limiter service
> following the same patterns as the existing cache service
Bug Fix with Test
> The login endpoint is throwing "Cannot read property 'id' of undefined"
> when the user's session expires. Fix the bug and add a test for it.
Refactor with Constraints
> Refactor the database query functions in src/db/ to use
> connection pooling. Keep the existing function signatures unchanged
> and don't modify the tests.
Code Review Mode
# Give aider your diff and ask for a review
git diff | aider --message "Review these changes for security issues and antipatterns"
Configuration File
Create .aider.conf.yml in your project root:
model: claude-3-5-sonnet-20241022
auto-commits: true
dirty-commits: false
auto-lint: true
lint-cmd: "biome check --apply"
test-cmd: "bun test"
With auto-lint, aider runs your linter after every change and fixes issues automatically.
Tips for Better Results
- Be specific about constraints: "Add pagination without changing the existing API interface"
- Use
/read-onlyfor reference files you don't want changed - Keep context focused: 3-5 files works better than 20
- Check the diff before committing:
/diffshows what changed before it's committed - Use
/runto paste test output: "Run the tests and fix any failures"
Aider is most valuable for changes that are clear in intent but tedious to implement — migrations, adding consistent patterns across files, updating interfaces everywhere they're used, and incremental refactors that you'd otherwise put off.
Enjoyed this guide? Subscribe to DevTools Guide — a free weekly newsletter covering developer tools, workflows, and best practices.