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

# Autodetect AI code

SonarQube Server 2025.2 can autodetect the likelihood of AI-generated code in your projects on GitHub using GitHub Copilot.

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](https://3577027091-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F69lEOGGgOhCpumODGD9v%2Fuploads%2Fgit-blob-975a17de7ce8ae3b164dd9f9db9c791adb294bbb%2F4be9087a2b059c269f15df202838af7a74e71a96.svg?alt=media)**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](https://3577027091-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F69lEOGGgOhCpumODGD9v%2Fuploads%2Fgit-blob-ca3b9de37a93a3d09c496b45878e418adab02c9f%2Fc151514ef7beca0f865ee429bc9fe0e33b05ceb4.svg?alt=media) [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 ![\*](https://3577027091-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F69lEOGGgOhCpumODGD9v%2Fuploads%2Fgit-blob-975a17de7ce8ae3b164dd9f9db9c791adb294bbb%2F4be9087a2b059c269f15df202838af7a74e71a96.svg?alt=media)**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 ![\*](https://3577027091-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F69lEOGGgOhCpumODGD9v%2Fuploads%2Fgit-blob-975a17de7ce8ae3b164dd9f9db9c791adb294bbb%2F4be9087a2b059c269f15df202838af7a74e71a96.svg?alt=media)**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
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 by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://docs.sonarsource.com/sonarqube-server/2025.2/ai-capabilities/autodetect-ai-code.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

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.
