Lowering the barrier to entry for CodeQL development through natural language and GitHub Copilot
A GitHub repository template for building custom CodeQL queries with AI assistance. This template provides a structured environment with prompts, instructions, and workflows designed to guide GitHub Copilot Coding Agent through the complete CodeQL development lifecycle.
This repository template enables developers to create custom CodeQL security queries with minimal CodeQL expertise by leveraging:
- GitHub Copilot Coding Agent for automated query development
- Hierarchical prompt system that guides AI through CodeQL tasks
- Test-driven development methodology for reliable query creation
- Pre-configured workflows for setup, testing, and validation
Before using this repository template, ensure your GitHub organization/account has:
- GitHub Actions enabled for running CI/CD workflows
- GitHub Copilot Coding Agent access for AI-assisted development
- GitHub Advanced Security (optional, but recommended)
- Click the "Use this template" button at the top of this repository
- Choose "Create a new repository"
- Select your GitHub organization or personal account
- Enter a repository name (e.g.,
my-codeql-queries) - Set the repository visibility (internal, private, or public)
- Click "Create repository"
Note: The 'copilot-setup-steps' actions workflow will automatically set up the environment for Copilot Coding Agent (CCA), so local installation is optional and primarily useful for manual development.
- Navigate to Issues in your new repository
- Click "New Issue"
- Select "Request new CodeQL Query" template
- Fill in the details:
- Choose target language (e.g., Java, Python, JavaScript)
- Describe what the query should detect
- Provide code examples (optional but recommended)
- Specify severity level
- Submit the issue
- Assign the issue to
@copilot(GitHub's Copilot Coding Agent user) - Wait for Copilot to process the issue and create a Pull Request
- Monitor progress via the
Sessionsand/or comments for the new Pull Request
- Navigate to the generated Pull Request
- Review the changes:
- Query implementation (
.qlfiles) - Test cases (in
test/directories) - Query documentation (
.mdand.qhelpfiles)
- Query implementation (
- Check CI/CD results:
- All tests pass
- Query compiles successfully
- Linting and formatting checks pass
- Review and approve the PR
- Merge to incorporate the query into your repository
| Template | Purpose |
|---|---|
| Request new CodeQL Query | Create a new CodeQL query to detect specific code patterns or vulnerabilities |
| Update existing CodeQL Query | Modify an existing query to improve accuracy or add new detection capabilities |
| Improve Prompts/Instructions | Contribute improvements to the AI guidance system |
After creating your first query, your repository will contain:
codeql-development-template/
βββ .github/
β βββ instructions/ # Level 2: Language-specific Copilot instructions
β βββ prompts/ # Level 3: High-level prompt templates
β βββ ISSUE_TEMPLATE/ # Level 1: Entry points for Copilot workflows
β βββ workflows/ # CI/CD automation for testing and setup
βββ languages/
β βββ {language}/ # Per-language development environments
β βββ custom/ # Your custom queries (generated by Copilot)
β β βββ src/ # Query source files (.ql)
β β βββ test/ # Query test cases
β βββ example/ # Example queries for reference
β βββ tools/ # Development resources and AST exploration
β βββ dev/ # Language-specific development guides
β βββ src/ # PrintAST queries for exploring code structure
β βββ test/ # PrintAST test suites
βββ resources/cli/ # CLI command reference documentation
β βββ codeql/ # CodeQL CLI subcommand guides
β βββ qlt/ # QLT CLI subcommand guides
βββ scripts/ # Setup and automation scripts
This template implements a hierarchical prompt system that maximizes GitHub Copilot's effectiveness:
- Issue Templates provide structured input for query requirements
- Language-Specific Instructions guide Copilot with relevant context
- High-Level Prompts break down complex CodeQL workflows
- Tool-Specific Resources provide CLI usage examples and patterns
- Test-Driven Development ensures query accuracy through automated testing
The Copilot Coding Agent uses this hierarchy to:
- Understand your query requirements
- Generate appropriate CodeQL logic
- Create comprehensive test cases
- Validate query correctness
- Document the query properly
See PROMPTS.md for details on the prompt hierarchy system.
The template supports CodeQL query development for:
| Language | CodeQL Library |
|---|---|
| GitHub Actions | actions |
| C/C++ | cpp |
| C# | csharp |
| Go | go |
| Java | java |
| JavaScript/TypeScript | javascript |
| Python | python |
| Ruby | ruby |
This repository template is available under the MIT License.
This repository template is maintained by the CODEOWNERS.
This repository template comes with no expectation or guarantee of support, with more details in the SUPPORT.md document.