ast-grep

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

1|Updated Nov 1, 2025
One-click install
npx skills add https://github.com/rselbach/dotfiles --skill ast-grep-rselbach
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: ast-grep
Source: https://github.com/rselbach/dotfiles/tree/main/agents/skills/ast-grep
Command: npx skills add https://github.com/rselbach/dotfiles --skill ast-grep-rselbach

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes references (resource) components.

What problem does it solve?

ast-grep enables translating natural language queries into AST-based rules to search code by structure rather than text, enabling precise queries across large codebases.

Core Features & Use Cases

  • Translate natural language queries into ast-grep rules to define structural searches.
  • Write rules that match code constructs (functions, classes, calls) by syntax rather than text.
  • Test and refine rules against small sample files before applying to real codebases.

Quick Start

Create a basic ast-grep rule for a sample snippet and verify it against a small test 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 instead of text across a large codebase?

You can search code by structure using AST-based rules to match syntax constructs like functions and classes. This allows precise structural queries across large codebases rather than relying on simple text matching.

How do I write an ast-grep rule to match specific function shapes or class structures?

You can write ast-grep rules using YAML definitions to match specific code constructs by syntax. Create atomic, relational, or composite rules to target function shapes, class structures, or specific AST characteristics.

What is AST-based code search and when do I need it for static analysis?

AST-based code search queries code by its abstract syntax tree structure rather than text. You need it for static analysis when locating specific syntax patterns, function shapes, or class structures across multi-language codebases.

Can I use ast-grep rules for structural code search across different programming languages?

Yes, ast-grep supports language-agnostic structural code search. You can define YAML-based rules to apply AST searches across multi-language codebases, matching syntax constructs regardless of the specific programming language.

How do I test and refine AST search rules before applying them to a real codebase?

You can test and refine AST search rules against small sample files before applying them to real codebases. The process provides steps for building, testing, and debugging rules to ensure they match the intended syntax patterns.

How do I translate a natural language code query into a structural search rule?

You can translate natural language code queries into AST-based rules for structural code search. This allows you to turn descriptive code queries into precise syntax-matching rules for locating patterns in your codebase.