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.

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
Using a relay service like claude4u.com with Aider gives you access to multiple AI models through a single endpoint. This is especially useful when you want to switch between Claude and GPT models during a session without reconfiguring API keys.

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:

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

  1. Be specific in your requests. Instead of "fix the bug", describe the expected vs. actual behavior and which files are involved.
  2. Add only relevant files. Including too many files wastes tokens and can confuse the model. Add files incrementally as needed.
  3. Review each commit. Use /diff after every change to verify the AI's work before moving on.
  4. Use /run for feedback loops. Run tests or linters and share the output so Aider can fix issues iteratively.
  5. 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.
Aider sends file contents to the AI provider's API. If you are working with sensitive code, use a private API deployment or a trusted relay service that does not log request content. Always check your provider's data retention policies.

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