ast-grep

Match and rewrite code using AST patterns across multiple languages.

9|2|Updated Nov 27, 2008
One-click install
npx skills add https://github.com/adragomir/dotfiles --skill ast-grep-adragomir
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: ast-grep
Source: https://github.com/adragomir/dotfiles/tree/main/.config/pi/agent/skills/ast-grep
Command: npx skills add https://github.com/adragomir/dotfiles --skill ast-grep-adragomir

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

Structural code search and rewriting using AST matching using patterns instead of regex.

Core Features & Use Cases

  • Pattern-based search across multiple languages to locate function calls, patterns, and refactoring opportunities that regex cannot reliably match.
  • Safe, configurable refactoring with dry-run previews and project-wide rewrites driven by AST patterns.
  • Advanced scans with inline rules to enforce coding standards and complex refactoring goals across codebases.

Quick Start

Describe the target codebase and an AST pattern to search, then run a safe AST-based refactor across the project.

Frequently Asked Questions about ast-grep

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I refactor code safely across multiple files without breaking function calls?

AST pattern matching refactors code safely by locating function calls and rewriting opportunities across multiple files using structural syntax instead of regex. It supports dry-run previews for incremental changes.

Why does regex fail to match code patterns for refactoring?

Regex fails to match code patterns for refactoring because it treats source code as plain text, missing syntax structure. AST pattern matching parses code structurally to reliably locate function calls and refactoring opportunities across languages.

Can I use AST patterns to search across JavaScript, TypeScript, and Python?

Yes, AST pattern matching works across JavaScript, TypeScript, Python, and Go to find function calls and refactoring opportunities, applying structural search syntax that regex cannot reliably match across these languages.

What is the best way to enforce coding standards across a codebase?

The best way to enforce coding standards is running advanced scans with inline rules that apply AST pattern matching across a codebase, identifying structural violations and refactoring goals that text-based search cannot detect.

How do I preview project-wide code rewrites before applying changes?

You can preview project-wide code rewrites by running safe, configurable AST pattern scans with dry-run previews, allowing you to verify structural changes across multiple files before applying any modifications.

Does AST pattern matching work for static analysis to find code patterns?

Yes, AST pattern matching performs static analysis by defining pattern syntax to scan codebases for structural patterns, enabling you to find function calls and enforce standards across supported programming languages.