ast-grep

Search, analyze, and refactor code using AST patterns with YAML rules.

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

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes references (resource) components.

What problem does it solve?

ast-grep provides a robust mechanism to locate, analyze, and transform code based on structural patterns, avoiding brittle regex searches and enabling safer refactors.

Core Features & Use Cases

  • Structural Search: Find code by structure (e.g., function calls with specific arguments) independent of whitespace.
  • Refactoring & Linting: Rename variables, change function signatures, and enforce custom rules with precise AST-based rules.
  • Code Analysis: Extract targeted information from large codebases to support audits and modernization.

Quick Start

Ask your AI to perform a structural search or targeted rewrite across your codebase using ast-grep.

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 code by structure instead of using brittle regex?

Structural code search uses AST pattern-matching to locate code by its syntax tree, ignoring whitespace. This allows you to find function calls with specific arguments precisely across multi-language codebases without relying on fragile regular expressions.

Can I enforce custom linting rules across a multi-language codebase?

Yes, you can enforce custom linting rules across a multi-language codebase using YAML rule configuration. AST-based analysis validates code structure and applies precise linting rules to ensure codebase consistency.

What is the best way to automate safe refactoring like renaming variables or changing function signatures?

Automated AST-based refactoring safely renames variables and changes function signatures by matching structural patterns. This approach modifies code based on syntax trees, ensuring transformations preserve code logic and avoid breaking changes.

How do I configure structural search and refactoring rules?

You configure structural search and refactoring rules using YAML. This configuration drives the AST pattern-matching engine to perform structural searches, apply transformations, and execute targeted rewrites across your codebase.

Does tree-sitter based code search work for large scale codebase modernization?

Tree-sitter based code search supports large scale codebase modernization by extracting targeted information and performing structural analysis. It applies AST patterns to support audits and modernization across multi-language environments efficiently.