ast-grep

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

1|1|Updated Dec 3, 2020
One-click install
npx skills add https://github.com/kaofelix/dotfiles --skill ast-grep-kaofelix
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: ast-grep
Source: https://github.com/kaofelix/dotfiles/tree/main/pi/.pi/agent/skills/ast-grep-skill/ast-grep/skills/ast-grep
Command: npx skills add https://github.com/kaofelix/dotfiles --skill ast-grep-kaofelix

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes references (resource) components.

What problem does it solve?

Ast-grep translates natural-language queries into AST-based rules, enabling structural code search that understands code syntax rather than relying on plain text.

Core Features & Use Cases

  • Rule generation: Convert natural-language requirements into AST grammar-based search rules.
  • Multi-language support: Apply searches across languages supported by Tree-sitter to locate constructs like async functions, class methods, or specific patterns.
  • Use Case: Quickly identify all occurrences of a particular AST pattern (e.g., function_declaration with an await expression) across a codebase.

Quick Start

Install the ast-grep CLI, write a YAML rule describing the target AST pattern, and run a search against your project to see matches. For example, create a rule that finds all function_declaration nodes containing await expressions and run ast-grep scan --rule your_rule.yml /path/to/project.

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 specific code patterns across a multi-language codebase without relying on plain text?

AST-based code search translates natural language queries into YAML rules that match syntax patterns structurally. It uses Tree-sitter grammars to locate specific constructs like async functions across multi-language codebases, avoiding the limitations of plain text search.

What is structural code search and when do I need it instead of regular text search?

Structural code search uses Abstract Syntax Trees to understand code syntax rather than treating files as plain text. You need it when locating complex constructs like function declarations containing await expressions, where formatting variations would break regular text matching.

How do I write a YAML rule to find async functions with await expressions using Tree-sitter?

Install the ast-grep CLI and create a YAML rule describing a function_declaration node containing an await expression. Run the command ast-grep scan --rule your_rule.yml /path/to/project to execute the structural search and see matches.

Does AST-based code search work with programming languages beyond JavaScript and TypeScript?

AST-based code search supports multi-language codebases through Tree-sitter integration. You can apply structural search rules to any compatible programming language to locate specific syntax constructs like class methods or function declarations across your project.

What's the best way to find all occurrences of a specific AST pattern like class methods in my project?

The best way to find specific AST patterns is using the ast-grep CLI to run a YAML rule scan against your project directory. This structural search method locates exact syntax constructs like class methods regardless of code formatting or text variations.

Do I need a specific runtime environment to run AST-based structural search rules?

Running AST-based structural search rules requires the ast-grep CLI and a compatible runtime environment. You need these dependencies installed locally to write, test, and execute YAML rules against your source code for pattern matching.