ast-grep

Translate natural language queries into ast-grep rules for structural code search.

Updated Feb 22, 2026
One-click install
npx skills add https://github.com/fantomc0der/opencode-session-export --skill ast-grep-fantomc0der
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: ast-grep
Source: https://github.com/fantomc0der/opencode-session-export/tree/main/.opencode/skills/ast-grep
Command: npx skills add https://github.com/fantomc0der/opencode-session-export --skill ast-grep-fantomc0der

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes references (resource) components.

What problem does it solve?

Translates natural language queries into ast-grep rules to enable precise, structure-based code searches across codebases.

Core Features & Use Cases

  • Translate NL queries into AST-based search rules that match structure rather than text.
  • Provide a step-by-step workflow: understand the query, create example code, write the rule, test, and search the target codebase.
  • Support complex patterns using relational rules (inside, has) and metavariables for flexible matching.

Quick Start

Describe the code pattern you want to find, and I will generate an ast-grep rule and a small test snippet to validate it.

Frequently Asked Questions about ast-grep

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

FAQPage Schema
How do I search for code patterns by structure instead of exact text?

To search code by structure, ast-grep translates natural language queries into AST rules that match code patterns rather than exact text. This allows you to find function calls, variable assignments, or specific syntax trees across large codebases.

Can I use tree-sitter languages for structural code search?

Tree-sitter languages are fully supported for structural code search. The generated ast-grep rules apply to any language supported by Tree-sitter, enabling you to query language constructs and complex structural patterns across your codebase.

What is the best way to find complex nested code patterns in a large codebase?

The best way to find complex nested patterns is using relational rules and metavariables. ast-grep generates rules with relational operators like `inside` and `has` to match flexible, deeply nested code structures across large codebases.

How do I generate and test an ast-grep rule from a natural language description?

To generate and test an ast-grep rule, describe the code pattern you want to find. The workflow then creates a small test snippet, writes the rule, and validates it before you search the target codebase using the ast-grep CLI.

Do I need a test code snippet to create an AST-based code search rule?

Yes, a test code snippet is required to create AST-based code search rules. The rule generation workflow needs a clear language target, a test snippet, and your natural language query to produce and validate executable ast-grep rules.

Why use AST structural search over regular expression text matching?

AST structural search is used over regex because it understands code syntax and language constructs. ast-grep rules match the actual structure of the code, ignoring formatting variations, comments, or whitespace that would break regular expression patterns.