Install any skill in seconds. Free to start, no credit card required.
Get Started Free →Comprehensive guide for setting up and configuring CodeQL code scanning via GitHub Actions workflows and the CodeQL CLI. This skill should be used when users need help with code scanning configuration, CodeQL workflow files, CodeQL CLI commands, SARIF output, security analysis setup, or troubleshooting CodeQL analysis.
| Test case | Without → With | Effect | Δ tokens | Δ turns |
|---|---|---|---|---|
| case-17 | ✗→✓ | ▲ Improved | — | — |
| case-18 | ✗→✓ | ▲ Improved | — | — |
| case-01 | ✗→✓ | ▲ Improved | — | — |
| case-06 | ✗→✓ | ▲ Improved | — | — |
| case-07 | ✗→✓ | ▲ Improved | — | — |
This skill provides procedural guidance for configuring and running CodeQL code scanning — both through GitHub Actions workflows and the standalone CodeQL CLI.
Use this skill when the request involves:
codeql.yml GitHub Actions workflowcodeql database create, database analyze, github upload-results)CodeQL supports the following language identifiers:
| Language | Identifier | Alternatives | |---|---|---| | C/C++ | c-cpp | c, cpp | | C# | csharp | — | | Go | go | — | | Java/Kotlin | java-kotlin | java, kotlin | | JavaScript/TypeScript | javascript-typescript | javascript, typescript | | Python | python | — | | Ruby | ruby | — | | Rust | rust | — | | Swift | swift | — | | GitHub Actions | actions | — |
> Alternative identifiers are equivalent to the standard identifier (e.g., javascript does not exclude TypeScript analysis).
none build mode for most languages..github/workflows/codeql.yml file for full control over triggers, build modes, query suites, and matrix strategies.To switch from default to advanced: disable default setup first, then commit the workflow file.
Define when scanning runs:
yamlon: push: branches: [main, protected] pull_request: branches: [main] schedule: - cron: '30 6 * * 1' # Weekly Monday 6:30 UTC
push — scans on every push to specified branches; results appear in Security tabpull_request — scans PR merge commits; results appear as PR check annotationsschedule — periodic scans of the default branch (cron must exist on default branch)merge_group — add if repository uses merge queuesTo skip scans for documentation-only PRs:
yamlon: pull_request: paths-ignore: - '**/*.md' - '**/*.txt'
> paths-ignore controls whether the workflow runs, not which files are analyzed.
Set least-privilege permissions:
yamlpermissions: security-events: write # Required to upload SARIF results contents: read # Required to checkout code actions: read # Required for private repos using codeql-action
Use a matrix strategy to analyze each language in parallel:
yamljobs: analyze: name: Analyze (${{ matrix.language }}) runs-on: ubuntu-latest strategy: fail-fast: false matrix: include: - language: javascript-typescript build-mode: none - language: python build-mode: none
For compiled languages, set the appropriate build-mode:
none — no build required (supported for C/C++, C#, Java, Rust)autobuild — automatic build detectionmanual — custom build commands (advanced setup only)> For detailed per-language autobuild behavior and runner requirements, search references/compiled-languages.md.
yamlsteps: - name: Checkout repository uses: actions/checkout@v4 - name: Initialize CodeQL uses: github/codeql-action/init@v4 with: languages: ${{ matrix.language }} build-mode: ${{ matrix.build-mode }} queries: security-extended dependency-caching: true - name: Perform CodeQL Analysis uses: github/codeql-action/analyze@v4 with: category: "/language:${{ matrix.language }}"
Query suite options:
security-extended — default security queries plus additional coveragesecurity-and-quality — security plus code quality queriespacks: input (e.g., codeql/javascript-queries:AlertSuppression.ql)Dependency caching: Set dependency-caching: true on the init action to cache restored dependencies across runs.
Analysis category: Use category to distinguish SARIF results in monorepos (e.g., per-language, per-component).
For monorepos with multiple components, use the category parameter to separate SARIF results:
yamlcategory: "/language:${{ matrix.language }}/component:frontend"
To restrict analysis to specific directories, use a CodeQL configuration file (.github/codeql/codeql-config.yml):
yamlpaths: - apps/ - services/ paths-ignore: - node_modules/ - '**/test/**'
Reference it in the workflow:
yaml- uses: github/codeql-action/init@v4 with: config-file: .github/codeql/codeql-config.yml
If autobuild fails or custom build commands are needed:
yaml- language: c-cpp build-mode: manual
Then add explicit build steps between init and analyze:
yaml- if: matrix.build-mode == 'manual' name: Build run: | make bootstrap make release
Download the CodeQL bundle (includes CLI + precompiled queries):
bash# Download from https://github.com/github/codeql-action/releases # Extract and add to PATH export PATH="$HOME/codeql:$PATH" # Verify installation codeql resolve packs codeql resolve languages
> Always use the CodeQL bundle, not a standalone CLI download. The bundle ensures query compatibility and provides precompiled queries for better performance.
bash# Single language codeql database create codeql-db \ --language=javascript-typescript \ --source-root=src # Multiple languages (cluster mode) codeql database create codeql-dbs \ --db-cluster \ --language=java,python \ --command=./build.sh \ --source-root=src
For compiled languages, provide the build command via --command.
bashcodeql database analyze codeql-db \ javascript-code-scanning.qls \ --format=sarif-latest \ --sarif-category=javascript \ --output=results.sarif
Common query suites: <language>-code-scanning.qls, <language>-security-extended.qls, <language>-security-and-quality.qls.
bashcodeql github upload-results \ --repository=owner/repo \ --ref=refs/heads/main \ --commit=<commit-sha> \ --sarif=results.sarif
Requires GITHUB_TOKEN environment variable with security-events: write permission.
To avoid repeated JVM initialization when running multiple commands:
bashcodeql execute cli-server
> For detailed CLI command reference, search references/cli-commands.md.
Alerts have two severity dimensions:
Error, Warning, NoteCritical, High, Medium, Low (derived from CVSS scores; takes display precedence)GitHub Copilot Autofix generates fix suggestions for CodeQL alerts in pull requests automatically — no Copilot subscription required. Review suggestions carefully before committing.
error/critical/high severity alerts> For detailed alert management guidance, search references/alert-management.md.
yaml- uses: github/codeql-action/init@v4 with: packs: | my-org/my-security-queries@1.0.0 codeql/javascript-queries:AlertSuppression.ql
Use the CodeQL CLI to create and publish packs:
bash# Initialize a new pack codeql pack init my-org/my-queries # Install dependencies codeql pack install # Publish to GitHub Container Registry codeql pack publish
For advanced query and path configuration, create .github/codeql/codeql-config.yml:
yamlpaths: - apps/ - services/ paths-ignore: - '**/test/**' - node_modules/ queries: - uses: security-extended packs: javascript-typescript: - my-org/my-custom-queries
Workflow logs include key metrics:
To enable detailed diagnostics:
--verbosity=progress++ and --logdir=codeql-logs| Problem | Solution | |---|---| | Workflow not triggering | Verify on: triggers match event; check paths/branches filters; ensure workflow exists on target branch | | Resource not accessible error | Add security-events: write and contents: read permissions | | Autobuild failure | Switch to build-mode: manual and add explicit build commands | | No source code seen | Verify --source-root, build command, and language identifier | | C# compiler failure | Check for /p:EmitCompilerGeneratedFiles=true conflicts with .sqlproj or legacy projects | | Fewer lines scanned than expected | Switch from none to autobuild/manual; verify build compiles all source | | Kotlin in no-build mode | Disable and re-enable default setup to switch to autobuild | | Cache miss every run | Verify dependency-caching: true on init action | | Out of disk/memory | Use larger runners; reduce analysis scope via paths config; use build-mode: none | | SARIF upload fails | Ensure token has security-events: write; check 10 MB file size limit | | SARIF results exceed limits | Split across multiple uploads with different --sarif-category; reduce query scope | | Two CodeQL workflows | Disable default setup if using advanced setup, or remove old workflow file | | Slow analysis | Enable dependency caching; use --threads=0; reduce query suite scope |
> For comprehensive troubleshooting with detailed solutions, search references/troubleshooting.md.
| Codebase Size | RAM | CPU | |---|---|---| | Small (<100K LOC) | 8 GB+ | 2 cores | | Medium (100K–1M LOC) | 16 GB+ | 4–8 cores | | Large (>1M LOC) | 64 GB+ | 8 cores |
All sizes: SSD with ≥14 GB free disk space.
Pin CodeQL actions to a specific major version:
yamluses: github/codeql-action/init@v4 # Recommended uses: github/codeql-action/autobuild@v4 uses: github/codeql-action/analyze@v4
For maximum security, pin to a full commit SHA instead of a version tag.
For detailed documentation, load the following reference files as needed:
references/workflow-configuration.md — Full workflow trigger, runner, and configuration optionstrigger, schedule, paths-ignore, db-location, model packs, alert severity, merge protection, concurrency, config filereferences/cli-commands.md — Complete CodeQL CLI command referencedatabase create, database analyze, upload-results, resolve packs, cli-server, installation, CI integrationreferences/sarif-output.md — SARIF v2.1.0 object model, upload limits, and third-party supportsarifLog, result, location, region, codeFlow, fingerprint, suppression, upload limits, third-party, precision, security-severityreferences/compiled-languages.md — Build modes and autobuild behavior per languageC/C++, C#, Java, Go, Rust, Swift, autobuild, build-mode, hardware, dependency cachingreferences/troubleshooting.md — Comprehensive error diagnosis and resolutionno source code, out of disk, out of memory, 403, C# compiler, analysis too long, fewer lines, Kotlin, extraction errors, debug logging, SARIF upload, SARIF limitsreferences/alert-management.md — Alert severity, triage, Copilot Autofix, and dismissalseverity, security severity, CVSS, Copilot Autofix, dismiss, triage, PR alerts, data flow, merge protection, REST API| Case | Status | Duration (ms) | Turns | Tokens | Tool calls | ||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| Without | With | Δ | Without | With | Δ | Without | With | Δ | Without | With | Δ | ||
case-03 | fail→fail | — | — | — | — | — | — | — | — | — | — | — | — |
case-17 | fail→pass | — | — | — | — | — | — | — | — | — | — | — | — |
case-11 | pass→pass | — | — | — | — | — | — | — | — | — | — | — | — |
case-18 | fail→pass | — | — | — | — | — | — | — | — | — | — | — | — |
case-08 | fail→fail | — | — | — | — | — | — | — | — | — | — | — | — |
case-13 | fail→fail | — | — | — | — | — | — | — | — | — | — | — | — |
case-09 | fail→fail | — | — | — | — | — | — | — | — | — | — | — | — |
case-19 | fail→fail | — | — | — | — | — | — | — | — | — | — | — | — |
case-20 | fail→fail | — | — | — | — | — | — | — | — | — | — | — | — |
case-12 | fail→fail | — | — | — | — | — | — | — | — | — | — | — | — |
case-14 | fail→fail | — | — | — | — | — | — | — | — | — | — | — | — |
case-22 | fail→fail | — | — | — | — | — | — | — | — | — | — | — | — |
case-01 | fail→pass | — | — | — | — | — | — | — | — | — | — | — | — |
case-04 | fail→fail | — | — | — | — | — | — | — | — | — | — | — | — |
case-06 | fail→pass | — | — | — | — | — | — | — | — | — | — | — | — |
case-02 | fail→fail | — | — | — | — | — | — | — | — | — | — | — | — |
case-10 | fail→fail | — | — | — | — | — | — | — | — | — | — | — | — |
case-07 | fail→pass | — | — | — | — | — | — | — | — | — | — | — | — |
case-16 | fail→fail | — | — | — | — | — | — | — | — | — | — | — | — |
case-15 | fail→fail | — | — | — | — | — | — | — | — | — | — | — | — |
case-05 | fail→pass | — | — | — | — | — | — | — | — | — | — | — | — |
case-21 | fail→fail | — | — | — | — | — | — | — | — | — | — | — | — |
DecimalAI ran this skill against gemini-3.6-flash twice over the same eval suite — once with the skill loaded and once without — and compared the two runs case by case. 22 cases were attempted. The headline lift of +27 percentage points is the difference between those two pass rates over the 22 comparable cases.
The per-case answers from this run were removed by the retention sweep, so the case table below shows the verdicts without the text either arm produced. The counts above were recorded at the time and are unaffected. Answers are now kept for 180 days.
Other measured skills in the registry, with their headline benchmark lift.