In a nutshell
Code Scanning finds vulnerabilities through static analysis (SAST), without running your code.
CodeQL turns code into a queryable database. Eligible findings can get Copilot Autofix suggestions or be assigned to Copilot for a fix.
Code scanning is not CodeQL 📖 Docs
Code scanning is the GitHub feature; CodeQL is one analysis engine. AI findings complement it on pull requests, and third-party tools can supply SARIF results.
How CodeQL works 📖 Docs
Extract code into a database, then compile and evaluate queries against it.
The schema describes the data; the database stores it. Extraction reads source directly or monitors a build, depending on the language and build mode ↗.
Reading a CodeQL query
QL is a declarative logic-programming language. You describe the shape of a bug and the evaluator finds every instance. The structure mirrors SQL’s FROM / WHERE / SELECT.
import java // ① pull in the standard library
from IfStmt ifstmt, Block block // ② declare the elements to inspect
where
block = ifstmt.getThen() and // ③ constrain them
block.getNumStmt() = 0 // → a then-branch with no statements
select ifstmt, "This if-statement is redundant." // ④ what to report, and how
The whole language is that shape: where is the definition of “what the bug looks like”, and the evaluator does the searching.
🔬 Security queries layer
DataFlow/TaintTrackingon top, defining sources, sinks and sanitizers and searching for paths between them. The packs are open source at github/codeql ↗. In practice they are enough — you write custom queries mainly to teach CodeQL the sources and sinks of your in-house framework.
📘 Details: About CodeQL queries ↗ / About data flow analysis ↗
What CodeQL finds
🌐 Supported languages — C/C++, C#, Go, Java/Kotlin, JavaScript/TypeScript, Python, Ruby, Rust, Swift, GitHub Actions. A repo with no CodeQL-supported language runs no scans and burns no Actions minutes.
Main capabilities
-
OPEN REPOSITORY SETTINGS
Open ghas-test-1 → Advanced Security ↗ and show Code scanning → CodeQL analysis.
For an unconfigured repository, the entry point is Set up → Advanced. This demo repository already has a workflow, so open the existing file without switching setup types.
-
WALK THROUGH ADVANCED SETUP
Open codeql.yml ↗. Show push / PR / schedule under
on, the languagematrix, and the runner underruns-on.C/C++ uses build-mode: manual with
make -C src/c/make -C src/cpp; the other languages use none. Point out queries: security-and-quality and the C/C++ CERT / MISRA packs.These packs come from github/codeql-coding-standards ↗: an example of extra query packs you can add (AUTOSAR C++14, CERT C/C++, MISRA C/C++).
Advanced setup controls the build and execution conditions through a versioned Actions workflow.
-
FROM CONFIGURATION TO RESULTS
Open an existing run under Actions → CodeQL ↗. Show the per-language Analyze jobs and their initialization, build, and analysis logs.
Finish at Security → Code scanning ↗ to see the alerts.
No workflow edits or commits are needed for this walkthrough. Leave the existing scans enabled.
Start with Default setup, customize it with repository properties, and reach for Advanced only when you need your own build.
Why shift left: fix it in the PR
A vulnerability is cheapest to fix in the pull request that introduces it. Once merged, it becomes security debt, and debt rarely gets paid down.
| 🟢 In the PR | 🔴 After merge | |
|---|---|---|
| 🧠 Context | Fresh in the author’s head | Rediscovered weeks later |
| 🔁 Fix cost | One commit, same review | Ticket, PR, review, deploy |
| 🚀 Exposure | Never reaches production | Can ship and stay live until fixed |
- 📉 Merged means forgotten: historically, only 10% of security debt in merged code gets addressed (GitHub data ↗)
- ⏱️ In the PR, it is fast: with Copilot Autofix, PR-time alerts were fixed in a median 28 min vs 1.5 h manually (GitHub, 2024 ↗)
Copilot Autofix: suggested fixes 📖 Docs
Copilot Autofix can generate a suggested patch for an eligible alert. You review, test and apply it; a successful fix is not guaranteed.
- 🤖 Input: alert details, surrounding code and CodeQL’s data-flow path inform the suggestion.
- 💬 On pull requests: supported alerts can receive inline suggestions automatically.
- 🛠️ On default-branch backlog alerts with Agentic Autofix off: Generate fix → Create PR with fix, if Copilot Autofix is enabled and supports the alert.
- 🆓 Cost: no Copilot license or AI credits for classic Autofix. Included with Code Security; free on public repositories.
- 🔌 Enablement: allowed by default with CodeQL unless an administrator disables it.
Agentic Autofix (GA) 📖 Docs
-
1. ALLOW AT ENTERPRISE LEVEL, IF APPLICABLE
An enterprise owner or security manager opens
Policies → Advanced Security → Agentic Autofixand selectsAll organizations: Allowed. Skip this for a standalone organization. Setup docs ↗Allowed grants permission to configure the feature; it does not enable any organization. Confirm the billing method and Code Security AI Credits budget before rollout.
-
2. SHOW THE TWO ORGANIZATION SETTINGS
Open theomonfort-org Advanced Security settings ↗ as an organization owner or security manager. In Global settings → Code scanning, locate Copilot Autofix and Agentic Autofix.
Copilot Autofix controls classic suggestions. To enable agent remediation, set
Agentic Autofix → On. Preview users must enable it again after GA.Turning this on enables Agentic Autofix for eligible repositories by default, not just the demo repo. Show the control without toggling it unless an organization-wide rollout is intended.
-
3. CHECK THE REPOSITORY OVERRIDE
In the chosen demo repository, open
Settings → Advanced Security → Code Security → Agentic Autofix. A repository administrator can set it to Off to opt out, or On if higher-level settings permit. Keep Copilot Autofix on if you want classic suggestions too.With Agentic Autofix enabled, users with write access can assign default-branch backlog alerts. No Copilot license is required. Enabling the setting alone does not start a repair session.
-
THE SECURITY BOT ON A PR
Open octodemo/octocat_supply-automatic-octo-funicular#57 ↗. In Files changed, show the comments from
github-advanced-security[bot].These findings are separate from Copilot code review. Keep this deliberately vulnerable demo PR unmerged.
-
TELL CODEQL AND AI FINDINGS APART
The CodeQL XSS comment ↗ is on
api/src/routes/cart.ts. Show the rule title and follow Show more details to the Security alert.For
CartShareController.php, show the risk explanation and fix advice in the AI SQL injection comment ↗ and command injection comment ↗.The author is the same bot, but AI findings are PR-only and do not become backlog alerts in Security.
-
FROM FINDING TO AGENTIC AUTOFIX
The linked PR is in octodemo, so theomonfort-org settings do not apply to it. Open the CodeQL XSS alert ↗ only as a reference. For remediation, choose an existing default-branch backlog alert in the configured demo repository; a PR-only alert cannot be assigned.
Show Assign to Copilot when Agentic Autofix is enabled. With it off, Generate fix is available only if classic Copilot Autofix is enabled and supports the alert.
A bot finding is not a remediation session. Invoking Assign to Copilot starts the agent's repair work and produces a separate draft PR. You can show the entry point without starting a session.
GA since 2026-10-15. When Agentic Autofix is enabled, Assign to Copilot replaces Generate fix on default-branch backlog alerts.
Autofix vs Agentic Autofix 📖 Docs
Two independent settings, not a cloud-agent switch (2026-10-19).
⚠️ Preview users must enable Agentic Autofix again after GA.
Security Campaigns — drive remediation at scale
Detection is the easy half; what happens after the alert is the real work. At scale, don’t grind the raw alert list — run a time-boxed campaign.
📘 Details: About security campaigns (GitHub Docs) ↗
My recommended starting checklist 📖 Docs
-
1. ENABLEMENT AND COVERAGE
ghas-test-1 → Advanced Security ↗ / CodeQL runs ↗: inspect the existing Advanced setup and language jobs. Do not switch this configured repository to Default setup.
-
2. EXTRA QUERY PACKS
ghas-test-1 → codeql.yml ↗ / MISRA / CERT / AUTOSAR packs ↗: show how the workflow configures additional queries and packs.
-
3. MERGE PROTECTION
ghas-test-1 → New branch ruleset ↗: Require code scanning results → CodeQL. Example: Security alerts: High or higher, Alerts: Errors, target
main. Keep it disabled for a walkthrough. -
4. AI SCAN
octodemo ↗ → Policies → Advanced Security → AI Scan, then theomonfort-org → Global settings ↗ → AI Scan.
Confirm enterprise permission and the Code Security AI Credits budget. Organization enablement affects all eligible repositories; show the controls without toggling them.
-
5. ASSISTED REMEDIATION
theomonfort-org → Autofix settings ↗: show the separate Copilot Autofix and Agentic Autofix controls. Check enterprise permission before enabling Agentic Autofix.
ghas-test-1 → Repository override ↗ / Code scanning alerts ↗
-
6. SECURITY CAMPAIGNS
theomonfort-org → Campaigns ↗: Create campaign → From code scanning filters. Scope to ghas-test-1, choose a manager and due date, then save as a draft.
Validate detection, protect new code, then reduce the backlog.
URL templates: replace ORG, OWNER, REPO.
Advanced setup and SARIF
When Default is not enough (monorepo, unusual build, another SAST tool), write the workflow yourself.
# .github/workflows/codeql.yml
name: CodeQL
on:
push: { branches: [main] }
pull_request: { branches: [main] }
schedule: [{ cron: '30 5 * * 1' }]
jobs:
analyze:
runs-on: ubuntu-latest
permissions: { security-events: write, contents: read }
strategy:
matrix: { language: [javascript, python] }
steps:
- uses: actions/checkout@v4
- uses: github/codeql-action/init@v3
with: { languages: '${{ matrix.language }}', queries: security-extended }
- uses: github/codeql-action/analyze@v3
# third-party SAST (Semgrep, Snyk, ESLint security) lands in the same UI:
- uses: github/codeql-action/upload-sarif@v3
with: { sarif_file: results.sarif }
💡 Point
runs-onat a self-hosted runner and the Actions minutes are not billed — the first lever when scan cost bites at scale.
Pricing: three meters 📖 Docs
▸ + UNFOLDS THE DETAIL
Eligibility by repository type 📖 Docs
| Feature | Public repo | Private repo without Code Security | Private repo with Code Security |
|---|---|---|---|
| Core code scanning | ✅ Free | ❌ | ✅ Included |
| Security campaigns | ❌ | ❌ | ✅ Included |
| Actions minutes | Free* | Not applicable | Separate usage* |
📦 Core: CodeQL, custom queries, SARIF uploads, eligible Autofix suggestions, PR annotations and Security overview.
💰 Actions*: standard hosted runners are free for public repos. Private repos consume included minutes, then bill overages. Larger runners are always billed.
⚠️ Public → private: Code Security is required to keep code scanning enabled.
Code Security Risk Assessment (free inventory scan)
One click, CodeQL scans the 20 most active repos in your org and shows where the vulnerabilities are. No GHAS / Code Security license needed, completely free (GA April 2026).
- 🔎 Scope — up to 20 repos with the most recent commits, re-selectable each run
- 📊 Output — report by severity, language, rule type, plus how many Copilot Autofix can fix
- 🕒 Frequency — re-runnable once every 90 days; org owners / security managers only
- 🚀 How to run —
Org → Security → Assessments → Run code security risk assessment - 🆓 Cost — no license, no Actions minutes — ideal for evaluating Code Security before buying
📊 Pair this with Secret Risk Assessment (see Secret Scanning ↗) and you get a full posture read in a single day, then decide on Code Security with real numbers.
📘 Details: Code security risk assessment ↗ / How exposed is your code? ↗