MSBA-361 · Lesson 4 of 12 · 18 min

Copilot Autofix

▶ Video coming soon A video version of this lesson is on the way.

The commerce group's 1,180 open alerts had produced a predictable reaction. Developers agreed that the alerts mattered, agreed that they could not stop feature work to fix them, and wanted to know whether anything could help. Seraphine's answer for the fourth session was Copilot Autofix, and her first slide was a warning about expectations rather than a demonstration: Autofix suggests fixes; it does not take responsibility for them.

What Copilot Autofix does

Copilot Autofix is a feature of code scanning that uses a large language model to suggest a code change that fixes an alert. It combines the alert's details, including the rule, the location and the data flow path, with the surrounding code, and produces a suggested patch with an explanation of what the change does and why it should resolve the problem.

Autofix appears in two places. In a pull request, when code scanning finds a new alert in the change, Autofix can generate a suggestion that appears alongside the alert annotation, and the author can commit it directly or edit it first. On an existing alert on the default branch, the alert page offers a button to generate a fix, and the suggestion can be turned into a pull request.

A flow from left to right: a code scanning alert with its rule, location and data flow path, plus the surrounding code, go into Copilot Autofix. Out comes a suggested change with an explanation. A developer reviews, tests and edits it, then commits it to a pull request. Code scanning runs again and closes the alert if the problem is gone.
Autofix suggests; a developer reviews and commits; code scanning confirms.

Two details shape how organizations use it. First, Autofix is enabled by default for repositories that use CodeQL, under either default or advanced setup, unless an administrator turns it off. Second, administrators can disable it at enterprise, organization or repository level, and a setting made higher up stops lower levels from re-enabling it.

Copilot Autofix at a glance. Availability details change; check the documentation before planning.
QuestionAnswer
Which repositories can use it?Public repositories on GitHub.com, and private or internal repositories with a GitHub Code Security (or Advanced Security) licence
Does each developer need a Copilot licence?No; Autofix for code scanning is part of Code Security, not a Copilot seat feature
Does generating a suggestion consume AI credits?No, according to GitHub's current documentation; agentic autofix, below, does
Which tools' alerts does it fix?CodeQL alerts, and since late 2024 alerts from some partner tools
Where is it switched off?Code security settings at enterprise, organization or repository level

What a suggestion looks like

Seraphine generated a fix live for one of the commerce group's SQL injection alerts in a reporting service. Autofix proposed replacing a query built by joining strings with a parameterized query, adjusting the call so the value was passed as a parameter, and explaining that this kept user input out of the SQL text. It changed four lines in one file.

An illustrative Autofix-style suggestion for a training repository. The diff format shows removed and added lines.
-  const sql = `SELECT sku, qty FROM stock WHERE store_id = ${storeId} AND sku LIKE '${prefix}%'`;
-  return db.query(sql);
+  const sql = "SELECT sku, qty FROM stock WHERE store_id = ? AND sku LIKE ?";
+  return db.query(sql, [storeId, `${prefix}%`]);

It looked right, and it was close to right. Teodric pointed out that the reporting service's database library expected named parameters rather than question marks in this module, because of a wrapper his team had written. The suggestion would have failed at run time. He edited it, ran the tests, and committed. Seraphine said that was the whole lesson: the suggestion saved most of the work, and a developer who knew the code finished it.

Using Autofix responsibly

GitHub's own guidance on responsible use of Autofix makes several points, and Skerry adopted them as rules.

Risks of accepting Autofix suggestions and how Skerry handles them.
RiskWhy it happensWhat to do
The fix is incorrectThe model can misunderstand the code or the libraryReview every suggestion as you would a colleague's pull request
The fix changes behaviourMaking code safe can reject inputs that used to be acceptedRun the tests and check edge cases
The fix is partialA suggestion may address one path but not othersLet code scanning run again and confirm the alert closes
The fix adds a dependencySome suggestions use a library for escaping or validationCheck the dependency is approved and passes dependency review
The fix touches other filesSuggestions can edit more than the alert's fileRead the whole diff, not just the highlighted line

