# Autodetect AI code

Knowing if your project contains AI-generated code helps raise awareness of code ownership and code security. To help build this awareness, SonarQube Server can autodetect AI-generated code in projects on GitHub using GitHub Copilot. If turned on, the feature alerts Project Admins when project contributors recently used GitHub Copilot so that such projects can be protected with [Standards for AI code](/sonarqube-server/2025.2/ai-capabilities/ai-standards.md).

**Autodetect AI-Generated Code** is turned on by default in SonarQube Server, but your GitHub App must have the appropriate permissions.

## Requirements <a href="#requirements" id="requirements"></a>

1. The **Autodetect AI-Generated Code** feature is turned on by default in SonarQube Server. See the instructions below to manage feature activation at the global and project levels.
2. A Project Admin must enable access from your GitHub App. The autodetection feature will not function without giving SonarQube Server access to GitHub Copilot Business.

## Autodetecting AI code <a href="#autodetect-ai-code" id="autodetect-ai-code"></a>

With access to your GitHub App, SonarQube Server can evaluate users’ GitHub Copilot usage and code contribution patterns to identify potential AI-generated code. If there is a match in user data, SonarQube Server will display the ![$ai-icon-sparkle](/files/QbssuGgK5Cc0Z3wSsL4b)**AI code detected** status on the project’s Overview and Project Information pages.

SonarQube Server does not retroactively check older code from previous commits. In addition, projects that have the ![$contains-ai-code](/files/7W2fFNBOHngF0RkqMAb6) [Standards for AI code](/sonarqube-server/2025.2/ai-capabilities/ai-standards.md#label-projects-with-ai-code) will be excluded from automatic AI code detection.

To activate **Autodetect AI-Generated Code** in SonarQube Server, follow these three steps:

### Step 1: Manage AI autodetection in SonarQube Server <a href="#mange-in-sonarqube-server" id="mange-in-sonarqube-server"></a>

**Autodetect AI-Generated Code** can be managed at the global and project levels:

* At the global level, go to **Administration** > **Configuration** > **General Settings** > **AI-Generated Code** and select or deselect **Autodetect AI-Generated Code**. The setting is turned on by default.
* At the project level, go to *Your Project* > **Project Settings** > **AI-Generated Code** and select or deselect **Autodetect AI-Generated Code in this project**. The setting is turned on by default.

### Step 2: Enable your GitHub integration <a href="#enable-in-github" id="enable-in-github"></a>

The **Autodetect AI-Generated Code** feature relies on your [Setting up a GitHub App](/sonarqube-server/2025.2/devops-platform-integration/github-integration/setting-up-at-global-level/setting-up-github-app.md) to give SonarQube Server access to your organization’s usage statistics of GitHub Copilot. To create a new integration or manage an existing one, go to **Administration** > **DevOps Platform Integrations** > **GitHub**.

Once you’ve registered your GitHub App, a Project Admin must navigate (in GitHub) to *Your GitHub App* > **App settings** > **Permissions & events** > **Organization permissions** > **GitHub Copilot Business** and set the access level to **Read-only**. Note that as per standard procedure, GitHub will send a confirmation email which must be acknowledged.

### Step 3: Rescan your project <a href="#rescan-your-project" id="rescan-your-project"></a>

With the requirements satisfied, SonarQube Server will check for the presence of AI-generated code each time an analysis is performed. Projects containing autodetected code will display the ![\*](/files/QbssuGgK5Cc0Z3wSsL4b)**AI code detected** status on the project’s Overview and Project Information pages.

If **Autodetect AI-Generated Code** is turned off on a project containing autodetected code, the ![\*](/files/QbssuGgK5Cc0Z3wSsL4b)**AI code detected** status will be displayed until the next analysis is run.

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

* [Overview](/sonarqube-server/2025.2/ai-capabilities/overview.md)
* [Standards for AI code](/sonarqube-server/2025.2/ai-capabilities/ai-standards.md)
* see [Fixing issues](/sonarqube-server/2025.2/user-guide/issues/fixing.md#getting-ai-generated-fix-suggestions)
* see [Standards for AI code](/sonarqube-server/2025.2/ai-capabilities/ai-standards.md#label-projects-with-ai-code)
* see [Defining quality gates](https://docs.sonarsource.com/sonarqube-server/10.9/instance-administration/analysis-functions/quality-gates/#defining-quality-gates) for standard instructions to create a new quality gate


---

# 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/sonarqube-server/2025.2/ai-capabilities/autodetect-ai-code.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.
