Aider
Aider is an AI pair programming tool that allows you to chat with an AI model directly in your terminal, making it easy to edit code in your local git repository. It integrates with various LLM providers (OpenAI, Anthropic, Gemini, OpenRouter, etc.) and supports many programming languages. The current version is 0.86.2, with active development and frequent releases focusing on new model support and user experience improvements.
Warnings
- gotcha Aider frequently updates its default model aliases (e.g., `gemini`, `flash`, `sonnet`, `opus`) and provider priorities across releases. This can lead to users unintentionally using different models or providers than expected if they don't explicitly specify their desired model with the `--model` flag.
- gotcha Aider requires API keys for LLM providers (e.g., OpenAI, Anthropic, Google Gemini, OpenRouter) to function. These keys must be configured correctly, typically as environment variables (e.g., `OPENAI_API_KEY`, `ANTHROPIC_API_KEY`, `GEMINI_API_KEY`, `OPENROUTER_API_KEY`). Misconfiguration or missing keys will prevent Aider from communicating with LLMs.
- breaking Aider has strict Python version requirements, currently `Python >=3.10, <3.13`. Installing or running Aider with unsupported Python versions (e.g., Python 3.9 or Python 3.13+) will lead to installation failures, dependency conflicts, or runtime errors as indicated by pip's `Requires-Python` metadata.
Install
-
pip install aider-chat
Quickstart
# 1. Set your API key (e.g., OpenAI, Anthropic, Gemini, OpenRouter)
# For OpenAI, set OPENAI_API_KEY. For other providers, check Aider docs.
# export OPENAI_API_KEY="sk-..." (Linux/macOS)
# $env:OPENAI_API_KEY="sk-..." (PowerShell)
import os
import subprocess
import shutil
# Using a dummy key for demonstration; replace with your actual key
openai_api_key = os.environ.get('OPENAI_API_KEY', 'sk-xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx')
if not openai_api_key.startswith('sk-'):
print("WARNING: OPENAI_API_KEY not set or invalid. Aider will likely fail without a valid key.")
# Create a dummy project directory and a file to edit
project_dir = "aider_quickstart_project"
if os.path.exists(project_dir):
shutil.rmtree(project_dir) # Clean up previous run
os.makedirs(project_dir)
os.chdir(project_dir)
with open("main.py", "w") as f:
f.write("def hello_world():\n print('Hello')\n")
# Initialize a git repo (Aider works best with git)
subprocess.run(["git", "init", "-b", "main"], check=True, capture_output=True)
subprocess.run(["git", "add", "main.py"], check=True, capture_output=True)
subprocess.run(["git", "commit", "-m", "Initial commit"], check=True, capture_output=True)
print(f"\nCreated '{project_dir}/main.py' and initialized git. Now launching Aider...\n")
print("To interact, type your requests into the terminal. E.g., 'Add 'world!' to the print statement.'")
print("Type '/help' for Aider commands, or '/exit' to quit.\n")
# Run Aider. The user will interact with it in the terminal.
# Use a model alias like 'gpt-4o' if OPENAI_API_KEY is set.
# Set environment variables for the subprocess call.
# Note: This will block until Aider exits.
result = subprocess.run(
["aider", "--model", "gpt-4o", "main.py"],
env={**os.environ, 'OPENAI_API_KEY': openai_api_key},
check=False # Aider might exit with non-zero if user cancels, etc.
)
print(f"\nAider process exited with code {result.returncode}.")
print(f"Check '{os.path.join(project_dir, 'main.py')}' for changes.")
# Clean up (optional)
os.chdir("..")
shutil.rmtree(project_dir)
print(f"Cleaned up '{project_dir}'.")