Aider – AI cli tool

Why try anything else than Copilot?

A few months ago, a friend recommended the CLI pair programming tool, Aider, to me. As a cloud engineer and developer, I had already been experimenting with AI-based coding tools like GitHub Copilot, using it for code completion, chat, and its “agent” mode. Once I was able to use an API-based model with my company’s account, I decided to give Aider a try.

In this article, I’ll share my thoughts on Aider, discuss its pros and cons, and walk you through my experience using it to code a small microservice.

How is Aider compared to tools like Github Copilot?

The first thing to know is that Aider is a CLI-based tool, which means you primarily use it in your terminal. This approach comes with some nice advantages:

Flexible IDE Choice

You can use Aider in any coding environment you prefer, such as your operating system’s terminal or your IDE’s integrated terminal.

Faster Workflow

Compared to GUI-based tools, I found a significant boost in my workflow speed. For example, handling different read/edit operations or switching chat modes in Aider can all be done with your keyboard, eliminating the need to use a mouse. Once I got used to this style of interaction, I really appreciated its efficiency.

After installing Aider, you need to set up your API key to connect the tool to your LLM provider. The documentation provides a great starting point for configuration.your LLM provider. The documentation provides a great starting point for configuration.

Chat Modes

After starting Aider, you are start in '/code' mode and will make changes directly to your code to satisfy your request. In Aider you have access to three different chat-modes:

  • /code
  • /architect
  • /ask

If you switch to '/ask' mode with the command:

Aider will never make any changes but gives you its preferred answer or implementation suggestion. In '/architect' mode, the model will make changes to your files like in code mode, but the implementation has a two-step approach: an architect model (e.g. a reasoning model) proposes changes for a more complex request, and an editor model translates that into specific file edits.

To see the available models in Aider, type '/models' and pick the model you like with the '/model' command. Aider can be configured to use different models for the available chat modes. Have a look at the documentation to find the right parameters.

Building Context

Since modern Large Language Models are so capable right now, getting good results for difficult problems becomes more and more a matter of good context. Building context with Aider is really easy. You can add files to the context of your system prompt with '/add'. These files will be edited when Aider thinks this is necessary for solving the problem. If you just want to give Aider information about a file, add it with '/read-only'. The name speaks for itself, I guess. For example, if I want to add additional tests to the test_car.py file and be sure that Aider doesn’t make any changes to your car.py file, make the file read-only.

You can even further enhance the context of your prompt if you add some documentation of a specific library you want to use. This is especially helpful when the library is not so widely used or if you are using an LLM that wasn’t trained on a huge amount of web data. In Aider, you can simply add the webpage containing the needed documentation to the chat window, or you can use '/web' to scrape the page’s content and add it directly to your prompt.

For example, we can ask Aider to give us a summary of all released versions which are present on Aider’s documentation: https://aider.chat/HISTORY.html

Coding Example

We are now able to switch to the '/ask' mode and prompt what we want to be implemented. The cool thing about this mode is that Aider doesn’t start directly implementing my prompt. Instead, it gives me an example of what it thinks is the right solution for my problem or prompt. After that, I can give it the go-ahead with '/code implement' or ask for something to add or change (like I did in the example below).

If you like Aider’s code suggestion, start the implementation by '/code go ahead or whatever you want to write behind the code section.

The console output now shows that Aider is taking its latest suggested implementation and starting to code the Car class, the object instantiation, and some print statements. A commit, including a generated commit message, is created right below. Aider even asks you to run the shell command to test its Python script, and if you want, you can add the output to the chat. This is very helpful if the script execution raises an error, as the output would be used as context input for Aiderto solve the problem.

As the next step, we let Aider code some unit tests in pytest for the Car class. Pytest is currently not installed as a module, and we will see that Aider can solve this without a problem.

Since we are in '/ask' mode, Aider gives us a suggestion of how it would solve the problem. After I agreed, the TestCar class, including the file and commit, is created. We also get the suggestion to run the shell command, which raised a “command not found” error. Even if the workflow is stuck at this point, we have the possibility to intervene and call a new command directly from Aider with the '/run' command:

This command also gives us an error, but Aider now directly suggests to fix the problem. If we hit ENTER, we get a new step list to solve the problem.

I now only ask it to go ahead with all steps and add a note to use the calls for my Apple operating system.

Aider has executed all commands and successfully passed all tests. As you have noticed, we need to manually approve all the steps. This is a default behavior in Aider and can be changed by adding the parameter '--yes-always'.

After the second prompt, we can have a look at our git history and see two commits done by our tool:

If we notice the LLM has done something unexpected, the latest step can be easily undone with '/undo'.

Summary

I had the chance to evaluate Aider in the last months extensively in a work project where I couI had the chance to evaluate Aider extensively in a work project over the last few months, where I coded a Go-based REST API service from scratch. During that time, I used Aider a lot and had the chance to compare it to GitHub CoPilot. Here are my key takeaways from working with Aider:

  • Its tracking of all changes with a deep git integration is a top feature.
  • Having fast and specific manageable context not only gives you transparency; it also enhances the quality of your output.
  • For complex features/subtasks, it is a good practice to ask the LLM in '/ask' mode for its implementation and refine its ideas with your own improvements. After you are satisfied, let the LLM implement the feature step by step. Keep the changes and iterations small.
  • Let Aider implement tests for every feature and execute the tests before a single commit is added by Aider. This can be added via the '--auto-test' parameter or done by yourself.

I hope my first blog post was not too long and you can get some inspiration for the first use of Aider. Feel free to leave a comment or a personal mail if you have questions.



Leave a Reply

Your email address will not be published. Required fields are marked *

Mit der Nutzung dieses Formulars erklärst du dich mit der Speicherung und Verarbeitung deiner Daten durch die Website einverstanden.