The most important rule was that Autofix does not change the review process. A pull request containing an Autofix suggestion still needs its usual reviews and checks. In repositories governed by the Confidential code ruleset from MSBA-291, that meant two approvals and passing builds, whether or not a model had written some of the code.

Freya also asked teams not to use the explanation as a substitute for understanding. The explanation is useful for a reviewer, but the developer accepting the change should be able to say in their own words why it fixes the problem.

Agentic autofix

In July 2026 GitHub released a preview of agentic autofix, and it became generally available on October 15, 2026. Where Copilot Autofix suggests a single change for one alert, agentic autofix works more like a developer handed a task. It explores the relevant files, proposes a fix, runs CodeQL again to check that the alert is resolved, and opens a draft pull request with a summary, its reasoning and the validation it performed. Reviewers can ask for further changes by commenting on the pull request.

Copilot Autofix and agentic autofix compared, as of November 2026.
Copilot AutofixAgentic autofix
How you start itGenerate a fix on an alert, or automatically in a pull requestAssign the alert to Copilot
What it producesOne suggested change for one alertA draft pull request, which can cover up to 25 alerts selected together
ValidationYou let code scanning run after committingIt reruns CodeQL itself before opening the pull request
Which alertsPull request alerts and existing alertsAlerts on the default branch only
CostNo AI credits for suggestionsAI credits from the Code Security budget plus Actions minutes
AvailabilityPublic repositories and Code Security licencesCode Security or Advanced Security customers on Enterprise Cloud, including data residency
EnablementOn by default with CodeQLEnterprise policy, then organization or repository setting, plus a Copilot billing method

When agentic autofix is enabled, the alert page's option to generate a single fix is replaced by an option to assign the alert to Copilot. Usage appears in enterprise billing under the Advanced Security product, and enterprises can set budgets for Code Security AI credits so that a burst of assignments does not produce a surprise bill.

Skerry's enterprise owners turned on the agentic autofix policy on November 12, 2026, but enabled it only in skerry-sandbox as a pilot. Lorcan Adeyemi-Brooke, the finance partner, set a monthly budget for the AI credits. The pilot's first test was a batch of 25 medium-severity alerts of one rule in a sandbox copy of an internal tool. Copilot opened one draft pull request that fixed 22 of them, explained why it had not changed the other three (they were in code that built SQL from constants only), and listed the CodeQL run it had used to check its work. Reviewers still requested two changes before approving.

Autofix in pull requests

The most valuable use of Autofix, Seraphine argued, was not the backlog but new code. When a developer opens a pull request that introduces an alert, a suggested fix in the same pull request is the cheapest possible remediation: the developer is already in the code, the context is fresh, and the fix lands before the problem ever reaches the default branch.

Skerry's data showed this. In the first three weeks of November, pull requests in in-scope repositories introduced 640 new CodeQL alerts. Autofix produced a suggestion for most of them. About half of all the new alerts were fixed in the same pull request by committing a suggestion, often edited; another quarter were fixed by hand; the rest were either dismissed with a reason or merged to be handled later, which the merge ruleset in lesson 11 was about to restrict.

When to turn Autofix off

There are reasons an organization might disable Autofix for some repositories. Some teams work under contracts or regulations that restrict sending code to AI services, even within GitHub. Some repositories contain code where any change needs a formal review by a separate group, so suggestions in pull requests create noise without saving time. Skerry kept Autofix on everywhere except for the 18 store terminal firmware repositories, where the payment terminal certification process required every change to be traced to an approved design document. For those, suggestions were still useful as hints, so the firmware lead, Anselm Okonkwo-Fairley, asked for Autofix to stay on in a sandbox fork where engineers could look at suggestions without them appearing in the certified repositories' pull requests.

Worked problem

Reviewing a suggestion

Autofix suggests fixing a path traversal alert by adding a check that rejects file names containing two dots, and changes one line. The alert is in an export job that writes files named after store codes. Is the suggestion enough?

Show solution
  1. Check what values are legitimate: store codes are letters and digits only.
  2. Notice that rejecting two dots does not stop absolute paths or other separators.
  3. Prefer an allow list that accepts only the legitimate pattern, and resolve the final path and confirm it is inside the export directory.
  4. Edit the suggestion accordingly, run tests and let code scanning confirm.

