# About autofix for code scanning

Autofix provides targeted recommendations to help you fix code scanning alerts and avoid introducing new security vulnerabilities.

Autofix provides you with targeted recommendations to help you fix code scanning alerts so you can avoid introducing new security vulnerabilities. The potential fixes are generated automatically by large language models (LLMs) using data from the codebase and from code scanning analysis.

## How autofix works

Autofix translates the description and location of a code scanning alert into code changes that may fix it. It interfaces with the large language model GPT-5.3-Codex from OpenAI, which has sufficient generative capabilities to produce both suggested fixes in code and explanatory text for those fixes.

There are two ways to get a fix for an alert: agentic autofix and Copilot自动修复. If Copilot云代理 is available in a repository, assigning an alert uses agentic autofix instead of Copilot自动修复.

## Agentic autofix

> \[!NOTE] This feature is currently in public preview and is subject to change.

Assign a code scanning alert to Copilot to have it resolve the alert for you. Assigning an alert starts an agent session: Copilot云代理 calls tools to explore your codebase beyond the affected file, generates a fix, validates it (for example, by re-running CodeQL), and iterates until it opens a pull request with the changes. See [解决代码扫描警报](/zh/code-security/how-tos/manage-security-alerts/manage-code-scanning-alerts/resolve-alerts#fixing-alerts-with-copilot).

Keep the following in mind:

* Agentic autofix requires Copilot云代理 and Copilot自动修复 to be available in the repository. If Copilot云代理 isn't available, assigning an alert falls back to Copilot自动修复 instead.
* Each agentic autofix session is billed as a Copilot云代理 session and consumes AI credits. See [关于 GitHub Copilot 云代理](/zh/copilot/concepts/agents/cloud-agent/about-cloud-agent#copilot-cloud-agent-usage-costs).
* Copilot follows any custom instructions configured for the repository or organization when it generates a fix.
* Agentic autofix works on a best-effort basis. Copilot validates fixes by re-running CodeQL using the code-scanning query suite, so it can't confirm that a fix resolves alerts generated by custom queries or the security-extended query suite. Fix quality for alerts from third-party tools is also not guaranteed.

## Getting a suggested fix with Copilot自动修复

Copilot自动修复 generates a single suggested fix for an alert, which you review and apply yourself.

You do not need a subscription to GitHub Copilot to use GitHub Copilot自动修复, and it does not consume AI credits. Copilot自动修复 is available to all public repositories on GitHub.com, as well as internal or private repositories owned by organizations and enterprises that have a license for GitHub Code Security.

Copilot自动修复 is allowed by default and enabled for every repository that uses CodeQL, regardless of whether it uses default or advanced setup for code scanning. There is no separate step to enable Copilot自动修复: enabling code scanning with CodeQL is sufficient. See [配置代码扫描的默认设置](/zh/code-security/code-scanning/enabling-code-scanning/configuring-default-setup-for-code-scanning).

Administrators at the enterprise, organization, and repository levels can choose to disable Copilot自动修复. If Copilot自动修复 has been disabled at your level, you can re-enable it by following the same steps used to disable it and selecting the option to allow Copilot自动修复. To learn how to manage Copilot自动修复 at each level, see [针对代码扫描安全警报禁用 Copilot 自动修复](/zh/code-security/how-tos/manage-security-alerts/manage-code-scanning-alerts/disabling-autofix-for-code-scanning).