What Is CodeQL? How GitHub's Query-Based Code Scanning Works (2026)
A practical explainer of CodeQL - how treating code as a queryable database finds vulnerabilities, how to enable code scanning, and how it compares to Semgrep and Snyk.
Published:
What is CodeQL?
CodeQL is a static analysis engine, built by GitHub, that treats your codebase as a database you can run queries against. Most scanners look at code as text and hunt for suspicious patterns with regular expressions. CodeQL does something more ambitious - it compiles your source into a relational database that captures the code’s structure, control flow, and data flow, and then lets you interrogate that database with a purpose-built query language called QL. Asking “is there any path where user input reaches a SQL statement without being sanitized?” becomes a literal query, and the engine finds every such path across the whole program.
That reframing is the whole idea. Once code is a database, finding a vulnerability is a search problem rather than a guessing game. A well-written query can trace tainted data from an HTTP request, through half a dozen function calls and files, into a dangerous sink, and report the exact path. This is why CodeQL is strong at the vulnerability classes that defeat pattern-only tools - injection, unsafe deserialization, path traversal - the kinds of flaws catalogued in the OWASP Top 10. It sits firmly in the SAST category of security tooling.
How CodeQL works, step by step
CodeQL analysis happens in three distinct phases. Understanding them explains both its power and its cost.
- Database creation. CodeQL extracts a database from your source. For interpreted languages like Python or JavaScript it reads the code directly. For compiled languages like Java or C++ it must observe the build - it watches the compiler run so it can capture exactly what gets compiled and how. This build dependency is why CodeQL setup is heavier than a text scanner.
- Query execution. The engine runs QL queries against that database. Each query is a logical program that describes a pattern of interest - a source of untrusted data, a dangerous sink, and the absence of a sanitizer between them. GitHub maintains extensive open-source query packs, so you inherit thousands of expert-written security queries without authoring any yourself.
- Results as alerts. Matches become code scanning alerts, each with the dataflow path that produced it, mapped to a CWE identifier so you know the weakness class. In GitHub, these appear in the Security tab and can annotate the pull request directly.
The signature capability here is taint tracking - following untrusted data as it flows through the program. A pattern matcher sees a single line; CodeQL sees the journey. That whole-program dataflow model is what lets it catch a vulnerability whose source and sink live in completely different files.
The QL query language
QL is a declarative, logic-based query language. You do not write step-by-step instructions; you describe the shape of what you are looking for and let the engine find every instance. An illustrative security query reads roughly like this:
// Illustrative - find user input flowing into a SQL query
import python
import semmle.python.dataflow.new.TaintTracking
from RemoteFlowSource source, SqlExecution sink
where TaintTracking::localTaint(source, sink)
select sink, "Untrusted data reaches a SQL query from $@.", source, "here"
You rarely need to write queries like this. Most teams run the standard packs. But the option matters - when your codebase has a custom sink or a project-specific dangerous API, you can extend the libraries to teach CodeQL about it, which is how large security teams tune the tool to their own frameworks.
Enabling CodeQL with GitHub code scanning
For the majority of users, CodeQL is not a standalone tool you install - it is the engine behind GitHub code scanning. Turning it on is a workflow decision, not a research project.
- Default setup is the fast path. In a repository’s Security settings, enable code scanning with CodeQL default setup and GitHub configures a workflow that scans on push and pull request automatically, choosing sensible query suites for your detected languages.
- Advanced setup gives you a
codeql-analysis.ymlGitHub Actions workflow you control - useful when you need custom build steps, specific query packs, or a particular schedule. If you already run AI code review in GitHub Actions, CodeQL slots into the same pipeline. - Pull request integration is where it earns its keep. New alerts introduced by a PR are posted as checks, so a vulnerability is caught before merge rather than in a later audit - the essence of shift-left security.
On cost - CodeQL code scanning is free for public repositories. For private repositories it is part of GitHub Advanced Security, a paid add-on. That licensing reality is often the deciding factor between CodeQL and an alternative.
How CodeQL compares to other SAST tools
CodeQL is powerful but opinionated, and it is not the only serious option. The right choice depends on your ecosystem, your appetite for setup, and how much analytical depth you actually need.
Semgrep is the most common alternative and the clearest contrast. Semgrep matches patterns against a lighter syntactic and dataflow model, which makes its rules dramatically faster to write - they look almost like the code they match - and its scans quicker. CodeQL goes deeper with full whole-program dataflow but pays for it in setup and query complexity. Semgrep also runs anywhere with a free open-source engine, while CodeQL is happiest inside GitHub. Our head-to-head Semgrep vs CodeQL guide breaks down exactly when each wins.
Snyk Code takes a third path - AI-assisted SAST through its DeepCode engine, with auto-fix suggestions and tight coupling to dependency scanning. It trades CodeQL’s query flexibility for a more turnkey, developer-first experience. See Snyk vs CodeQL for the comparison and our best SAST tools roundup for the wider field.
None of these are mutually exclusive with an AI reviewer. CodeRabbit and similar tools catch a different class of issue - logic bugs, missing tests, review-level concerns - and pair well with a dedicated SAST engine running underneath.
In short - reach for CodeQL when you live in GitHub, need deep dataflow analysis, and can absorb the setup; reach for Semgrep when you want fast, portable, easy-to-write rules.
When CodeQL is the right tool
CodeQL is an excellent fit when three things are true - your code is on GitHub, you have a real need for deep security analysis rather than surface linting, and you either work in the open (where it is free) or already pay for Advanced Security. Security-conscious teams building anything that handles untrusted input benefit most, because taint tracking is where CodeQL genuinely outclasses lighter tools.
It is a weaker fit when you are outside GitHub, when your team lacks the appetite to manage build-integrated scanning, or when you mainly want fast, low-friction checks in the pull request. In those cases a portable tool like Semgrep, or an AI reviewer for logic-level feedback, often delivers more value per hour of setup.
Conclusion
CodeQL’s core insight is simple and powerful - turn code into a queryable database and finding vulnerabilities becomes a search, complete with the exact dataflow path from untrusted source to dangerous sink. Most teams consume it through GitHub code scanning without ever writing a query, getting deep taint-tracking security analysis on every pull request. It is free for open source and part of GitHub Advanced Security for private repos. Weigh it against faster, more portable tools like Semgrep and turnkey options like Snyk Code, pick based on your ecosystem and your need for depth, and run it in the pull request where a caught vulnerability is still cheap to fix.
Further reading
Further Reading
GitarComments are not enough
Gitar applies the fix, validates it in CI, and clears the queue.
See it on your repo Read our independent Gitar reviewFrequently Asked Questions
What is CodeQL in simple terms?
CodeQL is a static analysis engine from GitHub that treats your source code as a database you can run queries against. Instead of scanning text with regular expressions, it builds a rich structural and dataflow model of the code, then you write queries in a dedicated language, also called QL, to ask questions like 'is there a path where untrusted input reaches a SQL query without sanitization?' GitHub ships large libraries of ready-made security queries, so most teams use CodeQL through GitHub code scanning without writing any queries themselves.
Is CodeQL free?
CodeQL is free for open-source repositories on GitHub through the code scanning feature. For private repositories, CodeQL code scanning is included with GitHub Advanced Security, which is a paid add-on for GitHub Enterprise and is also available for GitHub Team plans. The CodeQL CLI and query libraries can be used at no cost for research, open-source projects, and academic purposes under GitHub's license terms, but automated analysis of private company code generally requires the Advanced Security license.
What is the difference between CodeQL and Semgrep?
Both are static analysis tools, but they trade off depth against ease of use. CodeQL builds a full semantic database and excels at deep, whole-program dataflow queries, which makes it powerful but slower and steeper to learn. Semgrep matches patterns against a lightweight syntactic and dataflow model, so its rules are faster to write and its scans are quicker, at the cost of some analytical depth. CodeQL is tightly bound to the GitHub ecosystem, while Semgrep runs anywhere and has a free open-source engine.
What languages does CodeQL support?
CodeQL supports a focused set of major languages including C and C++, C#, Go, Java and Kotlin, JavaScript and TypeScript, Python, Ruby, Swift, and GitHub Actions workflows. Compiled languages require CodeQL to observe the build so it can construct an accurate database, while interpreted languages can be analyzed directly. The exact supported list expands over time, so check GitHub's documentation for the current set before planning a rollout.
Explore More
Tool Reviews
Free Newsletter
Stay ahead with AI dev tools
Weekly insights on AI code review, static analysis, and developer productivity. No spam, unsubscribe anytime.
Join developers getting weekly AI tool insights.
Related Articles
Is CodeRabbit Free for Open Source? Yes - And for Private Repos Too
CodeRabbit's free tier covers unlimited public and private repositories, not just open source. Here is exactly what the free plan includes, where the rate limits bite, and when to pay.
July 31, 2026
guideIs SonarLint Deprecated? No - Here's What Actually Happened
SonarLint was not deprecated. It was renamed to SonarQube for IDE on October 29, 2024, as part of a company-wide rebrand. Here is what changed, what did not, and what to install.
July 31, 2026
guideIs Semgrep Free for Commercial Use? Yes, With Two Catches
Semgrep Community Edition is LGPL-2.1 and free for commercial use. The paid tier is also free up to 10 contributors. Here is where the line actually falls and what you give up.
July 31, 2026
Semgrep Review
Snyk Code Review
CodeRabbit Review