# AI CodeFix

## Overview

AI CodeFix is part of the *Solve* phase of the [Agent Centric Development Cycle](/agent-centric-development-cycle/readme.md).

Sonar’s AI CodeFix uses a large language model (LLM) to automatically generate AI-driven code fixes for the issues discovered by SonarQube Cloud or SonarQube Server.

The feature is available with:

* SonarQube Cloud Team and Enterprise plans.
* SonarQube Server Enterprise and Data Center editions.

When the feature is enabled, a **Generate AI fix** button appears in the SonarQube Server or SonarQube Cloud UI for the selected issue. Clicking the button sends the affected code and issue description to an LLM. AI CodeFix then proposes an edit that resolves the problem without changing the code’s functionality.

## Sharing your code with Sonar <a href="#sharing-your-code-with-sonar" id="sharing-your-code-with-sonar"></a>

For fully self-hosted SonarQube Server configurations, AI CodeFix is designed to operate without outbound internet access. All necessary prompts and rule descriptions for AI CodeFix are provided with the SonarQube product installation.

* Requirement: The SonarQube Server instance must be able to reach your configured LLM endpoint.

If you use Sonar’s AI CodeFix LLM, the affected code snippet will be sent by the AI CodeFix service to the selected LLM. Service agreements with Sonar’s LLMs prevent your code from being used to train those models.

For terms and conditions, see [AI CodeFix terms](https://www.sonarsource.com/legal/ai-codefix-terms/) in our [Legal Documentation](https://www.sonarsource.com/legal/).

## Setup

### Use the feature

* SonarQube Cloud: [Getting AI-generated fix suggestions](https://docs.sonarsource.com/sonarqube-cloud/managing-your-projects/issues/fixing#getting-ai-generated-fix-suggestions).
* SonarQube Server: [Getting AI-generated fix suggestions](https://docs.sonarsource.com/sonarqube-server/user-guide/issues/fixing#getting-ai-generated-fix-suggestions).

### Use the feature in your IDE

After enabling AI CodeFix, users can select **Generate AI Fix** on eligible issues and copy the fix into their IDE with the **Open in IDE** feature in connected mode. If your engineers use SonarQube for [VS Code](https://docs.sonarsource.com/sonarqube-for-ide/vs-code/) or SonarQube for [IntelliJ](https://docs.sonarsource.com/sonarqube-for-ide/intellij/), AI CodeFix is available in the IDE and follows the settings defined in your quality profile.

* See the IntelliJ page for [AI CodeFix in your IDE](https://docs.sonarsource.com/sonarqube-for-ide/intellij/ai-capabilities/ai-codefix/)
* See the VS Code page for [AI CodeFix in your IDE](https://docs.sonarsource.com/sonarqube-for-ide/vs-code/ai-capabilities/ai-codefix/)

### Enable the feature

To learn how to enable the feature, see:

* SonarQube Cloud: [Enable AI CodeFix](https://docs.sonarsource.com/sonarqube-cloud/administering-sonarcloud/ai-features/enable-ai-codefix).
* SonarQube Server: [Enable AI CodeFix](https://docs.sonarsource.com/sonarqube-server/instance-administration/ai-features/enable-ai-codefix).

## Usage limits

Usage limits protect the AI CodeFix feature from abuse. Developers are notified directly when your organization reaches its monthly allocation. If the instance is blocked due to reaching the allowance, users attempting to generate a fix will see an error message. Usage quotas are reset on the first day of each month.

SonarQube Server instances using a self-hosted LLM aren’t subject to Sonar’s limits; however, you may encounter rate limits from your LLM provider.


---

# Agent Instructions: 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:

```
GET https://docs.sonarsource.com/agent-centric-development-cycle/features/ai-codefix.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
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.
