Codeql
GitHubOfficialFirst committed by VeVarunSharmaDistributed by GitHub
- Skill
- Tool integration
- Security
- MIT
- No issues found
AutoGineer summary
Written by AutoGineer from the skill’s own files, not by the author
This skill provides procedural instructions for setting up CodeQL to perform automated code scanning. It covers both the GitHub Actions workflow integration for automated CI/CD pipelines and the standalone CodeQL CLI for local analysis. The documentation includes details on language support, build modes, query suite selection, SARIF output management, and troubleshooting common analysis issues.
What it does
- Configures CodeQL code scanning within GitHub Actions workflows.
- Provides commands for local database creation and analysis using the CodeQL CLI.
- Explains how to manage and interpret SARIF output files.
- Details how to configure language matrices, build modes, and custom query packs.
- Offers guidance on alert triage, severity levels, and GitHub Copilot Autofix integration.
- Provides troubleshooting steps for common analysis failures and environment requirements.
When to use it
- When setting up automated security scanning in a GitHub repository.
- When you need to run CodeQL analysis locally on a development machine.
- When customizing CodeQL workflows for monorepos or specific build requirements.
- When troubleshooting failed CodeQL analysis or build mode configurations.
- When managing or dismissing security alerts generated by CodeQL.
Advantages
- Supports a wide range of programming languages.
- Integrates directly into GitHub Actions for automated security checks.
- Allows for granular control over analysis via custom query packs and configuration files.
- Provides clear paths for both default and advanced setup scenarios.
- Facilitates local analysis and debugging through the CodeQL CLI.
Usage examples
- “How do I set up a basic CodeQL workflow in GitHub Actions?”
- The agent will provide a template for a .github/workflows/codeql.yml file, explaining the necessary steps for initialization, language matrix configuration, and analysis.
- “How can I run CodeQL locally on my machine?”
- The agent will guide you through downloading the CodeQL bundle, creating a database with the CLI, and running the analysis command to generate a SARIF file.
- “What should I do if my CodeQL autobuild fails?”
- The agent will suggest switching to manual build mode and provide instructions on how to insert custom build commands into your workflow.
- “How do I interpret the severity of a CodeQL alert?”
- The agent will explain the difference between standard severity and security severity, including how CVSS scores influence the reported alert level.
Install
Download the skill as a ZIP:
https://mp-staging.autogineer.com/agent-skills/github/codeql/downloadUnzip it into the cross-client skills folder of your project:
mkdir -p .agents/skills && unzip codeql.zip -d .agents/skills
Documentation by VeVarunSharma
CodeQL Code Scanning
This skill provides procedural guidance for configuring and running CodeQL code scanning — both through GitHub Actions workflows and the standalone CodeQL CLI.
When to Use This Skill
Use this skill when the request involves:
Creating or customizing a
codeql.ymlGitHub Actions workflowChoosing between default setup and advanced setup for code scanning
Configuring CodeQL language matrix, build modes, or query suites
Running CodeQL CLI locally (
codeql database create,database analyze,github upload-results)Understanding or interpreting SARIF output from CodeQL
Troubleshooting CodeQL analysis failures (build modes, compiled languages, runner requirements)
Setting up CodeQL for monorepos with per-component scanning
Configuring dependency caching, custom query packs, or model packs
Supported Languages
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.,
javascriptdoes not exclude TypeScript analysis).
Core Workflow — GitHub Actions
Step 1: Choose Setup Type
Default setup — Enable from repository Settings → Advanced Security → CodeQL analysis. Best for getting started quickly. Uses
nonebuild mode for most languages.Advanced setup — Create a
.github/workflows/codeql.ymlfile 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.
Step 2: Configure Workflow Triggers
Define when scanning runs:
on:
push:
branches: [main, protected]
pull_request:
branches: [main]
schedule:
- cron: '30 6 * * 1' # Weekly Monday 6:30 UTCpush— 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 queues
To skip scans for documentation-only PRs:
on:
pull_request:
paths-ignore:
- '**/*.md'
- '**/*.txt'
paths-ignorecontrols whether the workflow runs, not which files are analyzed.
Step 3: Configure Permissions
Set least-privilege permissions:
permissions:
security-events: write # Required to upload SARIF results
contents: read # Required to checkout code
actions: read # Required for private repos using codeql-actionStep 4: Configure Language Matrix
Use a matrix strategy to analyze each language in parallel:
jobs:
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: noneFor 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.
Step 5: Configure CodeQL Init and Analysis
steps:
- 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 queriesCustom query packs via
packs: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).
Step 6: Monorepo Configuration
For monorepos with multiple components, use the category parameter to separate SARIF results:
category: "/language:${{ matrix.language }}/component:frontend"To restrict analysis to specific directories, use a CodeQL configuration file (.github/codeql/codeql-config.yml):
paths:
- apps/
- services/
paths-ignore:
- node_modules/
- '**/test/**'Reference it in the workflow:
- uses: github/codeql-action/init@v4
with:
config-file: .github/codeql/codeql-config.ymlStep 7: Manual Build Steps (Compiled Languages)
If autobuild fails or custom build commands are needed:
- language: c-cpp
build-mode: manualThen add explicit build steps between init and analyze:
- if: matrix.build-mode == 'manual'
name: Build
run: |
make bootstrap
make releaseCore Workflow — CodeQL CLI
Step 1: Install the CodeQL CLI
Download the CodeQL bundle (includes CLI + precompiled queries):
# 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 languagesAlways use the CodeQL bundle, not a standalone CLI download. The bundle ensures query compatibility and provides precompiled queries for better performance.
Step 2: Create a CodeQL Database
# 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=srcFor compiled languages, provide the build command via --command.
Step 3: Analyze the Database
codeql database analyze codeql-db \
javascript-code-scanning.qls \
--format=sarif-latest \
--sarif-category=javascript \
--output=results.sarifCommon query suites: <language>-code-scanning.qls, <language>-security-extended.qls, <language>-security-and-quality.qls.
Step 4: Upload Results to GitHub
codeql github upload-results \
--repository=owner/repo \
--ref=refs/heads/main \
--commit=<commit-sha> \
--sarif=results.sarifRequires GITHUB_TOKEN environment variable with security-events: write permission.
CLI Server Mode
To avoid repeated JVM initialization when running multiple commands:
codeql execute cli-serverFor detailed CLI command reference, search
references/cli-commands.md.
Alert Management
Severity Levels
Alerts have two severity dimensions:
Standard severity:
Error,Warning,NoteSecurity severity:
Critical,High,Medium,Low(derived from CVSS scores; takes display precedence)
Copilot Autofix
GitHub Copilot Autofix generates fix suggestions for CodeQL alerts in pull requests automatically — no Copilot subscription required. Review suggestions carefully before committing.
Alert Triage in PRs
Alerts appear as check annotations on changed lines
Check fails by default for
error/critical/highseverity alertsConfigure merge protection rulesets to customize the threshold
Dismiss false positives with a documented reason for audit trail
For detailed alert management guidance, search
references/alert-management.md.
Custom Queries and Packs
Using Custom Query Packs
- uses: github/codeql-action/init@v4
with:
packs: |
my-org/[email protected]
codeql/javascript-queries:AlertSuppression.qlCreating Custom Query Packs
Use the CodeQL CLI to create and publish packs:
# Initialize a new pack
codeql pack init my-org/my-queries
# Install dependencies
codeql pack install
# Publish to GitHub Container Registry
codeql pack publishCodeQL Configuration File
For advanced query and path configuration, create .github/codeql/codeql-config.yml:
paths:
- apps/
- services/
paths-ignore:
- '**/test/**'
- node_modules/
queries:
- uses: security-extended
packs:
javascript-typescript:
- my-org/my-custom-queriesCode Scanning Logs
Summary Metrics
Workflow logs include key metrics:
Lines of code in codebase — baseline before extraction
Lines extracted — including external libraries and auto-generated files
Extraction errors/warnings — files that failed or produced warnings during extraction
Debug Logging
To enable detailed diagnostics:
GitHub Actions: re-run the workflow with "Enable debug logging" checked
CodeQL CLI: use
--verbosity=progress++and--logdir=codeql-logs
Troubleshooting
Common Issues
| 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.
Hardware Requirements (Self-Hosted Runners)
| 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.
Action Versioning
Pin CodeQL actions to a specific major version:
uses: github/codeql-action/init@v4 # Recommended
uses: github/codeql-action/autobuild@v4
uses: github/codeql-action/analyze@v4For maximum security, pin to a full commit SHA instead of a version tag.
Reference Files
For detailed documentation, load the following reference files as needed:
references/workflow-configuration.md— Full workflow trigger, runner, and configuration optionsSearch patterns:
trigger,schedule,paths-ignore,db-location,model packs,alert severity,merge protection,concurrency,config file
references/cli-commands.md— Complete CodeQL CLI command referenceSearch patterns:
database create,database analyze,upload-results,resolve packs,cli-server,installation,CI integration
references/sarif-output.md— SARIF v2.1.0 object model, upload limits, and third-party supportSearch patterns:
sarifLog,result,location,region,codeFlow,fingerprint,suppression,upload limits,third-party,precision,security-severity
references/compiled-languages.md— Build modes and autobuild behavior per languageSearch patterns:
C/C++,C#,Java,Go,Rust,Swift,autobuild,build-mode,hardware,dependency caching
references/troubleshooting.md— Comprehensive error diagnosis and resolutionSearch patterns:
no source code,out of disk,out of memory,403,C# compiler,analysis too long,fewer lines,Kotlin,extraction errors,debug logging,SARIF upload,SARIF limits
references/alert-management.md— Alert severity, triage, Copilot Autofix, and dismissalSearch patterns:
severity,security severity,CVSS,Copilot Autofix,dismiss,triage,PR alerts,data flow,merge protection,REST API
Files
- ATTRIBUTION.mdAdded by AutoGineer855 B
- LICENSELicence file added by AutoGineer1.0 KiB
- SKILL.md13.2 KiB
- references/alert-management.md6.3 KiB
- references/cli-commands.md8.1 KiB
- references/compiled-languages.md9.1 KiB
- references/sarif-output.md9.7 KiB
- references/troubleshooting.md8.9 KiB
- references/workflow-configuration.md8.5 KiB
references/cli-commands.md
CodeQL CLI Command Reference
Detailed reference for the CodeQL CLI — installation, database creation, analysis, SARIF upload, and CI integration.
Installation
Download the CodeQL Bundle
Always download the CodeQL bundle (CLI + precompiled queries) from: https://github.com/github/codeql-action/releases
The bundle includes:
CodeQL CLI product
Compatible queries and libraries from
github/codeqlPrecompiled query plans for faster analysis
Platform-Specific Bundles
| Platform | File |
|---|---|
| All platforms | codeql-bundle.tar.zst |
| Linux | codeql-bundle-linux64.tar.zst |
| macOS | codeql-bundle-osx64.tar.zst |
| Windows | codeql-bundle-win64.tar.zst |
.tar.gzvariants are also available for systems without Zstandard support.
Setup
# Extract the bundle
tar xf codeql-bundle-linux64.tar.zst
# Add to PATH
export PATH="$HOME/codeql:$PATH"
# Verify installation
codeql resolve packs
codeql resolve languagescodeql resolve packs should list available query packs for all supported languages. If packs are missing, verify you downloaded the bundle (not standalone CLI).
CI System Setup
Ensure the full CodeQL bundle contents are available on every CI server:
Copy from a central location and extract on each server, or
Use the GitHub REST API to download the bundle dynamically per run
Core Commands
codeql database create
Create a CodeQL database from source code.
# Basic usage (interpreted language)
codeql database create <output-dir> \
--language=<language> \
--source-root=<source-dir>
# Compiled language with build command
codeql database create <output-dir> \
--language=java-kotlin \
--command='./gradlew build' \
--source-root=.
# Multiple languages (cluster mode)
codeql database create <output-dir> \
--db-cluster \
--language=java,python,javascript-typescript \
--command='./build.sh' \
--source-root=.Key flags:
| Flag | Description |
|---|---|
--language=<lang> | Language to extract (required). Use CodeQL language identifiers. |
--source-root=<dir> | Root directory of source code (default: current directory) |
--command=<cmd> | Build command for compiled languages |
--db-cluster | Create databases for multiple languages in one pass |
--overwrite | Overwrite existing database directory |
--threads=<n> | Number of threads for extraction (default: 1; use 0 for all available cores) |
--ram=<mb> | RAM limit in MB for extraction |
codeql database analyze
Run queries against a CodeQL database and produce SARIF output.
codeql database analyze <database-dir> \
<query-suite-or-pack> \
--format=sarif-latest \
--sarif-category=<category> \
--output=<output-file>Key flags:
| Flag | Description |
|---|---|
--format=sarif-latest | Output format (use sarif-latest for current SARIF v2.1.0) |
--sarif-category=<cat> | Category tag for the SARIF results (important for multi-language repos) |
--output=<file> | Output file path for SARIF results |
--threads=<n> | Number of threads for analysis |
--ram=<mb> | RAM limit in MB |
--sarif-add-file-contents | Include source file contents in SARIF output |
--ungroup-results | Disable result grouping (each occurrence reported separately) |
--no-download | Skip downloading query packs (use only locally available packs) |
Common query suites:
| Suite | Description |
|---|---|
<lang>-code-scanning.qls | Standard code scanning queries |
<lang>-security-extended.qls | Extended security queries |
<lang>-security-and-quality.qls | Security + code quality queries |
Examples:
# JavaScript analysis with extended security
codeql database analyze codeql-db/javascript-typescript \
javascript-typescript-security-extended.qls \
--format=sarif-latest \
--sarif-category=javascript \
--output=js-results.sarif
# Java analysis with all available threads
codeql database analyze codeql-db/java-kotlin \
java-kotlin-code-scanning.qls \
--format=sarif-latest \
--sarif-category=java \
--output=java-results.sarif \
--threads=0
# Include file contents in SARIF
codeql database analyze codeql-db \
javascript-typescript-code-scanning.qls \
--format=sarif-latest \
--output=results.sarif \
--sarif-add-file-contentscodeql github upload-results
Upload SARIF results to GitHub code scanning.
codeql github upload-results \
--repository=<owner/repo> \
--ref=<git-ref> \
--commit=<commit-sha> \
--sarif=<sarif-file>Key flags:
| Flag | Description |
|---|---|
--repository=<owner/repo> | Target GitHub repository |
--ref=<ref> | Git ref (e.g., refs/heads/main, refs/pull/42/head) |
--commit=<sha> | Full commit SHA |
--sarif=<file> | Path to SARIF file |
--github-url=<url> | GitHub instance URL (for GHES; defaults to github.com) |
--github-auth-stdin | Read auth token from stdin instead of GITHUB_TOKEN env var |
Authentication: Set GITHUB_TOKEN environment variable with a token that has security-events: write scope, or use --github-auth-stdin.
codeql resolve packs
List available query packs:
codeql resolve packsUse to verify installation and diagnose missing packs. Available since CLI v2.19.0 (earlier versions: use codeql resolve qlpacks).
codeql resolve languages
List supported languages:
codeql resolve languagesShows which language extractors are available in the current installation.
codeql database bundle
Create a relocatable archive of a CodeQL database for sharing or troubleshooting:
codeql database bundle <database-dir> \
--output=<archive-file>Useful for sharing databases with team members or GitHub Support.
CLI Server Mode
codeql execute cli-server
Run a persistent server to avoid repeated JVM initialization when executing multiple commands:
codeql execute cli-server [options]Key flags:
| Flag | Description |
|---|---|
-v, --verbose | Increase progress messages |
-q, --quiet | Decrease progress messages |
--verbosity=<level> | Set verbosity: errors, warnings, progress, progress+, progress++, progress+++ |
--logdir=<dir> | Write detailed logs to directory |
--common-caches=<dir> | Location for persistent cached data (default: ~/.codeql) |
-J=<opt> | Pass option to the JVM |
The server accepts commands via stdin and returns results, keeping the JVM warm between commands. Primarily useful in CI environments running multiple sequential CodeQL commands.
CI Integration Pattern
Complete CI Script Example
#!/bin/bash
set -euo pipefail
REPO="my-org/my-repo"
REF="refs/heads/main"
COMMIT=$(git rev-parse HEAD)
LANGUAGES=("javascript-typescript" "python")
# Create databases for all languages
codeql database create codeql-dbs \
--db-cluster \
--source-root=. \
--language=$(IFS=,; echo "${LANGUAGES[*]}")
# Analyze each language and upload results
for lang in "${LANGUAGES[@]}"; do
echo "Analyzing $lang..."
codeql database analyze "codeql-dbs/$lang" \
"${lang}-security-extended.qls" \
--format=sarif-latest \
--sarif-category="$lang" \
--output="${lang}-results.sarif" \
--threads=0
codeql github upload-results \
--repository="$REPO" \
--ref="$REF" \
--commit="$COMMIT" \
--sarif="${lang}-results.sarif"
echo "$lang analysis uploaded."
doneExternal CI Systems
For CI systems other than GitHub Actions:
Install the CodeQL bundle on CI runners
Run
codeql database createwith appropriate build commandsRun
codeql database analyzeto generate SARIFRun
codeql github upload-resultsto push results to GitHubSet
GITHUB_TOKENwithsecurity-events: writepermission
Environment Variables
| Variable | Purpose |
|---|---|
GITHUB_TOKEN | Authentication for github upload-results |
CODEQL_EXTRACTOR_<LANG>_OPTION_<KEY> | Extractor configuration (e.g., CODEQL_EXTRACTOR_GO_OPTION_EXTRACT_TESTS=true) |
CODEQL_EXTRACTOR_CPP_AUTOINSTALL_DEPENDENCIES | Auto-install C/C++ build dependencies on Ubuntu |
CODEQL_RAM | Override default RAM allocation for analysis |
CODEQL_THREADS | Override default thread count |
Requirements and compatibility
Written for: GitHub Copilot
Works with: Claude Code, Claude apps, OpenAI Codex, GitHub Copilot, Cursor, Gemini CLI, Kiro, OpenCode, Goose, Amp, Roo Code, JetBrains Junie, Factory Droid, Devin (ex-Windsurf), Mistral Vibe, OpenHands, Letta
“Works with” means the tool reads the open Agent Skills format; a skill written for one tool may use features others lack.
Needs: Needs Python
Security
No issues found by our static scan· No issues found
A static scan is not a guarantee. Skills are third-party content: review a skill before you let an agent use it.
Attribution and licence
- First committed by
VeVarunSharma
- Publisher
- GitHub (Official)
- Distributed by
- GitHub
- Source
- github/awesome-copilot · skills/codeql · commit 797337f
- Licence
- MIT License (redistribution allowed)
- LICENSE (added by AutoGineer from LICENSE)
- ATTRIBUTION.md (written by AutoGineer)
- Synced
- Contributors
- VeVarunSharma
AutoGineer is not affiliated with or endorsed by VeVarunSharma or GitHub.
Download ZIP
The ZIP holds the skill’s files, its licence files and an ATTRIBUTION.md. Download codeql.zip