> For the complete documentation index, see [llms.txt](https://docs.sonarsource.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.sonarsource.com/sonarqube-cli/analysis/ai-remediation.md).

# AI remediation

Use SonarQube CLI to send eligible SonarQube issues to the AI remediation agent and apply suggested fixes from your terminal.

`sonar remediate` asks the [Remediation Agent](/agent-centric-development-cycle/in-your-long-living-branches-the-code-maintenance-loop/remediation-agent.md) to propose a fix for issues it considers *eligible*. You pick which issues to remediate (interactively or by passing their keys), and the CLI returns the agent's suggested change.

> **Note:** Requires a SonarQube Cloud Team or Enterprise plan, or a SonarQube Server 2026.5 Enterprise or Data Center edition, with access to the Remediation Agent.

## When to use it

* You're triaging issues in an existing project and want an AI-generated starting point for a fix.
* You're running an automation pass over a known set of issue keys (for example, the BLOCKERs reported by `sonar list issues`).
* You're working inside Claude Code, Copilot, Codex, Cursor, or Antigravity, where the agent can chain `sonar remediate` after `sonar analyze` to suggest fixes for new findings.

`sonar remediate` is best used for clearly-scoped, well-defined issues (specific rule violations on a single function, for example). For sweeping refactors, treat the agent's output as a suggestion and review it carefully before applying.

## Prerequisites

* [The SonarQube CLI is installed and authenticated](/sonarqube-cli/quickstart-guide.md) against SonarQube Cloud or a SonarQube Server 2026.5 Enterprise or Data Center edition.
* Your organization is subscribed to the SonarQube Remediation Agent.
* You know your project key, or run from a directory where the CLI can auto-detect it (see [Project key auto-detection](/sonarqube-cli/integrations/integrations.md#project-key-auto-detection)).

## When the Remediation Agent is unavailable

If your organization is not subscribed to the Remediation Agent, the CLI prints an informational message with a link to [Sonar Agent Essentials](https://www.sonarsource.com/products/agent-essentials/) and exits with code `0`. If your organization is eligible but has not enabled the feature, the CLI tells you to contact your administrator and also exits with code `0`. These cases are non-fatal so scripts and agents can continue without treating access gaps as command failures.

## Interactive remediation

Run inside the project directory to pick issues from a list:

```bash
sonar remediate --project <YourProjectKey>
```

The CLI fetches the project's *eligible* issues from the server and prompts you to select which ones to remediate. The server decides eligibility; only issues the remediation agent can fix are shown.

## Non-interactive remediation

For scripts and CI/CD, pass the issue keys directly:

```bash
sonar remediate --project <YourProjectKey> --issues key-1,key-2,key-3
```

You can pass up to 20 issue keys per invocation. Get keys from `sonar list issues`:

```bash
sonar list issues --project my-org_my-app --severities BLOCKER --format json \
  | jq -r '.issues[].key' \
  | paste -sd, \
  | xargs -I {} sonar remediate --project my-org_my-app --issues {}
```

> **Note:** When `sonar remediate` runs without a terminal attached (in CI/CD, an SSH session without a TTY, or a CI runner), `--issues` is **required**. The command will fail fast otherwise rather than wait for input.

## What you get back

The remediation agent returns a proposed change. You review it, apply it, edit it, or discard it. The CLI does not push any changes to your repository on its own; you stay in control of what lands.

## Override the project

If auto-detection picks the wrong project (for example, when your repo is mapped to several SonarQube projects), pass `--project` explicitly:

```bash
sonar remediate --project my-org_specific-project
```

## Use it from an AI agent

After you install a [Claude Code](/sonarqube-cli/integrations/claude-code.md), [GitHub Copilot CLI](/sonarqube-cli/integrations/github-copilot-cli.md), [OpenAI Codex](/sonarqube-cli/integrations/codex.md), [Cursor](/sonarqube-cli/integrations/cursor.md), or [Antigravity](/sonarqube-cli/integrations/antigravity.md) integration, the agent can call `sonar remediate` itself. Example prompt:

*"List the BLOCKER issues in `my-org_my-app`, pick the top three, and run `sonar remediate` on them."*

## Related pages <a href="#related-pages" id="related-pages"></a>

* [Analyzing local changes](/sonarqube-cli/analysis/analyzing-local-changes.md)
* [Secrets detection](/sonarqube-cli/analysis/secrets-detection.md)
* [Commands reference](/sonarqube-cli/using-sonarqube-cli/commands.md)


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://docs.sonarsource.com/sonarqube-cli/analysis/ai-remediation.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
