Aider - AI Pair Programming Assistant Complete Guide
Let AI write, refactor and debug code directly in your repository, with automatic Git commits, supporting GPT-4o, Claude 3.5 and other models
Auto Edit Files
Directly modify local code files
Git Integrate
Automatically commit with meaningful messages
Voice Input
Support voice description of requirements
Multi-Model Support
GPT-4o, Claude, DeepSeek
1. Quick Installation
Install Aider
pip install aider-chat2. Configuration File Details
.aider.conf.yml Configure
# .aider.conf.yml
model: gpt-4o
auto-commits: true
auto-test: true
voice: true
watch: true
# Using custom API
openai-api-base: https://api.n1n.ai/v1
openai-api-key: your-api-key-here
# Git Configure
git: true
gitignore: true
pretty: true
show-diffs: true
# File monitoring
watch-files:
- "*.py"
- "*.js"
- "*.ts"Configuration Description
- • model: Specify the model to use (gpt-4o/claude-3-5-sonnet)
- • auto-commits: Automatically commit code changes
- • auto-test: Automatically run tests after modifications
- • voice: Enable voice input feature
- • watch: Monitor file changes
API Configure
- • openai-api-base: Custom API endpoint
- • openai-api-key: API key
- • Support OpenAI, Azure, self-hosted services
- • Compatible with OpenAI API format
3. Basic Usage
Common Commands
# Basic usage
aider main.py
# Specify multiple files
aider src/*.py tests/*.py
# Using voice input
aider --voice main.py
# Monitor file changes
aider --watch src/💡 Practical Tips
- • Use
/addcommand to add new files to the session - • Use
/dropto remove unnecessary files - • Use
/undoto undo the last modification - • Use
/diffto view code changes - • Use
/runto execute shell commands
4. Practical Example: Building a Complete Feature
Create User Authentication System
# Create a complex feature
$ aider main.py utils.py
> /add Please help me implement a user authentication system, including:
> 1. JWT token generation and validation
> 2. Password encryption and storage
> 3. User login/registration interface
> 4. Middleware permission validation
# Aider will automatically:
# - Analyze existing code structure
# - Generate required new files
# - Add necessary dependencies
# - Create unit tests
# - Auto commit code changes✨ Advantages of Aider
- • Understand the entire project context
- • Automatically handle imports and dependencies
- • Generate code that matches project style
- • Automatically create test files
- • Smart Git commit messages
🎯 Best Practices
- • Clearly describe requirements and expected results
- • Implement complex features step by step
- • Review generated code promptly
- • Keep commits small and frequent
- • Use test-driven development
5. Model Selection Recommendations
GPT-4o
✅ Strongest code understanding capability
✅ Complex logic implementation
✅ Architecture design
💰 Higher cost
aider --model gpt-4oClaude 3.5 Sonnet
✅ Excellent code quality
✅ Detailed explanations
✅ Higher security
💚 Cost-effective
aider --model claude-3-5-sonnetDeepSeek Coder
✅ Focused on code generation
✅ Fast speed
✅ Low cost
🚀 First choice for daily development
aider --model deepseek-coder6. FAQ Solutions
How to use custom API endpoint?
export OPENAI_API_BASE="https://api.n1n.ai/v1" export OPENAI_API_KEY="your-api-key" aider --model gpt-4o main.py
How to limit modification scope?
Use --read parameter to specify read-only files:
aider main.py --read lib/*.py tests/*.py
How to handle large codebases?
Use map mode to reduce token consumption:
aider --map-tokens 1024 --model gpt-4o-mini src/