ruk·si

Aider

Updated at 2025-02-24 03:11

Aider is a terminal-based AI assistant for code generation.

Compared to full-fledged AI IDEs, Aider has more of a learning curve but is more flexible./ / Compared to auto-completion tools, Aider is more powerful but requires more user input.

I use mise for most of my tools so:

# https://mise.jdx.dev/dev-tools/backends/pipx.html
mise use -g pipx:aider-chat
# this upgrades ~/.config/mise/config.toml 

Configure Aider:

vim ~/.aider.conf.yml
# https://aider.chat/docs/config/aider_conf.html
dark-mode: true
analytics-disable: true

auto-commits: false
attribute-author: false
attribute-committer: false

# https://aider.chat/docs/leaderboards/
model: r1
editor-model: sonnet

# You need to have the API keys defined somewhere when you run `aider`
#     https://aider.chat/docs/config/api-keys.html
#     https://platform.deepseek.com/api_keys
# DEEPSEEK_API_KEY=???
# ANTHROPIC_API_KEY=???
#
# I store them with the projects so billing goes to the right place.

Usage

cd ~/path/to/my/project
aider

Aider has three main chat modes:

  • /code (default) make changes according to prompts
  • /architect returns proposals before making changes
  • /ask discuss about the code without making changes

In general, architect mode is more powerful but requires more user input and is more expensive.

Aider indexes your file structure and high level code structure like classes and function/method signatures.

You can use /ls, /map and /copy-context to see the current context.

For Aider, to understand specific aspects of your code base better, you must add files to the context.

# mark files as related to the task but don't expect changes in them
/read-only <file1> <file2> ...

# mark files as probably the ones that should be edited
/add <file1> <file2> ...

# remove files from the context
/drop <file1> <file2>

The concept of "context" is important and nuanced. This is because most modern models don't have infinite information that they can effectively keep track of. Thinking about your context is a balancing act; smaller context is less expensive and better focused while larger context gives more absolute information to the model.

You can see the size of your context with /tokens

Specify conventions and extra information about the project through .aider.conf.yml in the project.

read:
  - README.md
  - CONVENTIONS.md

If you have something that the model might not know like a new library feature, you can add the web documentation to the context:

/web            Scrape a webpage, convert to markdown and send in a message

You frequently want to run stuff:

/run            Run a shell command and optionally add the output to the chat (alias: !)
/test           Run a shell command and add the output to the chat on non-zero exit code
                # you can configure the test command through .aider.conf.yml `test-cmd:`

If you are done with a certain task:

/clear          Clear the chat history
/reset          Drop all files and clear the chat history

With IDEs

Aider doesn't truly integrate with IDEs, but you can make it act on comments:

aider --watch-files
function factorial(n) // Implement this. AI!


# AI: Refactor this code...
# ... into to a compute_factorial() function. AI?


# Make these changes: AI!
# - Add a proper main() function
# - Use Click to process cmd line args
# - Accept --host and --port args
# - Print a welcome message that includes the listening url