Aider

raw JSON →
0.86.2 verified Sun Apr 12 auth: no python

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.

pip install aider-chat
error ModuleNotFoundError: No module named 'aider'
cause This error occurs when the 'aider' module is not installed or not accessible in the current Python environment.
fix
Ensure that 'aider-chat' is installed in your environment by running 'pip install aider-chat'. If the issue persists, consider installing 'aider' in an isolated environment using 'pipx' or 'uv' to avoid dependency conflicts. ([aider.chat](https://aider.chat/docs/troubleshooting/imports.html?utm_source=openai))
error ImportError: No module named 'aider'
cause This error indicates that the 'aider' module cannot be found, possibly due to an incorrect installation or the module not being in the Python path.
fix
Verify that 'aider-chat' is installed by running 'pip show aider-chat'. If it's not installed, install it using 'pip install aider-chat'. To prevent package conflicts, consider using 'pipx' or 'uv' for installation. ([aider.chat](https://aider.chat/docs/troubleshooting/imports.html?utm_source=openai))
error ModuleNotFoundError: No module named 'litellm'
cause This error occurs when the 'litellm' module, a dependency of 'aider', is missing or not installed correctly.
fix
Install the 'litellm' module by running 'pip install litellm'. To ensure all dependencies are correctly installed, it's recommended to install 'aider' in an isolated environment using 'pipx' or 'uv'. ([aider.chat](https://aider.chat/docs/troubleshooting/imports.html?utm_source=openai))
error ImportError: No module named 'openai'
cause This error indicates that the 'openai' module, required by 'aider', is not installed or not accessible in the current environment.
fix
Install the 'openai' module by running 'pip install openai'. To avoid dependency issues, consider installing 'aider' in an isolated environment using 'pipx' or 'uv'. ([aider.chat](https://aider.chat/docs/troubleshooting/imports.html?utm_source=openai))
error ModuleNotFoundError: No module named 'pyperclip'
cause This error occurs when the 'pyperclip' module, a dependency of 'aider', is missing or not installed correctly.
fix
Install the 'pyperclip' module by running 'pip install pyperclip'. To ensure all dependencies are correctly installed, it's recommended to install 'aider' in an isolated environment using 'pipx' or 'uv'. ([aider.chat](https://aider.chat/docs/troubleshooting/imports.html?utm_source=openai))
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.
fix Always explicitly specify your desired model using `aider --model your/model-name ...` to ensure consistent behavior, or regularly check release notes for alias changes.
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.
fix Ensure the correct API key environment variable for your chosen provider is set before running Aider. Refer to the official Aider documentation for specific provider setup instructions (aider.chat/docs/llms.html).
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.
fix Use a Python environment manager (e.g., `pyenv`, `conda`, `venv`) to ensure you are running Aider with a compatible Python version (e.g., Python 3.10, 3.11, or 3.12). For example, `python3.12 -m pip install aider-chat`.

This quickstart demonstrates how to set up a dummy project with a `main.py` file and a git repository, then launch Aider via the command line. Aider operates interactively in your terminal, acting as an AI pair programmer. You'll need to set an API key for your chosen LLM provider (e.g., OpenAI, Anthropic, Gemini) as an environment variable or pass it via CLI arguments. The example uses a `subprocess.run` call to execute Aider, allowing for direct terminal interaction.

# 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}'.")