ast-grep

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

3|1|Updated Jun 20, 2016
One-click install
npx skills add https://github.com/paulchiu/dotfiles --skill ast-grep-paulchiu
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: ast-grep
Source: https://github.com/paulchiu/dotfiles/tree/main/.config/opencode/skills/ast-grep
Command: npx skills add https://github.com/paulchiu/dotfiles --skill ast-grep-paulchiu

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes references (resource) components.

What problem does it solve?

Translate natural language code queries into ast-grep rules to perform structural code searches.

Core Features & Use Cases

  • Translate user queries into AST-based rules to search code by structure rather than text.
  • Support iterative workflow: understand query, draft example code, write rule, test, and apply to codebase.
  • Enable complex relational queries with tested results across languages.

Quick Start

Create a simple rule to find async functions that use await and test it 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 structure rather than text?

Structural code search uses AST-based rules to find patterns by syntax structure, ignoring irrelevant text variations. This approach translates natural language queries into ast-grep rules, enabling precise pattern discovery across large codebases.

What is the best way to write ast-grep rules for complex code patterns?

Writing ast-grep rules involves an iterative workflow: understand the natural language query, draft example code, write the AST rule, test it against the sample, and then apply it to the codebase for precise pattern discovery.

Can I perform static code analysis across multiple programming languages?

Yes, you can perform static code analysis across multiple languages by generating tree-sitter based AST rules. These structure-aware rules support complex relational queries with tested results across different programming languages.

How do I find async functions that use await in a large codebase?

To find async functions that use await, create a structural search rule defining the async function pattern and the await expression. Testing this rule against a sample file verifies the AST pattern before applying it to the entire codebase.

Does tree-sitter support iterative testing for structure-aware code search rules?

Yes, tree-sitter supports iterative testing for structure-aware code search rules. The workflow involves drafting example code, writing the AST rule, testing it against the sample, and then applying the validated rule to the broader codebase.