AI Features

AI Fix Generation

How radar fix uses Claude Sonnet to generate exact code diffs that resolve technical debt violations, and how to review and apply them.

AI Fix Generation

radar fix sends each violation's context and surrounding code to Claude Sonnet and receives back an exact code diff that resolves the issue. Fixes are generated per-file, reviewed interactively, and applied only with your confirmation.

Plan requirement: AI Fix Generation requires the Solo plan or higher. Free plan users can run radar scan to identify violations but must fix them manually.

How It Works

  1. radar scan runs deterministic analysis and produces a list of violations with file paths, line numbers, and rule IDs
  2. radar fix takes each violation and builds a prompt containing:
    • The violation type, severity, and rule description
    • The violating code with 30 lines of surrounding context
    • The file's import statements and exports
    • Your radar.yml policy (relevant sections only)
  3. Claude Sonnet returns an exact code diff in unified diff format
  4. Radar displays the diff for your review
  5. You accept, skip, or reject each fix
Violation → Context extraction → Claude API → Code diff → Review → Apply

Each file is processed independently. A fix for one file never modifies another file.

Usage

# Fix all violations in the current directory
radar fix .

# Fix violations in a specific directory
radar fix src/orders/

# Fix a single file
radar fix src/orders/order.service.ts

# Dry run — show fixes without applying
radar fix . --dry-run

Example

Given this violation:

// src/orders/order.service.ts — Line 42
// VIOLATION: sync-fs-in-handler (runtime-risk, critical)
@Get('export')
async exportOrders(@Res() res: Response) {
  const template = fs.readFileSync('./templates/export.html', 'utf-8');
  const orders = await this.orderRepo.findAll();
  // ...
}

Running radar fix src/orders/order.service.ts produces:

--- a/src/orders/order.service.ts
+++ b/src/orders/order.service.ts
@@ -42,7 +42,7 @@
 @Get('export')
 async exportOrders(@Res() res: Response) {
-  const template = fs.readFileSync('./templates/export.html', 'utf-8');
+  const template = await fs.promises.readFile('./templates/export.html', 'utf-8');
   const orders = await this.orderRepo.findAll();

The CLI then prompts:

Fix 1/3: sync-fs-in-handler in order.service.ts:42
  Replace fs.readFileSync with fs.promises.readFile

  Apply this fix? [y]es / [n]o / [v]iew full diff / [q]uit

What Gets Sent to the AI

For each violation, Radar sends:

  • Rule metadata --- rule ID, severity, category, description
  • Violating code --- the exact lines flagged, plus 30 lines of context above and below
  • File imports --- all import statements in the file
  • Policy excerpt --- the relevant section of your radar.yml (e.g., layer definitions for architecture violations)

Radar does not send your entire codebase, other files, or any secrets. The context window per fix is typically 100--200 lines of code.

Cost

Each fix consumes 1 AI credit, regardless of the violation type or code complexity. At the default API pricing, this costs approximately $0.003 per fix.

A scan that finds 12 violations and you choose to fix all 12 consumes 12 credits.

Limitations

  • Fixes are per-file only. Cross-file refactors (e.g., moving a function to a different layer) require manual intervention.
  • Fixes are suggestions. Always review the diff before applying --- the AI may occasionally produce a fix that changes behavior.
  • Generated fixes do not automatically run your test suite. Run npm test after applying fixes to verify correctness.

CLI Options

FlagDescription
--dry-runShow generated fixes without applying them
--config <path>Path to radar.yml
--rules <path>Path to rules.yml
--format jsonOutput fixes as JSON instead of interactive prompts
--severity criticalOnly generate fixes for critical-severity violations
Technical Debt Radar Documentation