Aider AI Coding Guide
Aider: AI Pair Programming in Your Terminal
Aider is a powerful command-line tool that turns large language models into a genuine pair programming partner. Unlike IDE-based AI assistants, Aider works directly in your terminal, editing files in your local git repository while maintaining a natural conversational workflow. It is one of the highest-rated AI coding tools in the open-source community, and for good reason.
Why Choose Aider?
Aider stands out from other AI coding tools because of its deep git integration and its ability to work across multiple files simultaneously. Every change Aider makes is automatically committed to git with a descriptive message, giving you a complete history of AI-assisted modifications that you can review, revert, or amend.
- Works with Claude, GPT, Gemini, and any OpenAI-compatible API
- Automatic git commits for every change with meaningful messages
- Multi-file editing — Aider understands relationships across your codebase
- Repository map feature that gives the AI a bird's-eye view of your project
- Voice coding support for hands-free pair programming
- Runs in any terminal on any platform — no IDE dependency
Installation
Aider is distributed as a Python package. Install it using pip or pipx for isolated environments:
# Recommended: install with pipx for isolation
pipx install aider-chat
# Alternative: install with pip
pip install aider-chat
# Verify installation
aider --version
Basic Configuration
Aider uses environment variables for API key configuration. Set up your preferred provider:
# For direct Anthropic API access
export ANTHROPIC_API_KEY=sk-ant-...
# For OpenAI
export OPENAI_API_KEY=sk-...
# For an API relay service like claude4u.com
export OPENAI_API_BASE=https://claude4u.com/v1
export OPENAI_API_KEY=your-relay-api-key
Starting a Session
Navigate to your project directory and launch Aider with your preferred model:
# Start with Claude Sonnet (recommended for most coding tasks)
aider --model claude-sonnet-4-20250514
# Start with GPT-4o
aider --model gpt-4o
# Use a relay service endpoint
aider --model claude-sonnet-4-20250514 \
--openai-api-base https://claude4u.com/v1 \
--openai-api-key your-relay-key
# Add specific files to the chat context
aider src/main.py src/utils.py tests/test_main.py
Key Commands During a Session
Once inside an Aider session, you can use several built-in commands to control the workflow:
/add <file>— Add a file to the chat context so Aider can read and edit it/drop <file>— Remove a file from the context to save tokens/undo— Revert the last change (git reset)/diff— Show the diff of the last change/run <command>— Execute a shell command and share the output with the AI/tokens— Show token usage for the current session/model <name>— Switch to a different AI model mid-session
Practical Workflow Examples
Here is a typical Aider workflow for adding a new feature:
# Start Aider with relevant files
aider src/api/routes.py src/api/handlers.py src/models/user.py
# In the Aider chat, describe what you want:
> Add a new endpoint POST /api/users/export that exports all users
> as a CSV file. Include email, name, and signup date fields.
> Add appropriate error handling and authentication checks.
# Aider will edit the files and auto-commit
# Review the changes:
/diff
# If something needs adjustment:
> The CSV should also include the user's role field
# Run tests to verify:
/run python -m pytest tests/test_api.py -v
Advanced Configuration with .aider.conf.yml
Create a .aider.conf.yml file in your project root for persistent settings:
model: claude-sonnet-4-20250514
openai-api-base: https://claude4u.com/v1
auto-commits: true
dark-mode: true
map-tokens: 2048
encoding: utf-8
Best Practices for Effective AI Pair Programming
- Be specific in your requests. Instead of "fix the bug", describe the expected vs. actual behavior and which files are involved.
- Add only relevant files. Including too many files wastes tokens and can confuse the model. Add files incrementally as needed.
- Review each commit. Use
/diffafter every change to verify the AI's work before moving on. - Use
/runfor feedback loops. Run tests or linters and share the output so Aider can fix issues iteratively. - Leverage the repository map. Aider automatically creates a map of your codebase to understand file relationships, but you can adjust the token budget with
--map-tokens.
Cost Management
Aider provides built-in cost tracking. Use the /tokens command to monitor usage during a session. For teams, an API relay service like claude4u.com offers centralized billing and usage dashboards, making it easy to track costs across multiple developers and projects. Setting token limits and choosing the right model size for each task are the most effective ways to control costs while maintaining productivity.
Aider is a remarkable tool that brings AI pair programming to its most natural form — a conversation in your terminal. With the right model backend and a reliable API connection, it can significantly accelerate your development workflow.
Get Started with 轻舟 AI
Stable, fast AI API relay — supports Claude, OpenAI, Gemini and more
Sign Up Free
轻舟 AI