CodeQL on GitHub Actions: cheaper and faster scans
What CodeQL code scanning costs in GitHub Actions minutes, and how to cut it: incremental analysis, build mode none, path filters, and cheaper runners.
In this series25 guides, you're on Cheaper CodeQL scans
CodeQL is GitHub’s code scanning engine. It doesn’t run on GitHub’s side for free: every scan is a GitHub Actions job, billed like any other job. On a busy private repository it is often one of the largest workflows on the bill, because it runs on every pull request commit, once per language, and each run can take from a few minutes to more than an hour.
This guide covers what a scan costs, how to see what yours cost, and the settings that lower the number, from the free ones to moving the scan to cheaper runners. It ends with timings of five real scans on GitHub and RunsOn runners.
What a scan costs#
Code scanning has two costs. The first is the GitHub Code Security ↗ license, which private and internal repositories need, and which nothing on this page changes. The second is compute:
- In public repositories, scans on standard GitHub-hosted runners are free.
- In private repositories, scans draw from your plan’s included compute, then cost the runner’s per-minute price: $0.006 a minute on the standard Linux runner.
- On larger runners, scans are billed in public repositories too.
- On self-hosted runners, scans cost nothing on GitHub’s bill. You pay for the machine.
How many minutes depends on how often the scan runs. Default setup scans:
- each push to the default branch and to protected branches,
- each commit pushed to a pull request that targets one of those branches (pull requests from forks excluded),
- once a week, as long as the repository saw a push or a pull request scan in the last 180 days.
It starts one job per language, in parallel. Each job is rounded up to a whole minute.
As an example, take a repository with 2 languages whose scans take 12 minutes each, and 40 scans per working day: 2 × 12 × 40 × 21 days = 20,160 minutes a month, or $121 on standard Linux runners. Swift is the expensive case: its scans run on macOS runners, at $0.062 a minute.
Find what CodeQL costs you#
In the organization, open Insights → Actions Usage Metrics. The Workflows tab lists the minutes each workflow used over the period you pick, and the Jobs tab the minutes of each job, so one line per scanned language. Default setup appears as a workflow named CodeQL; an advanced setup has the name you gave your workflow. See GitHub’s metrics guide ↗ for who can open the page.
These figures are minutes of run time, not billed amounts: multiply them by the runner’s rate. In a single repository, the Actions tab filtered on the CodeQL workflow shows how long each run took.
1. Check that pull request scans are incremental#
Since 2026, CodeQL can scan a pull request without rebuilding its database from scratch. It builds a database for the changed code only, and combines it with a cached database of the whole codebase, saved by the last scan of the default branch. GitHub calls this improved incremental analysis ↗. It is on by default, in default setup and advanced setup, when all of these hold:
- The language is C#, Java, JavaScript/TypeScript, Python or Ruby (since March 2026), or C/C++ or Go (since June 2026 ↗).
- Compiled languages other than Go use build mode
none. - The scan runs the default query suite. Adding
security-extendedor your own queries turns it off. - An advanced setup uses a current
github/codeql-action(@v4), and scans both pushes to the default branch and pull requests.
For C/C++ and Go, GitHub measured pull request scans 9% to 46% faster, depending on the language and on how long the full scan takes.
The cached database is stored in the repository’s Actions cache, so it counts toward the cache’s 10 GB allowance. If caches are evicted before pull requests can use them, scans fall back to a full analysis.
2. Skip the build with build mode none#
For compiled languages, CodeQL traditionally watches a real build of your code (autobuild or manual build mode), and the build is often most of the job. With build mode none, it reads the source files directly and builds nothing. It is available for C/C++, C#, Java and Rust. Go, Kotlin and Swift still need a build.
Default setup picks none where it can, but a repository set up earlier, or an advanced workflow written before the mode existed, may still build. In an advanced setup, set it per language:
- uses: github/codeql-action/init@v4 with: languages: java-kotlin build-mode: noneOn Apache Kafka, the scan in build mode none took 20.9 min on GitHub’s standard runner, against 36.4 min with autobuild (measured below).
The trade-off is accuracy. Without a build, CodeQL has to guess some dependencies and doesn’t see code generated during the build, so results can be less complete ↗ for Java projects that generate code, or for C/C++ code that leans on macros and external headers. Compare the alerts of one run in each mode before you switch.
3. Don’t scan pull requests that change no code#
A pull request that only touches documentation doesn’t need a scan. In an advanced setup, a path filter on the trigger skips the whole workflow:
on: push: branches: [main] pull_request: branches: [main] paths-ignore: - "**/*.md" - "docs/**"Two things to know:
- The filter decides whether the workflow runs, not which files are analyzed. A pull request that changes one source file and ten Markdown files gets a normal scan.
- A workflow skipped by a path filter reports no status. If CodeQL is a required check, the pull request waits forever.
Default setup has no trigger filter, so this one needs advanced setup.
4. Leave out code that can’t matter#
Separately from triggers, a CodeQL configuration file can exclude directories from the analysis itself: vendored dependencies, generated code, test fixtures.
paths-ignore: - "**/vendor/**" - "**/*.generated.ts" - "test/fixtures/**"Pass the file to the init step with config-file: ./.github/codeql/codeql-config.yml. It also works with default setup, through the github-codeql-config-file repository property ↗.
paths and paths-ignore apply to interpreted languages and to compiled languages in build mode none. When CodeQL watches a build, it analyzes whatever the build compiles, so the way to shrink the scan is to build less.
5. Cancel scans of outdated commits#
When a new commit lands on a pull request, the scan of the previous commit is wasted. In an advanced setup, a concurrency group cancels it:
concurrency: group: ${{ github.workflow }}-${{ github.head_ref || github.run_id }} cancel-in-progress: trueScans of the default branch each get their own group, so they always finish. That matters: they produce the cached database that incremental pull request scans start from.
6. Keep the default query suite on pull requests#
CodeQL ships two suites per language: default, and the larger security-extended. More queries take longer, and anything other than the default suite disables improved incremental analysis. If you want the extended suite, run it where time matters less, on the weekly schedule:
- uses: github/codeql-action/init@v4 with: languages: ${{ matrix.language }} queries: ${{ github.event_name == 'schedule' && 'security-extended' || '' }}7. Cache dependencies for Java, Go and C##
Builds and build mode none both download dependencies to resolve types. For Java, Go and C#, codeql-action can keep them in the Actions cache:
- uses: github/codeql-action/init@v4 with: languages: go dependency-caching: trueIt is off by default in advanced setup. Default setup turns it on, but only on GitHub-hosted runners.
8. Give CodeQL enough memory#
CodeQL uses all the cores and most of the memory it finds, and slows down sharply when memory is short. GitHub’s recommended hardware ↗:
| Codebase | RAM | CPU |
|---|---|---|
| Under 100,000 lines of code | 8 GB or more | 2 cores |
| 100,000 to 1 million lines | 16 GB or more | 4 or 8 cores |
| Over 1 million lines | 64 GB or more | 8 cores |
The standard runner in a private repository has 2 vCPUs and 8 GB: the first row. A larger codebase belongs on a bigger machine, and that is where the price per minute decides whether the scan gets cheaper or only faster.
| vCPUs | RAM on GitHub | GitHub Linux x64 | RunsOn Linux x64 |
|---|---|---|---|
| 2 | 8 GB | $0.006 | $0.0008 |
| 4 | 16 GB | $0.012 | $0.0013 |
| 8 | 32 GB | $0.022 | $0.0024 |
| 16 | 64 GB | $0.042 | $0.0034 |
Prices are per minute. GitHub’s are from its pricing page ↗ as of November 2026. RunsOn prices are 7-day EC2 spot averages in us-east-1, instance plus its EBS volume, in your own AWS account. They don’t include RunsOn’s flat yearly license, which is free for non-commercial use (see pricing). RunsOn’s 8- and 16-vCPU runners pick instances with 2 or 4 GB per vCPU: add a ram label to set the memory.
On GitHub, each doubling of vCPUs about doubles the price, so a larger runner lowers the bill only if the scan then takes half the time or less. Measure one scan on each size before you commit. Larger runners need the Team or Enterprise Cloud plan; for default setup, name the runner code-scanning ↗ or select it by label.
9. Run CodeQL on your own runners#
Self-hosted runners take the scan off GitHub’s bill entirely, and let you pick the memory the codebase needs. Both setups support them: advanced setup through runs-on:, default setup through a runner label in the repository or organization security settings.
Two caveats. In a public repository, standard runners are already free, so there is nothing to save unless the scan needs a bigger machine. And CodeQL builds your code with autobuild for some languages, so the runner needs the same toolchains as GitHub’s image.
On RunsOn#
RunsOn runs each job on a fresh EC2 instance in your AWS account, sized by the job’s label. The advanced setup from this guide, on a 4-vCPU, 16 GB on-demand runner:
name: CodeQL
on: push: branches: [main] pull_request: branches: [main] paths-ignore: - "**/*.md" schedule: - cron: "30 4 * * 1"
concurrency: group: ${{ github.workflow }}-${{ github.head_ref || github.run_id }} cancel-in-progress: true
permissions: actions: read contents: read security-events: write
jobs: analyze: name: Analyze (${{ matrix.language }}) runs-on: runs-on=${{ github.run_id }}/runner=4cpu-linux-x64/spot=false strategy: fail-fast: false matrix: include: - language: javascript-typescript build-mode: none - language: java-kotlin build-mode: none - language: go build-mode: autobuild steps: - uses: actions/checkout@v7 - uses: github/codeql-action/init@v4 with: languages: ${{ matrix.language }} build-mode: ${{ matrix.build-mode }} dependency-caching: true - uses: github/codeql-action/analyze@v4 with: category: "/language:${{ matrix.language }}"At $0.0044 a minute on-demand, the same minutes as the example repository from the top of this page (20,160 a month) cost about $88 of EC2, against $121 on GitHub’s standard runner. In practice the scans also finish sooner on the bigger machine, 2.7 to 3.5 times sooner in our measurements, so each scan cost 3 to 5 times less.
Spot or on-demand#
RunsOn launches runners on spot instances by default, at $0.0013 a minute for this runner. For CodeQL we recommend on-demand, which is what spot=false asks for in the workflow above:
- A scan can’t resume. When AWS reclaims a spot instance, the job fails and the analysis starts again from the checkout. Scans are among the longest jobs of a repository, so an interruption throws away more work than it does on a 3-minute test job.
- Default setup has no re-run. RunsOn recovers an interrupted spot job by asking GitHub to re-run the failed jobs of the workflow run. That works for the workflow above. For default setup, GitHub’s documentation describes no re-run: to get a new analysis, it tells you to trigger one, for example by pushing a commit. An interrupted scan would stay a failed check on the pull request until then, so give default setup an on-demand runner fleet.
- On-demand is already the cheaper option. The 3 to 5 times above are on-demand prices.
Spot remains reasonable for short scans in advanced setup: remove spot=false, and RunsOn re-runs an interrupted job up to twice, on on-demand capacity.
A codebase that needs more memory than cores can ask for it with the ram label, where GitHub’s sizes fix the memory per core:
runs-on: runs-on=${{ github.run_id }}/cpu=8/ram=64/family=r8Default setup works too, without a workflow file, on a RunsOn Fleet runner selected by label. The steps, and why default setup can’t target Flex runners, are in CodeQL code scanning on RunsOn.
Measured: five scans on GitHub and RunsOn runners#
To put numbers on sections 2, 8 and 9, we scanned four open-source projects at a pinned release, five times on each runner, in November 2026. Each scan is a full analysis with the default query suite, no caches, and nothing uploaded. Times are the median job duration, from checkout to the end of the analysis.
| Scan | GitHub 2 vCPUs, 8 GB | GitHub 4 vCPUs, 16 GB | RunsOn 4 vCPUs, 16 GB | RunsOn 8 vCPUs, 32 GB |
|---|---|---|---|---|
| Kafka 4.1.0, Java, build mode none | 20.9 min | 13.7 min | 7.8 min | 7.0 min |
| Kafka 4.1.0, Java, autobuild | 36.4 min | 18.1 min | 10.4 min | 7.5 min |
| Grafana 12.2.0, TypeScript | 13.4 min | 7.0 min | 4.7 min | 3.8 min |
| Terraform 1.13.4, Go | 12.5 min | 7.4 min | 4.2 min | 3.4 min |
| Django 5.2.7, Python | 7.5 min | 4.2 min | 2.8 min | 2.5 min |
And what one scan costs, at each runner’s price per minute:
| Scan | GitHub 2 vCPUs | GitHub 4 vCPUs | RunsOn 4 vCPUs, on-demand | RunsOn 4 vCPUs, spot |
|---|---|---|---|---|
| Kafka 4.1.0, Java, build mode none | $0.126 | $0.168 | $0.036 | $0.011 |
| Kafka 4.1.0, Java, autobuild | $0.222 | $0.228 | $0.048 | $0.014 |
| Grafana 12.2.0, TypeScript | $0.084 | $0.096 | $0.023 | $0.007 |
| Terraform 1.13.4, Go | $0.078 | $0.096 | $0.021 | $0.006 |
| Django 5.2.7, Python | $0.048 | $0.060 | $0.015 | $0.004 |
What the numbers say:
- A GitHub runner twice the size doesn’t lower the bill. The 4-vCPU runner finished in 50% to 65% of the time, at twice the price per minute, so every scan cost as much or more than on 2 vCPUs.
- The RunsOn 4-vCPU runner was 2.7 to 3.5 times faster than GitHub’s 2-vCPU runner, and 1.5 to 1.8 times faster than GitHub’s runner with the same 4 vCPUs and 16 GB. Its instance type (
m8a.xlarge) has faster cores. - Each scan cost 3 to 5 times less on RunsOn at on-demand prices, and 10 to 16 times less on spot, compared with GitHub’s 2-vCPU runner. For CodeQL we recommend on-demand.
- 8 vCPUs helped little, and 64 GB not at all. Doubling the cores cut 10% to 28% off the time. A third RunsOn runner with 8 vCPUs and 64 GB matched the 32 GB one within a few seconds on every scan. Size the runner for the codebase, not above it.
- Times varied more on GitHub. The Kafka scan in build mode
noneranged from 17 to 22 minutes on the 2-vCPU runner over five runs, and from 7.7 to 7.9 minutes on RunsOn.
How the costs are computed: GitHub rounds each job up to a whole minute, at $0.006 and $0.012 a minute. The RunsOn jobs ran on on-demand instances in us-east-1. Their cost is the job plus the 35 seconds or so of boot and shutdown that EC2 bills, at the instance’s on-demand price plus its EBS volume. The spot column applies the 7-day average spot price to the same durations. The GitHub 2-vCPU runner here is a larger runner of that size in a public repository, the same shape and price as the standard runner of private repositories. The 4-vCPU one is the free standard runner of public repositories, priced as the 4-vCPU larger runner a private repository would pay for. The RunsOn license is not included.
The workflow, the pinned commits and the logs of every run are public in runs-on-demo/benchmark-public ↗. Pull request scans with incremental analysis are not part of this measurement.
Where to start#
- Look up the CodeQL workflow’s minutes in the usage metrics.
- Open a recent pull request scan and check that its compiled languages use build mode
none, and that it runs the default suite. - If you are on advanced setup, add the path filter and the concurrency group.
- If scans are still long, compare one run on a machine that matches GitHub’s hardware table with one on the standard runner, then pick the cheapest runner of that size.