ast-grep-patterns

Create and validate ast-grep patterns for tree-sitter parsed code structures.

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

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

Ast-grep pattern syntax enables precise matching of code structures by using metavariables, multi-node patterns, and pattern objects. It helps debug pattern parsing issues and choose appropriate strictness levels for accurate results.

Core Features & Use Cases

  • Metavariable syntax for single-node and multi-node captures
  • Pattern object syntax to handle ambiguous or incomplete code fragments
  • Debugging support via playground and --debug-query
  • Control over strictness levels and contextual patterns for precise matches

Quick Start

Create a pattern that matches a function call with a single metavariable argument and test it in the playground.

Frequently Asked Questions about ast-grep-patterns

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

FAQPage Schema
How do I use metavariables in ast-grep to match code structures?

Metavariables in ast-grep capture single-node and multi-node code structures for dynamic pattern matching. You author patterns using metavariable syntax to represent variables, enabling reliable structural searches across tree-sitter parsed codebases.

What's the best way to debug ast-grep pattern parsing issues?

Debug ast-grep pattern parsing issues using the playground or the --debug-query command. These tools help validate pattern syntax, inspect tree-sitter parsing behavior, and identify why a structural code search fails to match.

How do I match ambiguous or incomplete code fragments with ast-grep?

Match ambiguous code fragments with ast-grep using pattern object syntax and selector/context patterns. These features handle incomplete tree-sitter structures by specifying contextual constraints, ensuring precise multi-node matching.

When should I adjust strictness levels in ast-grep pattern matching?

Adjust ast-grep strictness levels to control pattern matching precision against tree-sitter code structures. Higher strictness enforces exact structural matches, while lower strictness allows flexible metavariable captures for broader code search results.

Does ast-grep work with tree-sitter for structural code search?

Ast-grep works with tree-sitter to perform structural code search and pattern matching. It parses codebases using tree-sitter grammars, enabling metavariable captures and contextual pattern validation across supported programming languages.

Why does my ast-grep pattern fail to match a multi-node code structure?

Ast-grep pattern matching fails due to incorrect metavariable syntax, inappropriate strictness levels, or ambiguous fragments. Validate pattern objects and context patterns using the playground to ensure multi-node tree-sitter structures align.