Skip to main content

This version of GitHub Enterprise Server will be discontinued on 2024-06-29. No patch releases will be made, even for critical security issues. For better performance, improved security, and new features, upgrade to the latest version of GitHub Enterprise Server. For help with the upgrade, contact GitHub Enterprise support.

Creating a custom query

You can work from a template to write your own code to create a custom query to analyze a specific language.

About custom queries

Note: Creating a custom query is optional, and the github/codeql repository contains a large number of example queries you can use instead.

You create a new query file from a template for a given language, which imports the standard libraries for analyzing that language. For more information, see "About CodeQL queries" in the CodeQL documentation.

Creating a custom query

  1. In the extension sidebar, open the "Queries" view, then click the Create query icon.

  2. In the VS Code Command Palette, select the target language for your query. If you've chosen not to create your custom query in an existing directory, selecting a language will autogenerate a directory labeled codeql-custom-queries-LANGUAGE, where LANGUAGE is the name of the selected language. A query template labeled example.ql will then be added to the existing or autogenerated directory.

  3. In the template, write your custom query, then save the file. Once your query is finished, you can run it from the "Queries" view.

Further reading

You can read about how to create queries for supported languages in the CodeQL documentation: