How to use Aider for AI pair programming in the terminal

Aider is an open-source terminal tool that uses LLMs to edit your code directly. Unlike IDE plugins, Aider understands your full git history and makes commits automatically. This guide covers setup, the file context system, and effective workflows.

What makes Aider different

Aider operates from the terminal alongside your existing editor. It reads files you specify, makes targeted edits, and commits the changes to git with a descriptive message — automatically. This tight git integration means every AI change is tracked, diffable, and easily reversible.

Aider supports all major LLMLLMLarge Language Model — a neural network trained on vast amounts of text data that can understand and generate human-quality language across a wide range of tasks.Learn more → providers and local models. It maintains a leaderboard of models ranked by their code editing ability — Claude Sonnet consistently tops it, but GPTGPTGenerative Pre-trained Transformer — the model architecture and family name behind OpenAI's most famous models, from GPT-2 to GPT-5.Learn more →-4o and Gemini 2.5 Pro are competitive alternatives.

Install and authenticate

Install via pip: `pip install aider-install && aider-install`. Then run `aider` in your project directory. On first run it will promptPromptThe input text sent to a language model — the question, instruction, or context that triggers a response.Learn more → for your API key. Set it with: `export ANTHROPIC_API_KEY=sk-ant-...` for Claude, or `export OPENAI_API_KEY=sk-...` for GPT-4o.

Aider defaults to Claude Sonnet. To use a different model: `aider --model gpt-4o` or `aider --model ollama/llama3.3`. For best results on coding tasks, stick with Claude Sonnet or GPT-4o-mini for simpler changes.

The /add command and file context

Aider needs to know which files it is allowed to edit. Use `/add <filename>` to add files to the context. Aider will read their full content and can modify them in response to your instructions. Use `/drop <filename>` to remove files from context when they are no longer relevant.

For large codebases, keep the context focused: add only the files relevant to the current task. Adding too many files wastes tokens and can confuse the model about which files to modify. Aider's `--map-tokens` option creates a compressed repository map that helps the model understand the broader codebase without reading every file.

Making changes and reviewing diffs

Type your request in natural language: 'Add input validation to the create_user function that checks for a valid email format and raises a ValueError with a descriptive message.' Aider will propose changes, show a diff, and apply them to the file.

Aider makes a git commit after each successful change. If a change looks wrong, undo it with `/undo` — this reverses the git commit and restores the previous state. This makes it safe to experiment: every change is tracked and reversible.

Run tests automatically

Aider can run your test suite after each change with the `--test-cmd` flag: `aider --test-cmd 'pytest tests/' --auto-test`. When tests fail, Aider automatically reads the failure output and tries to fix the code — iterating until tests pass or it runs out of ideas.

This test-driven loop is one of Aider's most powerful features. Write the failing test first, add both the test and the source file to context, and ask Aider to 'make the tests pass'. It will implement whatever is needed.