ast-grep

Find and rewrite code using Abstract Syntax Tree patterns.

Updated Mar 20, 2026
One-click install
npx skills add https://github.com/dljsjr/sandpiper-ai --skill ast-grep-dljsjr
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: ast-grep
Source: https://github.com/dljsjr/sandpiper-ai/tree/main/skills/sandpiper/ast-grep
Command: npx skills add https://github.com/dljsjr/sandpiper-ai --skill ast-grep-dljsjr

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes references (resource) components.

What problem does it solve?

Automates and accelerates code understanding and modification by enabling structural code search, linting, and codemods using AST patterns instead of brittle text matching.

Core Features & Use Cases

  • AST-based search across languages to find code by structure (e.g., function calls, imports, or patterns inside loops or classes).
  • Linting and guidance by AST rules to enforce coding standards and safe refactors.
  • Codemod-like rewrites that transform code while preserving semantics, enabling large-scale refactors with confidence.
  • Real-world usage: audit a codebase to rename a symbol across files without breaking references.

Quick Start

Start with a simple search by pattern using ast-grep run and specify the language to see precise structural matches.

Frequently Asked Questions about ast-grep

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

FAQPage Schema
How do I search and refactor code by AST patterns instead of text matching?

AST-based code search finds and rewrites code using Abstract Syntax Tree patterns instead of brittle text matching, enabling structure-aware matches like function calls in loops or imports inside classes across multiple languages.

Can I run large-scale codemods to rename a symbol across files without breaking references?

Yes, codemod-like rewrites transform code while preserving semantics and enable large-scale refactors with confidence. You can audit a codebase to rename a symbol across files without breaking references using scope-aware AST rules.

What's the best way to enforce coding standards with AST linting rules?

AST linting enforces coding standards by applying structural rules to validate code patterns. This catches violations like function calls in loops or imports inside classes that text-based linters miss, ensuring safe refactors.

Do I need to install the ast-grep CLI to perform structural search and rewrites?

Yes, the ast-grep CLI must be installed to perform structural code search and rewrites. It configures pattern syntax, relational rules, and safe automated transformations across multiple languages and project types.

Does AST-based code analysis work across multiple programming languages?

Yes, AST-based code analysis works across multiple languages and project types, supporting precise pattern matching such as function calls, imports, and symbol renaming with scope awareness regardless of syntax differences.