How to Use Aider to Edit Code From the Terminal

November 12, 2026

Aider is a terminal-based AI pair programmer that reads files from your local git repository, writes changes back as real diffs, and commits them for you. Install it with one pip command, run aider inside a repo, and you are editing code in about three minutes.

The part that matters: Aider works on your files, not a chat buffer. Every edit is a git commit, so git diff and git revert are your undo buttons. That single design choice makes it far less scary than pasting code into a web chat.

What is Aider and what does it need?

Aider is an open-source Python package from Paul Gauthier that pairs a language model with your repository. It runs on macOS, Linux, and Windows via WSL. You need Python 3.9 or newer, git, and an API key from a supported provider (OpenAI, Anthropic, DeepSeek, Gemini, or a local model through Ollama).

First run checklist:

  • Python 3.9+ and pip available in the shell.
  • A git repository. Aider refuses to work well outside one.
  • An API key exported as an environment variable.
  • A model name you know the price of, because costs accumulate per token.

How do you install Aider and start a session?

python -m pip install aider-install
python -m aider_install

Then set your key and start it inside a project:

export ANTHROPIC_API_KEY=sk-...
cd ~/projects/my-app
aider --model sonnet

The --model flag matters more than any other setting. Cheap models save money on trivia and break on multi-file refactors. Pick the strongest model you can afford for architecture work and switch to a lighter one for renaming variables.

How do you tell Aider which files to work on?

Aider only edits files you have added to the chat. This is a safety feature, not a limitation. Add files with /add:

/add src/auth.py src/models.py tests/test_auth.py

Aider shows a token count for the current chat. Watch that number. Once you cross roughly 30,000 tokens on a mid-size model, quality drops and cost climbs. Use /drop to remove files you are done with, or /tokens to see the breakdown.

A trick worth knowing: /add a file, ask a question about it, then /drop it. You get the answer without carrying the file through every later request.

What does Aider actually do on the first edit?

Type a plain request like “make the login endpoint return 401 with a JSON error body instead of redirecting.” Aider replies with a diff. It does not apply it immediately in the default mode; you see the proposed change, then accept or reject.

Once applied, Aider commits automatically with a message it writes. If you dislike that, start with --no-auto-commits, though most people keep the commits: they are small, descriptive, and easy to squash.

Common first-edit failures and fixes:

  • It edits the wrong file. You forgot to /add the target. Aider will say “not in chat” rather than guess.
  • The diff does not apply. Usually stale context. Run /reset and re-add.
  • Changes break tests. Say “run the tests” and Aider executes them, then fixes what failed.

How much does Aider cost to run?

The tool itself is free and open source. You pay the model provider per token, and Aider reports the running session cost after each message.

Real numbers from mid-size repositories: a single-file change with a 10,000-token context costs a few cents on a frontier model. A 60,000-token refactor across five files can cost 40 cents or more in one request because the whole context is resent. Keeping context lean is the main cost lever you control.

LiteLLM support means you can point Aider at local models for zero marginal cost, at the price of noticeably weaker refactor quality.

Who should use Aider and who should not?

It suits developers comfortable in a shell who already use git deliberately. If your workflow is commit-early-commit-often, Aider fits without friction.

It does not suit IDE-first developers who want inline autocomplete and a sidebar chat. Aider has no GUI and no tab completion in the editor. It also frustrates people who work across multiple repositories at once; one session, one repo.

A second caveat: Aider is chatty about its own architecture and will sometimes rewrite a file more broadly than asked. Review the diff before accepting. It is one keystroke, and it has saved me from two bad refactors this year.

Quick Summary

  • Aider is a free, open-source CLI coding assistant that edits files in a git repo and auto-commits changes.
  • Install with python -m pip install aider-install, run aider --model sonnet inside a repo.
  • It only touches files added via /add; keep chat context under about 30,000 tokens.
  • You pay per token to the model provider; a large multi-file refactor can cost tens of cents in one request.
  • Best for terminal-and-git users; not for IDE-centric workflows or multi-repo sessions.
Tags: