How to Use GitHub Copilot Agentic Autofix for Code Scanning Alerts

Introduction

This tutorial is for security engineers, repository administrators, and team leads who run CodeQL code scanning on GitHub Enterprise Cloud and sit on a backlog of open alerts. You will learn how to enable GitHub Copilot agentic autofix, assign alerts to Copilot individually or in batches of up to 25, and review the draft pull request it produces before anything merges.

Quick answer

Assign a code scanning alert to Copilot from the Security tab, or select up to 25 alerts at once. Copilot explores the code, proposes a fix, reruns CodeQL to verify it, and opens a draft pull request for your review.

Evidence

Agentic autofix reached general availability on October 15, 2026, after a public preview that began in July 2026. GitHub describes the workflow in its changelog this way: “it explores relevant files, proposes a fix, and reruns CodeQL to confirm the fix closes the alert before opening a pull request for your review.” That revalidation loop is the feature that separates agentic autofix from the older Copilot Autofix, which generates a single suggested code change for one alert that you review and apply yourself.

Two numbers define the practical scope of the feature. First, one assignment can cover up to 25 alerts, and all 25 land in a single draft pull request, which makes it a realistic tool for clearing a medium severity backlog rather than a one alert at a time gadget. Second, the eligibility boundary is narrow: it is available only to GitHub Code Security and GitHub Advanced Security customers on GitHub Enterprise Cloud, including Enterprise Cloud with data residency, and only for alerts on the repository default branch. GitHub’s own documentation on autofix for code scanning spells out how agentic autofix differs from Copilot Autofix, including the fact that agentic autofix sessions consume AI credits and Actions minutes while Copilot Autofix suggestions do not. The same documentation notes that agentic autofix is not available for repositories owned by Enterprise Managed Users, a detail that catches some enterprise teams by surprise.

Prerequisites

  • A repository on GitHub Enterprise Cloud with CodeQL code scanning already enabled and alerts present on the default branch.
  • A GitHub Code Security or GitHub Advanced Security license for the organization or enterprise.
  • An enterprise owner or security manager who can enable the agentic autofix policy, plus an organization owner or repository administrator who can turn it on for the repository.
  • A Copilot billing method configured for the enterprise, since agent sessions bill against it.
  • Write access to the repository, which is required to assign alerts.
  • A test suite or CI workflow you can run against the draft pull request before merging.

Step-by-step guide

Step 1: Enable agentic autofix at the enterprise level

An enterprise owner or security manager must first allow agentic autofix through the enterprise Advanced Security policy. Until that policy is on, organization and repository settings cannot enable the feature, and the Assign to Copilot button will not appear on alerts. If your organization does not belong to an enterprise, an organization owner or security manager enables it directly for the organization.

Step 2: Enable it for the organization or repository

Once the enterprise policy allows it, an organization owner or security manager enables agentic autofix for the organization, which turns it on for eligible repositories by default. A repository administrator can then opt a repository out, or re-enable it when the higher level settings permit. For an eligible public repository owned by a personal account, a repository administrator can enable agentic autofix directly. Confirm the setting took effect before you assign anything, because an assignment made while the feature is off simply is not offered.

Step 3: Pick a first batch of alerts

Open the repository code scanning alerts list and filter for the default branch. Start with a small, low risk batch, for example five to ten alerts of the same query type, such as SQL injection or cross-site scripting in one service. A batch of identical query types is easier to review, because the fix pattern repeats and a wrong pattern is visible across all files at once. Avoid starting with alerts in authentication, authorization, or payment code, where a behavior change is hardest to spot in review.

Step 4: Assign one alert to Copilot

For a single alert, go to the repository main page, open the Security and quality tab, click Code scanning in the left sidebar, and click the alert name. Toward the top of the alert page, under Assignees, click Assign to Copilot. This is the assignment flow GitHub documents in its guide to resolving code scanning alerts. This starts an agent session that explores the codebase, generates a fix, and validates it by rerunning CodeQL. Copilot typically opens a draft pull request within a few minutes, authored by Copilot, with a summary of the fix and the validation steps it took.

Step 5: Assign a batch of up to 25 alerts

From the code scanning alerts backlog or a security campaign, select up to 25 alerts, then click Assign to Copilot above the list. One assignment creates one agent session and one pull request for all selected alerts. Batching is the main productivity win here: instead of 25 separate suggestions to triage, you review one draft pull request. Keep batches thematically tight, because a single pull request mixing unrelated services is harder to review and harder to revert if one fix is wrong.

Step 6: Assign alerts through the API (optional)

If you run remediation campaigns from scripts, you can assign an alert through the REST API by updating the alert assignees:

PATCH /repos/{owner}/{repo}/code-scanning/alerts/{alert_number}
Authorization: Bearer <token>
Content-Type: application/json

{
  "assignees": ["copilot-swe-agent[bot]"]
}

Use this for campaign automation, not as a replacement for the UI flow on your first run. Verify the assignment in the UI before you assume the session started, because an API call against an ineligible alert or a repository where agentic autofix is disabled will not produce a session.

Step 7: Review the draft pull request

Open the draft pull request and read the diff file by file, not just the summary. Check the agent session log, available from the Agents tab of the repository, for what Copilot explored and which validation steps it ran. Confirm that CodeQL reran and that the alert is closed by the change. Then run your own test suite and CI checks against the branch, because a CodeQL recheck only proves the vulnerable pattern is gone, not that behavior is preserved. If a fix looks wrong, comment on the pull request or interact with the session in the Agents tab to ask Copilot for a revision. Only mark the pull request ready for review and merge it after tests pass and a human has approved the diff.

Step 8: Track cost and set a budget

Each agentic autofix session consumes Code Security AI Credits and GitHub Actions minutes. Consumption appears in the AI usage section of billing, and you can set budgets at the SKU level. Check usage after your first batch and set a budget before you scale to the full backlog, because a 25 alert batch across a large repository can consume noticeably more credits than a single alert fix. Note the billing change that comes with enablement: agentic autofix replaces the free Generate Fix option on individual alerts, so every fix you request through the button now draws on your credit budget.

Troubleshooting

The Assign to Copilot button is missing

This almost always means agentic autofix is not enabled at a higher level. Check the enterprise Advanced Security policy first, then the organization setting, then the repository setting. Also confirm the alert is on the default branch: alerts detected only on pull requests or other branches cannot be assigned to Copilot, and the button will not appear for them. Repositories owned by Enterprise Managed Users are not eligible at all, so if your enterprise uses managed users, that is the answer and no setting will surface the button.

Copilot opens a pull request but the alert stays open

The agent session may have produced a partial fix, or the rerun of CodeQL may have found the alert still present under a different code path. Read the session log in the Agents tab to see which validation step failed, then comment on the pull request asking Copilot to address the remaining occurrence. If the alert resists two rounds of revision, fix it by hand: some alerts involve design level changes, such as restructuring how user input flows through a service, that an agent patch cannot safely make.

The draft pull request changes behavior or breaks tests

Treat this as the expected failure mode, not a surprise. A fix that silences CodeQL can still change behavior, for example by escaping output in a place where downstream code expected raw markup. Revert the offending hunk, run the failing test to confirm the regression, and either fix it manually or ask Copilot to revise with the test failure quoted in your comment. This is why the first batch should avoid authentication and permissions code, and why CI must run before merge.

Credit usage is higher than expected

Check the AI usage section of billing to see which sessions consumed credits, and confirm whether a batch of 25 alerts ran as one session or was split. Set an SKU level budget for Code Security AI Credits before the next batch, and reserve agentic autofix for alerts you would otherwise pay a developer hours to clear. For single, simple alerts where you only want a suggestion to apply yourself, remember that Copilot Autofix remains free when agentic autofix is not enabled for the repository.

The pull request touches files unrelated to the alert

An agent exploring a codebase can pull in adjacent files, especially when a fix spans shared helpers. If the diff includes unrelated refactoring, ask Copilot in a pull request comment to drop the unrelated changes, or split the pull request by hand before review. Do not merge a mixed diff to save time: an unrelated change bundled with a security fix is the hardest kind of change to audit later.

FAQ

See the FAQ in the front matter above for the most common questions, including licensing, the 25 alert batch limit, default branch eligibility, and the Generate Fix replacement.

Conclusion

Agentic autofix is best used as a backlog clearing tool with a human gate, not as an auto merge pipeline. Enable it at the enterprise and organization levels, start with a small batch of same type alerts on the default branch, review the draft pull request with tests, and set a credit budget before scaling. For the complementary workflow of getting Copilot to review new code before it merges, read how to request GitHub Copilot code review via the REST and GraphQL APIs. If you want to see how Copilot agents behave in a broader automation setup, the GitHub Copilot computer use tutorial covers agent driven workflows end to end.

Frequently asked questions

TP
ToolPilot Team

We install, break, and fix automation tools so you don't have to. Every tutorial on ToolPilot is tested hands-on before publishing.

Keep reading