ast-grep

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

256|5|Updated Jan 24, 2022
One-click install
npx skills add https://github.com/ryoppippi/dotfiles --skill ast-grep-ryoppippi
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: ast-grep
Source: https://github.com/ryoppippi/dotfiles/tree/main/claude/skills/ast-grep
Command: npx skills add https://github.com/ryoppippi/dotfiles --skill ast-grep-ryoppippi

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes references (resource) components.

What problem does it solve?

This Skill helps translate natural language queries into ast-grep rules for structural code search. It enables searching code by its structure rather than text, allowing precise matches across large codebases.

Core Features & Use Cases

  • AST-based search: Find code patterns by structure, not just textual matches.
  • Rule creation & testing: Write, test, and refine ast-grep rules to match complex constructs.
  • Cross-language queries: Apply rules across languages supported by the AST parser.

Quick Start

Use the ast-grep skill to craft a rule that matches a specific code structure, then test it against a sample file to verify matches.

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 structure instead of just text patterns?

AST-based search finds code by its syntactic structure rather than literal text matches. This allows precise pattern matching across large codebases—for example, locating all async functions without error handling or identifying specific language constructs where grep or text search would miss context-dependent variations.

How do I write AST search rules for code patterns?

Translate natural language descriptions of code patterns into ast-grep rules using atomic operators (pattern, kind, regex), relational operators (inside, has, precedes, follows), and composite logic (all, any, not). Test rules against sample files to verify matches before applying them across your codebase.

Can I apply the same structural search rule across multiple programming languages?

Yes. AST-based rules work cross-language because they match code structure, not syntax. A single rule can find equivalent patterns in JavaScript, Python, Go, and other supported languages, provided each language's AST parser is available.

What's the difference between text search and structural code search?

Text search matches character sequences and is vulnerable to whitespace, formatting, and naming variations. Structural search matches code by its AST shape, capturing semantically equivalent patterns regardless of how they're written, making it far more reliable for finding specific constructs.

Do I need prior knowledge of AST syntax to create rules?

No. This Skill translates natural language descriptions into ast-grep rule syntax. You describe what code pattern you're looking for in plain terms, and the rules are generated with support for pattern matching, conditionals, and relationships—no prior AST knowledge required.

What code patterns can ast-grep rules detect?

AST rules detect patterns ranging from simple (specific function calls) to complex (functions meeting multiple structural conditions—for instance, async functions inside class methods with no try-catch blocks). Rules support negation, precedence, nesting, and composite logic to express precise structural requirements.