ast-grep

Execute AST-based search, linting, and codemod rewrites with syntax-aware patterns.

1|1|Updated May 3, 2026
One-click install
npx skills add https://github.com/matt-riley/agent-skills --skill ast-grep-matt-riley
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: ast-grep
Source: https://github.com/matt-riley/agent-skills/tree/main/skills/ast-grep
Command: npx skills add https://github.com/matt-riley/agent-skills --skill ast-grep-matt-riley

SYSTEM DOCUMENTATION & REQUIREMENTS

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

What problem does it solve?

AST-based code search, linting, and codemod rewrites enable structure-aware edits over plain-text searches, reducing false positives and enabling scalable refactors.

Core Features & Use Cases

  • Structural search and pattern matching over code to identify API usage, anti-patterns, or refactor targets
  • Lint-rule style validations and safe codemod previews before applying changes
  • Use case: refactor a repetitive coding pattern across a large TS/JS codebase with confidence after previews

Quick Start

Execute an AST-based search or rewrite using the provided CLI with explicit language and scoped paths.

Frequently Asked Questions about ast-grep

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

FAQPage Schema
How do I refactor repetitive coding patterns across a large TypeScript codebase safely?

AST-based codemod rewrites refactor repetitive TypeScript patterns by applying syntax-aware transformations. You get safe previews before applying changes, ensuring reproducible results across large codebases without false positives from plain-text search.

What is structural code search and how does it reduce false positives?

Structural code search parses abstract syntax trees to match code patterns based on syntax and semantics rather than text. This structure-aware approach eliminates false positives that plague plain-text regex searches when finding API usage or anti-patterns.

Can I preview codemod changes before applying them to my project?

Yes, AST-based codemod rewrites provide safe previews before applying any changes. You validate lint-rule style transformations against your scoped paths and confirm the structural edits before committing the rewrites to your codebase.

Does ast-grep work for pattern-based migrations in JavaScript and TypeScript?

ast-grep executes AST-based search and codemod rewrites for JavaScript and TypeScript pattern-based migrations. It applies syntax-aware transformations to scoped paths, enabling scalable refactors across supported languages with reproducible results.

What's the best way to lint for anti-patterns using syntax-aware rules?

AST-based linting validates code against syntax-aware rules by parsing abstract syntax trees instead of plain text. This structure-aware mechanism identifies anti-patterns and API usage accurately, reducing false positives during large-scale codebase analysis.

When should I use structural editing instead of plain-text search and replace?

Use structural editing when plain-text search produces false positives or misses semantic matches. AST-based rewrites parse syntax trees to apply safe, reproducible transformations, making them essential for large-scale refactors and pattern-based migrations.