Using AI tools in the CLI


As the programming landscape changes I’ve been going through a variety in tools I use for creating digital products.

I’ve been going from simple copying & pasting to one of the big LLM services, to using one of their ready made editors, to using Emacs plugins gpt.el and now using “agent” based CLIs.

I’m now using aider for my LLM assisted programming and getting all the benefits of the ready made solutions.

With aider you can stay in your CLI or favorite text based editor to work via prompts with any of the LLM services (or locally hosted ones)

Demo

I’m using the emacs plugin aider.el but I’ll demonstrate the CLI as well here:

Configuration

You can configure aider like any other CLI tool using a text config in my case I’m using .aider.conf.yml in my home directory.

yaml
some-api-key: xxxx-xxxx-xxxx

In it’s most basic form you’ll just throw in your API key to the LLM services but you can look at the aider configuration docs

Using the CLI

For this simple example I’ll update the copyright notice in the footer of this website.

I’ll start aider by just launching

sh
aider

in a shell located in my repository.

With a prompt like Update the copyright footer to use the current timestamp I dont even need to specify any files as aider will look for

Aider will prompt you to add the files to the chat to do the modifications.

txt
> Update the copyright footer to use the current timestamp
 
To update the copyright footer, I'll likely need to edit:
 
src/components/Footer.astro
 
Please add this file to the chat so I can propose the necessary changes.
 
 
Tokens: 2.9k sent, 34 received. Cost: $0.0091 message, $0.0091 session.
Add src/components/Footer.astro to the chat? (Y)es/(N)o/(D)on't ask again
 [Yes]: Y
I'll update the Footer component to use the current timestamp from the
server-side. Since this is an Astro component, we can use the frontmatter
script section to get the timestamp.
 
src/components/Footer.astro
 
 
 <<<<<<< SEARCH
 ---
 const today = new Date();
 ---
 
 <footer class="my-8 mx-3 text-muted">
   &copy; {today.getFullYear()}
 =======
 ---
 const timestamp = new Date().toLocaleString('en-US', {
   timeZone: 'Europe/Vienna',
   year: 'numeric',
 });
 ---
 
 <footer class="my-8 mx-3 text-muted">
   &copy; {timestamp}
 >>>>>>> REPLACE
 
 
This change will:
 
 1 Replace the simple Date object with a more specific timestamp using
   toLocaleString()
 2 Set the timezone to Vienna (since the site appears to be for Florian
   Schrödl)
 3 Only show the year in the output format
 
The rest of the footer component can remain unchanged as it's working
fine.

Aider will automatically udpate the file and create a commit with a message like chore: Update copyright footer to use localized timestamp

Most of the time I will review the diff in each commit using magit and bundle them together.

In this scenario the change is fine and I’ll accept it.

Using the emacs plugin

With aider.el you can use the same interface with some convinience key bindings in emacs.

I’ve set up the doom emacs bindings that come with aider, but a bit modified for my taste in my emacs config.

Now I can press SPCapa to start aider in any project.

This change introduced a bug which i fixed by just continuing to chat with the same context

Tips

  • You can paste errors just as is to aider and it will attempt to fix them
  • If you set up playwright aider can automatically check the browser for any errors and try to auto-fix them
  • You can combine models by using cheaper ones for the instruction generation with aider --model gemini --architect --editor-model claude-3.7
  • When the context gets too long you can reset it by typing /reset
  • Aider is great for extracting and refactoring code!

On programming with LLMs

Using LLMs for programming are great but to use with caution.

When I’m doing code architecture or anything touching too much logic, I prefer to do it my self, as thinking through the problem creates context and knowledge for you as a developer to solve the problem, which makes fixing your own bugs easier, as LLMs will often create buggy code.

But I do like using these modern tools for quick iterations of visual changes, refactoring and boileplate heavy code. It also gives me great power as I like to work in various languages depending on what I want out of the result.