Answer: Not on its own. Replace the deny check with an allow list for store codes and confirm the resolved path stays in the export directory, then let code scanning confirm the alert closes.

Where Autofix struggles

Autofix works best on alerts with a well-known fix pattern in a single file: an unparameterized query, missing output encoding, an unsafe file path. It works less well in three situations, and developers at Skerry learned to recognize them quickly.

Situations where Autofix suggestions need extra care.
SituationWhat happensWhat to do
The fix belongs in another file or a shared helperThe suggestion fixes the symptom locallyUse the suggestion as a hint and make the change where the shared cause is
The fix needs a new dependencyThe suggestion may add oneCheck the dependency through dependency review and the team's approved list
The alert is a false positiveAutofix may still propose a changeDismiss with a reason instead of merging an unnecessary change
Large or unusual codeNo suggestion, or a partial oneFix by hand; not every alert gets a suggestion

The first situation was the most common. In the commerce code, Autofix often suggested parameterizing a query directly, when the team's standard was to call the shared query helper. Teodric's habit was to accept the idea of the suggestion and rewrite it to use the helper. The commerce team later added repository instructions for Copilot that described the helper, as lesson 11 explains.

What the November numbers showed

Seraphine looked at November's 640 new alerts in pull requests to see whether Autofix was helping or merely producing changes. About half were fixed by committing an Autofix suggestion, often after editing it; about a quarter were fixed by hand; and the rest were dismissed with a reason or left for later. In a sample of 40 Autofix commits, she found three that fixed the alert but not a second path with the same problem nearby, which CodeQL then reported as a new alert on the next analysis. Her conclusion for the champions was simple: Autofix speeds up the common case, and the reviewer's job is to look for the uncommon one.

Common mistakes

  • MistakeCommitting Autofix suggestions without review or tests.

    InsteadTreat suggestions like any colleague's code: read the whole diff, run tests and keep normal reviews.

  • MistakeAssuming a Copilot licence is needed for every developer.

    InsteadAutofix for code scanning comes with Code Security or public repositories.

  • MistakeTurning on agentic autofix everywhere without a budget.

    InsteadPilot it, and set a budget for Code Security AI credits.

  • MistakeUsing Autofix only on the old backlog.

    InsteadIts biggest value is fixing new alerts in the pull request that introduced them.

Summary and key terms

  • Copilot Autofix uses an AI model and the alert's details to suggest a fix with an explanation.
  • It appears in pull requests and on existing alerts, and is on by default for CodeQL repositories.
  • It is available for public repositories and with Code Security, without a Copilot licence per developer.
  • Suggestions can be wrong, partial or change behaviour, so review and testing remain essential.
  • Agentic autofix, generally available since October 15, 2026, opens validated draft pull requests for up to 25 default-branch alerts at a time.
  • Agentic autofix needs an enterprise policy and a Copilot billing method, and consumes AI credits and Actions minutes.
  • Fixing alerts in the pull request that introduced them is the cheapest remediation of all.
Copilot Autofix
A code scanning feature that suggests code changes to fix alerts, with an explanation.
Agentic autofix
A feature that assigns default-branch alerts to Copilot, which explores the code, validates a fix with CodeQL and opens a draft pull request.
Suggested fix
A proposed patch that a developer can commit, edit or reject.
AI credits
The usage unit billed for agentic autofix and other metered AI features.
Responsible use
GitHub's guidance on the limits of AI-generated fixes and the review they need.

Practice problems

Work each problem on paper first, then reveal the answer to check.

  1. Where does Copilot Autofix show suggestions?

    Show answer

    In pull requests for newly introduced alerts, and on existing alerts through the option to generate a fix.

  2. What three things must be in place to use agentic autofix?

    Show answer

    The enterprise policy, the organization or repository setting, and a Copilot billing method.

  3. Why is a pull request the best place to fix a new alert?

    Show answer

    The developer is already in the code, and the problem never reaches the default branch.

Lesson quiz · 5 questions

Score 60% or more to complete this lesson.

Take the quiz