CLI

radar fix

AI-powered fix generation that scans for violations and produces per-file diffs with interactive apply.

radar fix

The fix command scans your codebase for violations, generates AI-powered fixes using Claude, and lets you review and apply them interactively. Each fix includes a before/after diff, explanation, and confidence level.

Plan requirement: AI fix generation requires Solo plan or above. Cost: ~$0.003 per fix (1 credit).

Usage

radar fix <path> [options]

Options

FlagDescriptionDefault
-c, --config <path>Path to radar.yml./radar.yml
-r, --rules <path>Path to rules.yml./rules.yml
--severity <level>Only fix: critical or allall
--dry-runShow fixes without applyingfalse
--autoApply all high-confidence fixes without promptingfalse
--file <file>Fix a single file onlyall files
--max-cost <amount>Maximum AI cost in dollars1.00
--api-key <key>Anthropic API key (or ANTHROPIC_API_KEY env var)env var

API Key Setup

The fix command requires an Anthropic API key:

# Set via environment variable (recommended)
export ANTHROPIC_API_KEY=sk-ant-api03-...

# Or pass directly
radar fix . --api-key sk-ant-api03-...

Without an API key, the command falls back to text-only fix instructions (no AI generation).

Example Session

$ radar fix src/

Scanning for violations...
Found 5 violations. Generating AI fixes...

src/events/event.service.ts (2 violations)

  ---
  [perf-unbounded-query] (critical)
  Query on XL table "events" without LIMIT or pagination
  Line 42

  BEFORE:
  - async findAll(): Promise<Event[]> {
  -   return this.prisma.event.findMany();
  - }

  AFTER:
  + async findAll(page = 1, pageSize = 50): Promise<Event[]> {
  +   return this.prisma.event.findMany({
  +     take: pageSize,
  +     skip: (page - 1) * pageSize,
  +     orderBy: { createdAt: 'desc' },
  +   });
  + }

  Adds cursor-based pagination to prevent unbounded queries on XL table.
  Confidence: high

? Apply this fix? (1 violation)
  ❯ Yes - apply this fix
    No - skip
    All - apply all remaining fixes
    Quit - stop fixing

After selecting "Yes":

  Fixed! (1 violation)

  ---
  [reliability-missing-null-guard] (warning)
  Nullable value used without check
  Line 58

  BEFORE:
  - const event = await this.prisma.event.findUnique({ where: { id } });
  - return event.title;

  AFTER:
  + const event = await this.prisma.event.findUnique({ where: { id } });
  + if (!event) {
  +   throw new NotFoundException(`Event ${id} not found`);
  + }
  + return event.title;

  Adds null guard to prevent runtime crash when event is not found.
  Confidence: high

? Apply this fix? (1 violation) Yes - apply this fix
  Fixed! (1 violation)

═══════════════════════════════════════
  FIX SUMMARY
═══════════════════════════════════════
  Fixed:   4
  Skipped: 1
  AI cost: $0.015

Re-scanning to verify fixes...

  Violations: 5 -> 1 (-4)
  Debt score: 28 -> 3

  1 violations remaining. Run radar fix again or fix manually.

Grouped Fixes

When multiple violations occur on the same line, the fix command groups them into a single AI call. This produces a combined fix that addresses all issues at once:

  ---
  [runtime-sync-fs] (critical)
  Synchronous file read in request handler
  [reliability-missing-try-catch] (warning)
  Missing error handling around file operation
  Line 23 (2 violations grouped)

  BEFORE:
  - const config = readFileSync('./config.json', 'utf-8');
  - const parsed = JSON.parse(config);

  AFTER:
  + let parsed: Config;
  + try {
  +   const config = await readFile('./config.json', 'utf-8');
  +   parsed = JSON.parse(config);
  + } catch (error) {
  +   throw new InternalServerErrorException('Failed to load config');
  + }

Dry Run

Preview all fixes without modifying any files:

$ radar fix src/ --dry-run

  BEFORE:
  - return this.prisma.event.findMany();

  AFTER:
  + return this.prisma.event.findMany({ take: 100 });

  [dry-run] Would apply this fix

Auto Mode

Apply all high-confidence fixes without prompting. Useful in CI or when you trust the AI output:

$ radar fix src/ --auto

Only fixes with confidence: high are auto-applied. Medium and low confidence fixes still prompt for confirmation.

Cost Control

Set a ceiling on AI spending per run:

# Stop after $0.50 in API costs
radar fix src/ --max-cost 0.50

When the ceiling is reached:

  Cost ceiling reached ($0.50). Stopping AI fixes.

Each fix costs approximately $0.003. A typical scan with 20 violations costs ~$0.06.

Fix a Single File

Target one file to reduce scope and cost:

radar fix src/ --file src/events/event.service.ts

Critical Only

Skip warnings and focus on blocking violations:

radar fix src/ --severity critical

Without API Key

When no API key is available, the command outputs text-based fix instructions instead of AI-generated diffs:

$ radar fix src/

No API key found.
  Set ANTHROPIC_API_KEY environment variable
  Or use: radar fix --api-key sk-ant-...

Without AI, showing fix instructions only:

Fix these issues in my codebase:

1. In src/events/event.service.ts line 42:
   Add pagination: findMany({ take: 100, skip: offset })

2. In src/orders/order.handler.ts line 18:
   Replace readFileSync with readFile (async)

Re-scan After Fixes

After applying fixes, the command automatically re-scans to verify the violations are resolved and reports the before/after delta:

Re-scanning to verify fixes...

  Violations: 12 -> 3 (-9)
  Debt score: 38 -> 8

  3 violations remaining. Run radar fix again or fix manually.

When all violations are resolved:

  Violations: 5 -> 0 (-5)
  Debt score: 18 -> 0

  All violations fixed! Code is clean.
Technical Debt Radar Documentation