AD SPACE AVAILABLE · BRAND PARTNERS WELCOME

Configuring Aider with Automated Linting to Self-Repair Syntax Errors Before Git Commits

Lam Mui Teng · 365Finds Editorial
Indexed 88,650 Wiki articles

Put 365 Wiki to work with your AI

Copy the prompt below, paste it into the AI you already use, then ask your question.

Download full Skill

Try it with the prompt first. If you use 365 Wiki often, install the full 365Wiki Skill so you do not have to paste it again. No regular AI? Gemini or Microsoft Copilot on the web will work.

365Wiki Skill

Most AI coding assistants vomit broken syntax straight into your working tree and leave you to clean up the mess. Missing imports, unclosed brackets, TypeScript type mismatches, and undefined variables end up polluting your Git history with embarrassing fix-up commits. Aider takes an entirely different philosophical stance: it treats the local terminal and Git repository as a closed feedback loop. If the model generates code that fails your project's syntax or style rules, Aider catches the error, feeds the diagnostic output directly back to the LLM, and forces it to repair the code before committing anything to Git.

At 365Finds, we consider Aider's automated linting loop one of the few genuinely indispensable agentic workflows in software development today. However, leaving Aider on its default settings leaves substantial value on the table. Here is how to configure --lint-cmd, wire up language-specific linters, avoid common formatter trapdoors, and lock the workflow into repository-level configuration.


How Aider's Self-Repair Loop Works

By default, Aider operates with --auto-lint enabled. Whenever the model applies an edit to any file in your repository, Aider executes a validation pass before invoking git commit.

The execution chain unfolds in five distinct steps:

  1. Diff Application: The LLM outputs an edit block; Aider writes the changes to disk.
  2. Linter Execution: Aider runs either its built-in Tree-sitter parser or your configured --lint-cmd against the touched files.
  3. Exit Code Evaluation: If the linter exits with code 0, Aider assumes the syntax is clean and immediately creates a Git commit with an AI-generated commit message.
  4. Diagnostic Feedback: If the linter returns a non-zero exit code, Aider captures the stdout and stderr streams, formats the raw compiler or linter errors into an LLM-friendly diagnostic prompt, and hands it back to the active model.
  5. Self-Correction: The LLM inspects its own errors, issues a corrected diff, and Aider re-runs the linter. This loop repeats until the linter passes or you interrupt the session.

Aider ships with built-in Tree-sitter linters for languages like Python, JavaScript, TypeScript, C++, and HTML. These built-in checks catch basic structural syntax errors without requiring external binaries. But 365Finds does not recommend relying on Tree-sitter alone: it will catch an unclosed parenthesis, but it will completely ignore missing imports, undefined variables, and broken type signatures.


Step 1: Configuring Custom Linters with --lint-cmd

To turn Aider into a strict code gatekeeper, you must override or augment the built-in linters with your actual production CLI tooling.

You pass custom linter commands using the --lint-cmd flag. The command must satisfy two rules:

Per-Language Configuration Syntax

If your repository contains multiple languages, specify the target language prefix followed by a colon:

# Single language (Python with Ruff)
aider --lint-cmd "python: ruff check"

# Multiple languages (Python + TypeScript)
aider --lint-cmd "python: ruff check" --lint-cmd "typescript: npx eslint"

When Aider modifies a .py file, it runs ruff check path/to/file.py. When it touches a .ts file, it invokes npx eslint path/to/file.ts. Files belonging to unspecified languages continue using Aider's fallback Tree-sitter parser.

Recommended CLI Linter Commands by Ecosystem

Language / StackRecommended --lint-cmdWhy 365Finds Recommends It
Pythonpython: ruff checkExtremely fast; catches import errors and syntax faults in single-digit milliseconds
TypeScript / JStypescript: npx eslintEnforces type rules and strict linting before code enters staging
Rustrust: cargo checkValidates borrow checker rules and compiler errors before Git commits
Gogo: golangci-lint runAggregates fast static analysis checks across modified Go packages

Step 2: Persisting Configuration in .aider.conf.yml

Typing lengthy command-line arguments on every invocation is error-prone. 365Finds recommends storing your linting configuration directly in a .aider.conf.yml file placed at the root of your Git repository. This ensures every contributor on your team shares the identical automated self-repair pipeline.

Create .aider.conf.yml with the following block:

# .aider.conf.yml

# Ensure auto-lint and auto-commits are active
auto-lint: true
auto-commits: true

# Map language-specific linters
lint-cmd:
  - "python: ruff check"
  - "typescript: npx eslint --no-warn-ignored"
  - "javascript: npx eslint --no-warn-ignored"

# Optional: Run test suites automatically after clean lint passes
auto-test: false
test-cmd: "pytest -q"

If you prefer personal user-level defaults rather than project-specific settings, place this file at ~/.aider.conf.yml. Aider merges settings, giving priority to repository-level configuration over home-directory configuration.


Step 3: Avoiding the Code Formatter Trap

A frequent mistake we see developers make is piping auto-formatters like Black, Prettier, or ruff format directly into --lint-cmd.

Many formatters return a non-zero exit code whenever they rewrite a file to fix indentation or quotes. When Aider sees that non-zero exit code, it assumes a fatal syntax defect occurred. It captures the formatting change notification, sends it back to the LLM, and asks the model to "fix" the issue. The LLM re-edits the code, the formatter runs again, and the session enters an unnecessary token-draining loop.

If you want formatting executed alongside linting, wrap your command in a shell script that exits with 0 on successful formatting, or separate formatting into Git hooks.

For a combined Python setup using Ruff, run Ruff's linter rather than its formatting engine inside Aider:

# Correct: checks syntax and imports, exits 0 on valid code
aider --lint-cmd "python: ruff check"

# Problematic: exits non-zero if code needed reformatting
aider --lint-cmd "python: ruff format --check"

If your project relies on pre-commit, write a lightweight runner script scripts/aider-lint.sh:

#!/usr/bin/env bash
# Run pre-commit hooks on modified files without failing on harmless reformatting
pre-commit run --files "$@"
exit_code=$?

# If pre-commit modified files, re-check once to ensure syntax validity
if [ $exit_code -ne 0 ]; then
  pre-commit run --files "$@" > /dev/null 2>&1
  exit $?
fi

exit 0

Then configure Aider:

lint-cmd:
  - "python: ./scripts/aider-lint.sh"

Step 4: Testing and Validating the Self-Repair Cycle

To verify that your auto-linting pipeline works as expected without waiting for Aider to touch a file during regular chat:

  1. Trigger Manual Linting: Inside an active Aider session, run /lint. Aider immediately runs your configured linter against all files currently loaded in the chat session.
  2. Reviewing Failed Lints: If a file has syntax errors, Aider prints the compiler diagnostic output and asks: Run linter to fix issues? Confirming lets the LLM draft the correction immediately.
  3. Standalone CLI Invocation: From your terminal outside an interactive chat, run:
    aider --lint
    
    Aider scans all "dirty" (uncommitted) files in the Git working directory, applies your configured --lint-cmd, prompts the LLM to fix any identified syntax violations, and commits the clean result.

If you ever need to disable auto-linting temporarily—for instance, during rapid exploratory prototyping where you deliberately tolerate broken syntax—start Aider with the --no-auto-lint flag.

References