ast-grep

Translate natural language queries into AST-based rules for structural code search.

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

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

Translate natural language queries into AST-based rules to perform structural code search across codebases, enabling precise matching of code patterns beyond text search.

Core Features & Use Cases

  • AST-based pattern construction: convert natural language queries into AST patterns to match code structure.
  • Rule testing and debugging: test rules with example snippets and the CLI's debug features to refine queries.
  • Flexible search workflow: perform simple pattern searches, complex relational queries, and multi-step transforms with composed rules.

Quick Start

Install ast-grep and run a simple inline rule to locate a function matching a pattern in your codebase.

Frequently Asked Questions about ast-grep

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

FAQPage Schema
How do I find code patterns structurally when text search isn't enough?

Structural code search finds code patterns by translating natural language queries into AST-based rules, matching functions, calls, and control-flow structures even when text matches are insufficient.

Can I use AST-based rules to search across multiple programming languages?

Yes, AST-based structural code search is language-agnostic. It applies to diverse codebases, enabling you to locate matching code patterns across different programming languages using consistent rule definitions.

What's the best way to translate natural language queries into AST code search rules?

You can translate natural language queries into AST patterns by constructing atomic, relational, or composite rules. Use inline rules for simple searches and rule files for complex, multi-step structural transforms.

How do I test and debug AST rules against example code snippets?

Test and debug AST rules by running example snippets through the CLI's debug features. This iterative refinement process helps you verify pattern matches on functions and control-flow structures before applying rules broadly.

What is the difference between AST-based structural search and standard regex code search?

AST-based structural search matches code syntax trees rather than raw text, meaning it understands functions, calls, and control-flow structures. This allows precise structural pattern matching that standard text or regex search cannot achieve.

When should I avoid using AST rules for code pattern matching?

AST-based structural search may be unnecessary for simple string or variable name lookups where standard text matching suffices. It is best suited for complex structural relationships, composite transforms, and pattern matching across diverse codebases.