Aider — AI Pair Programming in Your Terminal (2026 Guide)
Advertisement
Introduction
Why This Matters
Most AI coding tools require a GUI IDE. Aider does not. It runs entirely in your terminal, reads your project files, makes changes, and commits them to git — all through a chat interface in your shell. For developers who live in the terminal, work over SSH, or prefer keyboard-driven workflows, Aider is the natural fit. It is open source, model-agnostic, and you pay only for the API tokens you use.
How Aider Works
Aider operates in a REPL-style chat loop. You tell it which files to work with, then describe what you want in plain English. Aider sends the file contents and your instruction to the configured LLM, receives a diff, applies it to the files, and commits the change to git automatically.
The entire interaction looks like a conversation:
$ aider src/auth.py tests/test_auth.py
Aider v0.42.0, using claude-sonnet-4-5 model.
> Add JWT token validation to the login endpoint.Aider then shows a diff and asks for confirmation before writing.
Installation
pip install aider-chat
# Verify installation
aider --versionSet your API key as an environment variable:
export ANTHROPIC_API_KEY=sk-ant-...
# or
export OPENAI_API_KEY=sk-...Or create a config file at ~/.aider.conf.yml:
model: claude-sonnet-4-5
anthropic-api-key: sk-ant-...
auto-commits: trueStarting a Session
# Open specific files
aider src/api.py src/models.py
# Open all Python files in a directory
aider src/**/*.py
# Start with a specific model
aider --model gpt-4o src/api.py
# Dry run — show diffs without writing
aider --dry-run src/api.pyReal Workflow Example
Here is a complete session adding authentication to a Flask API:
$ git checkout -b feature/jwt-auth
$ aider src/app.py src/auth.py requirements.txt
> Add JWT authentication. Users should log in with email and password
> and receive a token. Protected routes should require a valid token.
Aider: I'll add JWT authentication. Here are the changes:
--- src/auth.py
+++ src/auth.py
@@ -0,0 +1,42 @@
+import jwt
+import datetime
+from functools import wraps
+from flask import request, jsonify
+
+SECRET_KEY = "your-secret-key"
+
+def generate_token(user_id: int) -> str:
+ payload = {
+ "user_id": user_id,
+ "exp": datetime.datetime.utcnow() + datetime.timedelta(hours=24)
+ }
+ return jwt.encode(payload, SECRET_KEY, algorithm="HS256")
+
+def require_auth(f):
+ @wraps(f)
+ def decorated(*args, **kwargs):
+ token = request.headers.get("Authorization", "").replace("Bearer ", "")
+ if not token:
+ return jsonify({"error": "No token provided"}), 401
+ try:
+ payload = jwt.decode(token, SECRET_KEY, algorithms=["HS256"])
+ request.user_id = payload["user_id"]
+ except jwt.ExpiredSignatureError:
+ return jsonify({"error": "Token expired"}), 401
+ except jwt.InvalidTokenError:
+ return jsonify({"error": "Invalid token"}), 401
+ return f(*args, **kwargs)
+ return decorated
Apply these changes? (y/n): y
Applied. Committed: "Add JWT authentication middleware"Git Integration
Every change Aider makes is committed automatically (configurable). This gives you a clean audit trail:
git log --oneline
# a3f1b2c Add JWT authentication middleware
# 9d4e5f1 Add input validation to user registration
# 7c8a9b0 Initial commit
# Undo last Aider change
git revert HEADThe --no-auto-commits flag disables auto-commit if you prefer to commit manually.
Using Aider with Local Models via Ollama
# Start Ollama
ollama serve
# Run Aider with a local model
aider --model ollama/llama3 src/utils.pyLocal models are slower and produce lower quality output but keep all code on your machine.
In-Chat Commands
While in a session, Aider supports special commands:
| Command | Action |
|---|---|
| /add filename | Add a file to the session |
| /drop filename | Remove a file from the session |
| /undo | Undo the last change and commit |
| /diff | Show pending changes |
| /run command | Run a shell command and show output |
| /tokens | Show token usage so far |
| /quit | Exit the session |
Common Mistakes
- Including too many files: Aider sends all session files to the LLM on every message. Keep sessions focused on 3-5 files to control cost and latency.
- Vague prompts: "Improve this" produces generic output. "Add input validation that raises ValueError if email is not a valid format" produces precise, usable code.
- Not reviewing diffs: Aider auto-commits by default. Read every diff before accepting — use
--dry-runwhile learning. - Forgetting to add test files: Include your test file in the session so Aider writes tests alongside the implementation.
Best Practices
- Start a new git branch before each Aider session — easy to squash or abandon
- Include test files in the session so Aider writes tests alongside implementation code
- Use
--dry-runthe first time you run a new type of task to see what Aider would do - Run your test suite after each Aider commit:
aiderthen/run pytest - For large refactors, break the work into multiple focused sessions rather than one giant prompt
Key Takeaways
- Aider is a free, open-source terminal AI pair programmer that works with Claude, GPT-4, and local models
- It runs in a REPL chat loop, applies diffs to files, and auto-commits changes to git
- Every Aider change gets its own git commit, making it trivial to review or revert AI-generated code
- Focused sessions with 3-5 files produce better and cheaper results than large multi-file sessions
- The
--dry-runflag shows diffs without applying them — essential for learning and auditing - Aider works perfectly over SSH, making it the best AI coding tool for remote server work
- Including test files in the session causes Aider to write tests automatically alongside new code
- You pay only for the API tokens consumed — typical sessions cost 0.50 depending on complexity
Advertisement