ast-grep

Perform AST-aware code search and structural refactoring across 25 programming languages.

2|1|Updated Sep 16, 2024
One-click install
npx skills add https://github.com/mvandermeulen/nvim --skill ast-grep-mvandermeulen
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: ast-grep
Source: https://github.com/mvandermeulen/nvim/tree/main/.claude/skills/ast-grep
Command: npx skills add https://github.com/mvandermeulen/nvim --skill ast-grep-mvandermeulen

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes scripts (resource) and references (resource) components.

What problem does it solve?

This skill solves the limitation of traditional text-based search tools like grep or ripgrep when dealing with complex code structures, allowing you to perform precise, syntax-aware searches and rewrites across 25 programming languages.

Core Features & Use Cases

  • Structural Matching: Find code based on its shape (e.g., function calls, class definitions, or import statements) rather than just text bytes.
  • Deterministic Codemods: Safely rewrite code patterns across an entire repository, such as migrating require calls to imports or renaming function parameters.
  • Offline Validation: Catch regex-misuse errors and language-specific syntax traps before executing any changes.

Quick Start

Use the ast-grep skill to search for all console.log calls in the current typescript project.

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 patterns based on syntax structure instead of plain text?

AST-aware code search matches code based on its structural shape, such as function calls or class definitions, rather than raw text bytes. This syntax-aware approach targets complex code patterns across 25 programming languages precisely.

What is the best way to safely rewrite function parameters across an entire repository?

Deterministic codemods perform structural refactoring to safely rewrite code patterns across a repository, such as migrating require calls to imports or renaming function parameters. Offline pattern validation ensures structural integrity during mutations.

Why does my regex code search fail to match specific import statements?

Traditional text-based search tools like grep or ripgrep have limitations with complex code structures. AST-aware search overcomes this by matching the structural shape of import statements rather than just text bytes.

Do I need to install a specific binary to run ast-grep for structural code search?

Yes, performing AST-aware code search and structural refactoring requires a valid ast-grep binary installed in your environment. The skill uses this binary to analyze code structures and provide offline pattern validation.

Can I use structural refactoring and codemods across multiple programming languages?

Yes, AST-aware code search and structural refactoring support 25 programming languages. You can target complex code patterns and execute deterministic codemods across multiple language syntaxes within your repository.

How do I catch syntax traps before executing large-scale code mutations?

Offline pattern validation catches regex-misuse errors and language-specific syntax traps before executing any changes. This ensures structural integrity and prevents invalid code mutations during refactoring.