ast-grep

Translate natural-language queries into ast-grep AST pattern rules.

1|Updated Apr 17, 2026
One-click install
npx skills add https://github.com/alexgorbatchev/ai-registry --skill ast-grep-alexgorbatchev
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: ast-grep
Source: https://github.com/alexgorbatchev/ai-registry/tree/main/skills/ast-grep
Command: npx skills add https://github.com/alexgorbatchev/ai-registry --skill ast-grep-alexgorbatchev

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes references (resource) components.

What problem does it solve?

Structural code searches using ast-grep translate descriptive queries into AST-pattern rules, enabling precise matching across languages by syntax rather than text.

Core Features & Use Cases

  • Translate natural language queries into AST patterns to search code structure.
  • Support atomic, relational (inside/has), and composite rules with metavariables for flexible queries.
  • Test and validate rules against sample code and real projects using the ast-grep CLI.

Quick Start

Create a minimal rule (e.g., kind: function_declaration with a has pattern: await $EXPR) and test it with ast-grep scan against a sample file.

Frequently Asked Questions about ast-grep

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

FAQPage Schema
How do I search code by syntax structure instead of plain text?

To search code by structure, you translate natural-language queries into ast-grep rules that match syntax patterns using Tree-sitter ASTs instead of plain text. This enables precise multi-language codebase searches via atomic and relational rules.

What is an AST pattern rule and how do metavariables work?

An AST pattern rule defines structural code matches using syntax trees, while metavariables act as wildcards capturing specific code expressions. This Skill generates atomic, relational, and composite rules with metavariables for flexible structural searches.

Can I find code patterns based on relational context like inside or precedes?

Yes, ast-grep supports relational rules for inside, has, precedes, and follows scenarios. This Skill translates natural-language queries into composite rules that match code structures based on their hierarchical or sequential relationships.

How do I create and test an ast-grep rule from a natural language query?

You describe what you want to find in natural language, and the Skill generates an ast-grep rule using atomic or relational patterns. You then test the constructed rule against sample code using the ast-grep CLI scan command.

Does structural code search work across multiple programming languages?

Structural code search works across multiple languages supported by Tree-sitter. This Skill generates language-agnostic AST rules with metavariables that can be tested via inline rules or rule files using the ast-grep CLI.

Why use AST pattern matching instead of regular expressions for code search?

AST pattern matching identifies code by syntax structure and hierarchical relationships, avoiding false positives from text matching. This Skill generates ast-grep rules with metavariables to precisely target structural patterns across Tree-sitter-supported languages.