ast-grep

Search and refactor code patterns using AST-based syntax across 20+ languages.

Updated Aug 23, 2026
One-click install
npx skills add https://github.com/towry/dots --skill ast-grep-towry
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: ast-grep
Source: https://github.com/towry/dots/tree/main/conf/claude-local-marketplace/skills/ast-grep
Command: npx skills add https://github.com/towry/dots --skill ast-grep-towry

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

Use ast-grep to search, lint, and rewrite code using Abstract Syntax Trees (ASTs) across 20+ languages. It enables pattern-based searches that are aware of code structure, not just text.

Core Features & Use Cases

  • Patterned Searches: Query code with language-aware patterns and meta-variables.
  • Code Refactoring: Rewrite selections safely while preserving semantics.
  • Linting & Validation: Apply rule-based checks to catch issues early.

Quick Start

Example: ast-grep run -p 'console.log($MSG)' -l javascript ast-grep run -p 'System.out.println($MSG)' -l java

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 across multiple programming languages?

ast-grep enables pattern-based code search across 20+ languages using Abstract Syntax Trees, making queries structure-aware rather than text-based. Use the CLI with language flags like `-l javascript` or `-l java` to search with meta-variables that match code semantically.

Can I use AST-based patterns to refactor code safely?

Yes, ast-grep rewrites code selections while preserving semantics through structural pattern matching. Define patterns with meta-variables and capture groups, then apply transformations via YAML rule configurations to safely refactor across your codebase.

How do I set up linting rules for code quality checks?

ast-grep supports rule-driven checks through YAML configuration files that define AST-based linting rules. Apply these rules with the CLI workflow commands to enforce structural patterns and catch issues early across Java, JavaScript, TypeScript, Python, Rust, Go, and other supported languages.

Does ast-grep work with my programming language?

ast-grep supports over 20 languages including Java, JavaScript, TypeScript, Python, Rust, Go, and many others. Check the official documentation for the complete list of supported languages and their feature coverage.

What's the difference between AST-based search and regex pattern matching?

AST-based search understands code structure and syntax, matching semantically equivalent patterns regardless of formatting. Regex matches text literally, making it fragile to whitespace and formatting changes; ast-grep patterns remain robust across structural variations.

Can I test and validate my ast-grep rules before deployment?

Yes, ast-grep includes CLI commands for testing rules: use `ast-grep test` to validate rule behavior against sample code before scanning your entire codebase with `ast-grep scan`.