← Aider

Aider Cheat Sheet

AI pair programming in your terminal. Works with any git repo and supports GPT-4, Claude, and more.

---

Installation

# pip
pip install aider-chat

pipx (recommended)

pipx install aider-chat

Upgrade

pip install --upgrade aider-chat

---

Core Commands

CommandDescription
aiderStart in current git repo
aider file1.py file2.pyStart with specific files in context
aider --model <model>Choose AI model
aider --no-auto-commitsDisable automatic commits
aider --dark-modeUse dark color scheme
aider --light-modeUse light color scheme
aider --vimEnable vim keybindings
aider --restore-chatRestore previous session
---

Slash Commands (In-Session)

File Management

CommandDescription
/add <file>Add file(s) to context
/drop <file>Remove file(s) from context
/lsList files in context
/read <file>Add file as read-only (referenced but not edited)
/clearRemove all files from context

Git Operations

CommandDescription
/commitCommit current changes with AI-generated message
/commit <message>Commit with custom message
/diffShow unstaged changes
/undoUndo last commit (git reset --soft HEAD~1)
/git <command>Run arbitrary git command

Session Control

CommandDescription
/run <command>Execute shell command and show output
/testRun tests (looks for pytest, npm test, etc.)
/resetReset chat history (keep files in context)
/exitExit aider
/quitExit aider (alias)

Model & Configuration

CommandDescription
/modelShow available models
/model <name>Switch to different model
/architectSwitch to architect mode (plan-first)
/editorSwitch to editor mode (direct edits)
/helpShow all slash commands
/tokensShow token usage
/costShow estimated cost

Advanced

CommandDescription
/voiceEnable voice input (requires whisper)
/pastePaste from clipboard
/web <url>Fetch and add web content to context
/lintRun linter on files
/settingsShow current settings
---

CLI Flags

Model Selection

FlagDescription
--model <name>gpt-4-turbo, claude-3-opus, gpt-3.5-turbo, etc.
--opusUse claude-3-opus (shorthand)
--sonnetUse claude-3.5-sonnet (shorthand)
--4-turboUse gpt-4-turbo (shorthand)
--4oUse gpt-4o (shorthand)
--list-modelsShow all available models

Git Behavior

FlagDescription
--no-auto-commitsDon't auto-commit changes
--auto-testRun tests after each change
--no-dirty-commitsRefuse to edit if repo is dirty
--commit-prompt <template>Custom commit message template

Context & Files

FlagDescription
--read <file>Add file as read-only
--yesAccept all changes without confirmation
--no-streamDon't stream responses (wait for complete answer)
--show-diffsShow diffs before applying changes

UI & Display

FlagDescription
--dark-modeDark color scheme
--light-modeLight color scheme
--no-fancy-inputDisable fancy readline input
--vimEnable vim keybindings
--no-prettyDisable syntax highlighting

Advanced

FlagDescription
--api-key <key>Override API key
--message <prompt>Send prompt and exit (one-shot mode)
--restore-chatResume previous session
--config <file>Use custom config file
--encoding <type>Force token encoding (cl100k_base, etc.)
---

Configuration File (.aider.conf.yml)

Location

Place in project root or ~/.aider.conf.yml for global settings.

Example Configuration

# Model settings
model: claude-3.5-sonnet
edit-format: diff

Git settings

auto-commits: true auto-test: false dirty-commits: false

UI settings

dark-mode: true fancy-input: true vim-mode: true

Cost tracking

show-cost: true

Default files (always include)

files: - src/main.py - src/utils.py

Read-only files (context but not editable)

read: - README.md - docs/api.md

Custom commit prompt

commit-prompt: | Write a concise commit message following conventional commits. Focus on the "why" not the "what".

---

Edit Formats

Aider supports different edit modes:

FormatDescriptionBest For
diffUnified diff formatLarge files, precise edits
wholeReplace entire fileSmall files, major rewrites
udiffUnified diff with contextDefault, balanced approach
Set via CLI:
aider --edit-format diff
Set via config:
edit-format: diff

---

Examples

Basic Usage

# Start with files
aider main.py utils.py

Inside aider:

> Add error handling to the API call in main.py > Write tests for the new error handling > /test > /commit

One-Shot Mode

# Make change and exit
aider --message "Add type hints to all functions" src/api.py

Architect Mode (Plan-First)

aider --architect app.py

> Refactor this to use dependency injection [Aider plans changes, shows plan, gets approval, then applies]

With Read-Only Context

# Include docs as reference but don't edit
aider --read README.md --read docs/api.md src/main.py

Auto-Test Workflow

# Run tests after every change
aider --auto-test tests/test_api.py src/api.py

> Fix the failing authentication test [Aider edits, runs tests automatically, iterates until passing]

---

Git Integration

Auto-Commits

By default, aider commits after each change:
feat: add authentication middleware
  • Added JWT verification
  • Added error handling for invalid tokens

Disable Auto-Commits

aider --no-auto-commits

Then manually: /commit

Custom Commit Messages

# .aider.conf.yml
commit-prompt: |
  Format: <type>(<scope>): <description>
  Types: feat, fix, docs, refactor, test

---

Model Support

Supported Providers

  • OpenAI: gpt-4-turbo, gpt-4o, gpt-3.5-turbo
  • Anthropic: claude-3-opus, claude-3.5-sonnet, claude-3-haiku
  • Local Models: via OpenAI-compatible API

Set API Keys

# OpenAI
export OPENAI_API_KEY="sk-..."

Anthropic

export ANTHROPIC_API_KEY="sk-ant-..."

Cost Tracking

# Show cost estimate
/cost

Enable cost display

aider --show-cost

---

Tips & Best Practices

Context Management

  • Add only files you're actively editing to context
  • Use /read for documentation/reference files
  • Use /drop to remove files when done

Commit Workflow

1. Make changes with aider 2. Review with /diff 3. Test with /run pytest or /test 4. Commit with /commit or custom message

Performance

  • Use --4o for fast, cheap edits
  • Use --opus for complex refactors
  • Use --no-stream for scripting

Safety

  • Enable --no-dirty-commits to prevent editing uncommitted work
  • Use --show-diffs to review before applying
  • Use /undo to revert last commit
---

Troubleshooting

"Repository not found"

# Initialize git first
git init
git add .
git commit -m "Initial commit"

"No API key found"

# Set environment variable
export OPENAI_API_KEY="your-key"

Or use --api-key flag

aider --api-key "your-key"

Context Too Large

# Drop unnecessary files
/drop large_file.py

Use read-only for reference

/read docs.md

Edits Not Applying

  • Try --edit-format diff for better precision
  • Ensure files are tracked by git
  • Check file permissions
---

Resources

  • Official Docs: https://aider.chat/docs/
  • GitHub: https://github.com/paul-gauthier/aider
  • Examples: https://aider.chat/examples/
  • Discord: https://discord.gg/aider