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.
What is SAST?
Application security testing splits into four families. Code Scanning owns SAST (Static Application Security Testing): reading the source itself, without executing it.
๐ Rule of thumb โ SAST finds bugs in the code you wrote, SCA finds bugs in the code someone else wrote. Different territory, so neither one covers the other.
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.
Default setup vs Advanced setup
There are two ways to enable CodeQL. Default setup is enough to start.
๐ Unless you have a monorepo, special build requirements, or need custom queries, start with Default setup โ you can switch to Advanced later without losing history.
๐ Details: Configuring default setup โ
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 backlog alerts without cloud agent: Generate fix โ Create PR with fix.
- ๐ 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 (Public Preview) ๐ Docs
When cloud agent is available, Assign to Copilot replaces Generate fix on individual code scanning alerts.
- ๐ฏ Assign: one alert, or 1โ25 alerts from a repository backlog or security campaign.
- ๐ Agent session: explore the codebase โ generate a fix โ validate and iterate โ open a draft PR.
- ๐ Requirements: cloud agent and Autofix must both be available. No pre-generated Autofix suggestion is required.
- ๐ธ Cost: AI credits + Actions minutes. Without cloud agent, the classic Generate fix flow remains available for eligible alerts.
- โ ๏ธ Validation is best-effort: custom queries,
security-extendedand third-party alerts are not guaranteed to be validated.
Autofix vs Agentic Autofix ๐ Docs
๐ On individual alert pages, repository availability determines the button: cloud agent available โ Assign to Copilot; otherwise โ Generate fix for eligible alerts. PR inline Autofix suggestions remain a separate experience.
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) โ
Getting started (fastest path)
Repo โ Settings โ Code security
โธ STEP 1 ยท DEFAULT SETUP
Set up CodeQL โ Default. Languages are detected for you; it runs on push and PR.
Alert โ Fix
โธ STEP 2 ยท AUTOFIX
Cloud agent available: Assign to Copilot (metered). Otherwise: Generate fix for eligible alerts (no AI credits).
Org โ Settings โ Code security
โธ STEP 3 ยท ROLL OUT
Build a security configuration and apply it to new and existing repos at once.
Repo โ Settings โ Rules
โธ STEP 4 ยท MERGE PROTECTION
Code scanning alone never blocks a merge. Make it required in a ruleset.
Results appear in the Security tab and the PRโs Files changed tab. Start with one repo and estimate Actions usage before rolling out.
Advanced setup and SARIF
When Default is not enough (monorepo, unusual build, custom queries, 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? โ