tree-sitter-queries

Write and optimize tree-sitter queries in S-expression syntax for syntax trees.

1|Updated Mar 15, 2026
One-click install
npx skills add https://github.com/hafley66/claude-research --skill tree-sitter-queries
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: tree-sitter-queries
Source: https://github.com/hafley66/claude-research/tree/main/skills/tree-sitter-queries
Command: npx skills add https://github.com/hafley66/claude-research --skill tree-sitter-queries

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

Writing and maintaining tree-sitter queries for syntax highlighting, code analysis, and editor tooling can be complex and error-prone, requiring precise pattern matching of language syntax trees.

Core Features & Use Cases

  • Write tree-sitter queries using S-expression syntax to match language nodes.
  • Use captures, predicates, quantifiers, anchors, and field names to extract and constrain matches.
  • Build queries for syntax highlighting, code analysis, and editor features across multiple languages.
  • Understand the difference between tree-sitter queries and ast-grep patterns to choose the right approach.

Quick Start

Write a simple tree-sitter query to capture function names from a source file.

Frequently Asked Questions about tree-sitter-queries

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I write tree-sitter queries for syntax highlighting?

To write tree-sitter queries for syntax highlighting, use S-expression syntax in .scm files to pattern-match language syntax trees. Apply captures, predicates, and field names to extract and constrain matches for editor integration and code analysis.

What is the difference between tree-sitter queries and ast-grep patterns?

Tree-sitter queries use S-expression syntax with captures and predicates to match syntax trees, while ast-grep patterns offer a different structural approach. Understanding this distinction helps you choose the right method for syntax highlighting and code analysis.

How do I use predicates and quantifiers in tree-sitter query files?

Use predicates and quantifiers in tree-sitter query files by applying S-expression syntax to constrain matches within language syntax trees. You can combine them with captures, anchors, alternations, and wildcards to extract precise nodes for editor tooling.

Can I apply tree-sitter queries across multiple programming languages?

Yes, you can apply tree-sitter queries across multiple programming languages. By writing S-expression patterns in .scm files, you can build queries for syntax highlighting, code analysis, and editor features for any language supported by tree-sitter.

Why are my tree-sitter queries not matching the correct syntax tree nodes?

Tree-sitter queries may fail to match correct syntax tree nodes if S-expression patterns lack proper captures, field names, or anchors. Verify that your quantifiers, predicates, and wildcards in .scm files accurately reflect the target language syntax structure.