AI Features

AI PR Comments

How Technical Debt Radar posts AI-generated explanations of the top 5 violations as comments on your pull requests, with impact analysis and fix suggestions.

AI PR Comments

When a pull request is analyzed, Radar can post an AI-generated comment that explains the top 5 most severe violations in context. Each explanation includes why the violation matters, its production impact, and a concrete fix suggestion --- all formatted for your platform.

Plan requirement: AI PR Comments require the Pro plan or higher. Solo and Free plans receive deterministic PR comments (violation list without AI explanations).

How It Works

  1. Radar's deterministic analysis runs on the PR's changed files and produces a ranked list of violations
  2. The top 5 violations (by severity and debt points) are selected
  3. For each violation, Radar sends the code context to Claude Sonnet with a prompt requesting:
    • A plain-language explanation of what the code does wrong
    • The production impact (what would happen if this reached production)
    • A specific fix suggestion with code
  4. Radar formats the response as a single PR comment and posts it via the GitHub or GitLab API
PR opened/updated
  → Deterministic scan (7 analyzers)
    → Top 5 violations selected
      → Claude API (batch request)
        → PR comment posted

Example PR Comment

## Technical Debt Radar — 3 violations found

### ❌ Gate: FAIL — 2 blocking violations

---

**1. sync-fs-in-handler** · `src/orders/order.service.ts:42` · Critical

You're using `fs.readFileSync` inside a `@Get()` handler. This blocks the
Node.js event loop for the duration of the file read. Under load (100+
concurrent requests), this creates a cascading timeout: every request queues
behind the file read, response times spike from 50ms to 5s+, and health
checks start failing.

**Fix:** Replace with `await fs.promises.readFile()`:
```ts
const template = await fs.promises.readFile('./templates/export.html', 'utf-8');

2. unbounded-query · src/orders/order.repository.ts:18 · Critical

prisma.order.findMany() with no take or where clause on a table you've declared as XL (1M+ rows). This generates SELECT * FROM orders — a query that will return every row in the table. At 1M rows, this consumes ~2GB of memory and takes 15–30 seconds, during which the connection pool slot is occupied.

Fix: Add pagination:

const orders = await prisma.order.findMany({
  take: 100,
  skip: offset,
  where: filters,
});

3. fire-and-forget · src/notifications/notify.service.ts:31 · Warning

sendEmail(user.email) is called without await and without .catch(). If this promise rejects, it becomes an unhandled rejection — which in Node.js 15+ terminates the process by default.

Fix: Either await it or attach an error handler:

await sendEmail(user.email);
// or
sendEmail(user.email).catch(err => this.logger.error('Email failed', err));

## Platform-Aware Formatting

Radar detects your platform and adjusts comment formatting accordingly:

| Platform | Formatting |
|---|---|
| **GitHub** | GitHub-flavored Markdown with collapsible `<details>` sections for long explanations, syntax-highlighted code blocks, and permalink line references |
| **GitLab** | GitLab-flavored Markdown with `/code` blocks, merge request discussion threading, and GitLab-style file references |

The comment is posted as a single top-level comment (not inline annotations) to avoid notification noise. It is updated in place on subsequent pushes to the same PR --- Radar edits the existing comment rather than creating new ones.

## Cost

Each AI PR comment consumes **3 credits** per PR analysis. This covers the Claude API cost of analyzing and explaining 5 violations with full code context, at approximately **$0.035 per PR**.

Credits are consumed when the PR comment is generated, not when it is posted. If the same PR is re-analyzed after a new push, another 3 credits are consumed for the updated comment.

## What Gets Sent to the AI

For each of the top 5 violations:

- The violating code with surrounding context (approximately 50 lines)
- The violation rule ID, severity, and category
- The file path and line number
- Table size declarations from `radar.yml` (for performance violations)

Your full codebase, secrets, environment variables, and other files are never sent.

## Configuring AI PR Comments

AI PR comments are enabled by default on Pro+ plans. You can disable them in `radar.yml`:

```yaml
ai:
  pr_comment: false    # Disable AI explanations (deterministic comment still posted)

Or configure the number of violations explained:

ai:
  pr_comment: true
  pr_comment_top_n: 3  # Explain top 3 instead of top 5
Technical Debt Radar Documentation