AI Features

AI Feedback Loop

How to use Radar's ai-prompt output format to create a feedback loop between AI coding tools and Technical Debt Radar for automated violation fixing.

AI Feedback Loop

Technical Debt Radar integrates with AI coding tools like Claude Code, Cursor, and GitHub Copilot through a dedicated output format. The --format ai-prompt flag produces a report specifically designed to be pasted into an AI assistant, creating a closed loop: code with AI, scan with Radar, fix with AI, verify with Radar.

The Workflow

┌─────────────────────────────────────────────────────────┐
│                   AI Feedback Loop                       │
│                                                         │
│  1. Developer writes code (with or without AI)          │
│       │                                                 │
│       ▼                                                 │
│  2. radar scan --format ai-prompt                       │
│       │                                                 │
│       ▼                                                 │
│  3. Report with exact file paths, line numbers,         │
│     fix instructions in AI-readable format              │
│       │                                                 │
│       ▼                                                 │
│  4. Paste report into Claude Code / Cursor / Copilot    │
│       │                                                 │
│       ▼                                                 │
│  5. AI fixes all violations                             │
│       │                                                 │
│       ▼                                                 │
│  6. radar scan — score drops, violations resolved       │
│       │                                                 │
│       ▼                                                 │
│  7. git push — Radar verifies on PR: PASS               │
│                                                         │
└─────────────────────────────────────────────────────────┘

This workflow costs 0 AI credits from Radar --- the --format ai-prompt flag uses only deterministic analysis. The AI processing happens in your own coding tool.

Complete Example

Step 1: Write Code

You have been building an order export feature. Your AI coding tool generated this code:

// src/orders/order.controller.ts
@Get('export')
async exportOrders(@Res() res: Response) {
  const template = fs.readFileSync('./templates/export.html', 'utf-8');
  const orders = await this.prisma.order.findMany();
  sendExportEmail(user.email);
  // ... render and return
}

Step 2: Run Radar with AI-Prompt Format

$ radar scan . --format ai-prompt

Output:

=== TECHNICAL DEBT RADAR — AI FIX INSTRUCTIONS ===

You are fixing technical debt violations in a Node.js/TypeScript codebase.
For each violation below, apply the exact fix described. Do not change
any other code. Preserve all existing functionality.

---

VIOLATION 1 of 3
Rule: sync-fs-in-handler
Severity: CRITICAL (blocks merge)
Category: Runtime Risk
File: src/orders/order.controller.ts
Line: 42

PROBLEM: fs.readFileSync() is called inside a @Get() request handler.
This blocks the Node.js event loop for the duration of the file read.
Under concurrent load, this causes cascading timeouts for all requests.

FIX: Replace fs.readFileSync with the async equivalent:
  - Change: fs.readFileSync('./templates/export.html', 'utf-8')
  - To:     await fs.promises.readFile('./templates/export.html', 'utf-8')
  - The containing function is already async, so no signature change needed.

---

VIOLATION 2 of 3
Rule: unbounded-query
Severity: CRITICAL (blocks merge)
Category: Performance
File: src/orders/order.controller.ts
Line: 43

PROBLEM: prisma.order.findMany() is called with no take, skip, or
where clause. The orders table is declared as XL (1M+ rows) in radar.yml.
This generates SELECT * FROM orders, returning all rows.

FIX: Add pagination parameters:
  - Change: await this.prisma.order.findMany()
  - To:     await this.prisma.order.findMany({ take: 100, skip: offset, where: filters })
  - Add offset and filters parameters to the handler method signature
  - Add @Query() decorators for pagination inputs

---

VIOLATION 3 of 3
Rule: fire-and-forget
Severity: WARNING
Category: Reliability
File: src/orders/order.controller.ts
Line: 44

PROBLEM: sendExportEmail(user.email) is called without await and without
.catch(). If this promise rejects, it becomes an unhandled rejection.

FIX: Add await or a catch handler:
  - Option A: await sendExportEmail(user.email);
  - Option B: sendExportEmail(user.email).catch(err => this.logger.error('Export email failed', err));

---

SUMMARY: 3 violations (2 critical, 1 warning). Fix all critical
violations to unblock the PR merge gate. Current debt score: 42.
Expected score after fixes: 21.

=== END RADAR REPORT ===

Step 3: Paste Into AI Coding Tool

Copy the entire output and paste it into Claude Code, Cursor, or any AI coding assistant:

> Fix these violations in my codebase:
>
> [paste radar output here]

The AI tool reads the exact file paths, line numbers, and fix instructions, then applies all changes.

Step 4: Verify With Radar

$ radar scan .

Technical Debt Radar v1.1.0
Scanning src/ ... done (1.2s)

Results:
  Architecture:    0 violations  ✓
  Runtime Risk:    0 violations  ✓
  Performance:     0 violations  ✓
  Reliability:     0 violations  ✓
  Maintainability: 1 warning     ✓

Debt Score: 21 → 3 (−18 points)
Gate: PASS

Step 5: Push and Merge

$ git add -A && git commit -m "fix: resolve radar violations in order export"
$ git push

# PR gate check passes automatically
# ✅ Radar: PASS — 0 blocking violations

Format Details

The ai-prompt format is designed for maximum AI comprehension:

  • Exact file paths --- absolute or repo-relative, matching your filesystem
  • Exact line numbers --- pinpointing the violating statement
  • Rule IDs --- machine-readable identifiers for each violation type
  • Before/after examples --- showing the exact code to change and what to change it to
  • No ambiguity --- instructions use imperative language ("Change X to Y") rather than suggestions
  • Score prediction --- expected debt score after all fixes are applied

Combining with radar fix

You can use both approaches:

  • radar fix uses Radar's own Claude API integration with your credits --- no copy-paste needed, interactive review
  • --format ai-prompt uses your own AI tool's API --- no Radar credits consumed, batch processing

For most developers, --format ai-prompt with Claude Code or Cursor is the fastest workflow because it fixes all violations in a single pass without interactive confirmation.

Technical Debt Radar Documentation