CodeQL documentation

database create


codeql database create [--language=<lang>[,<lang>...]] [--github-auth-stdin] [--github-url=<url>] [--source-root=<dir>] [--threads=<num>] [--ram=<MB>] [--command=<command>] [--mode=<mode>] <options>... [--] <database>


Create a CodeQL database for a source tree that can be analyzed using one of the CodeQL products.



[Mandatory] Path to the CodeQL database to create. This directory will be created, and must not already exist (but its parent must).

If the --db-cluster option is given, this will not be a database itself, but a directory that will contain databases for several languages built from the same source root.

It is important that this directory is not in a location that the build process will interfere with. For instance, the target directory of a Maven project would not be a suitable choice.


[Advanced] If the database already exists, delete it and proceed with this command instead of failing. This option should be used with caution as it may recursively delete the entire database directory.


[Advanced] Read a Code Scanning configuration file specifying options on how to create the CodeQL databases and what queries to run in later steps. For more details on the format of this configuration file, refer to To run queries from this file in a later step, invoke codeql database analyze without any other queries specified.


Instead of creating a single database, create a “cluster” of databases for different languages, each of which is a subdirectory of the directory given on the command line.

-l, --language=<lang>[,<lang>...]

The language that the new database will be used to analyze.

Use codeql resolve languages to get a list of the pluggable language extractors found on the search path.

When the --db-cluster option is given, this can appear multiple times, or the value can be a comma-separated list of languages.

If this option is omitted, and the source root being analysed is a checkout of a GitHub repository, the CodeQL CLI will make a call to the GitHub API to attempt to automatically determine what languages to analyse. Note that to be able to do this, a GitHub PAT token must be supplied either in the environment variable GITHUB_TOKEN or via standard input using the --github-auth-stdin option.

-s, --source-root=<dir>

[Default: .] The root source code directory. In many cases, this will be the checkout root. Files within it are considered to be the primary source files for this database. In some output formats, files will be referred to by their relative path from this directory.

-j, --threads=<num>

Use this many threads for the import operation, and pass it as a hint to any invoked build commands.

Defaults to 1. You can pass 0 to use one thread per core on the machine, or -N to leave N cores unused (except still use at least one thread).

-M, --ram=<MB>

Use this much memory for the import operation, and pass it as a hint to any invoked build commands.

-c, --command=<command>

For compiled languages, build commands that will cause the compiler to be invoked on the source code to analyze. These commands will be executed under an instrumentation environment that allows analysis of generated code and (in some cases) standard libraries.

If no build command is specified, the command attempts to figure out automatically how to build the source tree, based on heuristics from the selected language pack.

Beware that some combinations of multiple languages require an explicit build command to be specified.


[Advanced] Suppress all database cleanup after finalization. Useful for debugging purposes.


[Advanced] Skip any pre-finalize script specified by the active CodeQL extractor.

Extractor selection options


A list of directories under which extractor packs may be found. The directories can either be the extractor packs themselves or directories that contain extractors as immediate subdirectories.

If the path contains multiple directory trees, their order defines precedence between them: if the target language is matched in more than one of the directory trees, the one given first wins.

The extractors bundled with the CodeQL toolchain itself will always be found, but if you need to use separately distributed extractors you need to give this option (or, better yet, set up --search-path in a per-user configuration file).

(Note: On Windows the path separator is ;).

Options to configure how to call the GitHub API to auto-detect languages.

-a, --github-auth-stdin

Accept a GitHub Apps token or personal access token via standard input.

This overrides the GITHUB_TOKEN environment variable.

-g, --github-url=<url>

URL of the GitHub instance to use. If omitted, the CLI will attempt to autodetect this from the checkout path and if this is not possible default to

Low-level dataset cleanup options


Set the maximum amount of space that the disk cache for intermediate query results can use.

If this size is not configured explicitly, the evaluator will try to use a “reasonable” amount of cache space, based on the size of the dataset and the complexity of the queries. Explicitly setting a higher limit than this default usage will enable additional caching which can speed up later queries.


[Advanced] Set target amount of free space on file system.

If --max-disk-cache is not given, the evaluator will try hard to curtail disk cache usage if the free space on the file system drops below this value.


[Advanced] Set target fraction of free space on file system.

If --max-disk-cache is not given, the evaluator will try hard to curtail disk cache usage if the free space on the file system drops below this percentage.

-m, --mode=<mode>

Select how aggressively to trim the cache. Choices include:

brutal: Remove the entire cache, trimming down to the state of a freshly extracted dataset

normal (default): Trim everything except explicitly “cached” predicates.

light: Simply make sure the defined size limits for the disk cache are observed, deleting as many intermediates as necessary.


Delete any backup directories resulting from database upgrades.

Tracing options


[Advanced] Do not trace the specified command, instead rely on it to produce all necessary data directly.


[Advanced] The path to a compiler specification file. It may be used to pick out compiler processes that run as part of the build command, and trigger the execution of other tools. The extractors will provide default compiler specifications that should work in most situations.

Build command customization options


[Advanced] The directory in which the specified command should be executed. If this argument is not provided, the command is executed in the value of --source-root passed to codeql database create, if one exists. If no --source-root argument is provided, the command is executed in the current working directory.


[Advanced] Only run the specified build command(s) if a database under construction uses an extractor that depends on tracing a build process. If this option is not given, the command will be executed even when CodeQL doesn’t need it, on the assumption that you need its side effects for other reasons.

Common options

-h, --help

Show this help text.


[Advanced] Give option to the JVM running the command.

(Beware that options containing spaces will not be handled correctly.)

-v, --verbose

Incrementally increase the number of progress messages printed.

-q, --quiet

Incrementally decrease the number of progress messages printed.


[Advanced] Explicitly set the verbosity level to one of errors, warnings, progress, progress+, progress++, progress+++. Overrides -v and -q.


[Advanced] Write detailed logs to one or more files in the given directory, with generated names that include timestamps and the name of the running subcommand.

(To write a log file with a name you have full control over, instead give --log-to-stderr and redirect stderr as desired.)

  • © GitHub, Inc.
  • Terms
  • Privacy