ast-grep

Identify syntax-based code patterns across Python, JavaScript/TypeScript, and Java codebases.

8|2|Updated Jul 13, 2015
One-click install
npx skills add https://github.com/tstapler/dotfiles --skill ast-grep-tstapler
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: ast-grep
Source: https://github.com/tstapler/dotfiles/tree/main/.claude/skills/ast-grep
Command: npx skills add https://github.com/tstapler/dotfiles --skill ast-grep-tstapler

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

Locate code patterns that depend on syntax rather than text, such as function calls, imports, or decorators, by analyzing the code's structure.

Core Features & Use Cases

  • Semantic pattern matching: Use AST-informed queries to find calls, definitions, imports, and decorators.
  • Language support: Works with Python, JavaScript/TypeScript, Java, and more via language flags.
  • Flexible output: Reports matches with file paths, line numbers, and surrounding context for quick review.
  • Use Case: Refactor or understand unfamiliar codebases by locating all usages of a symbol across a project.

Quick Start

Run sg with a language flag and a pattern to locate the desired syntax construct in your codebase.

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 using syntax structure instead of plain text?

AST-informed semantic search supports Python, JavaScript/TypeScript, and Java by applying language flags during your query to locate specific syntax constructs accurately.

How do I find all usages of a function or decorator across a project?

You can locate all usages of a symbol across a project by running a semantic pattern matching query with a language flag, which reports matches with file paths, line numbers, and surrounding context.

Does AST pattern matching work for refactoring unfamiliar codebases?

AST pattern matching works for refactoring unfamiliar codebases by identifying syntax-based code patterns across files, helping you understand structural dependencies and locate all relevant usages for review.

What context is provided when semantic code search finds a match?

Semantic code search provides context-rich match reporting that includes file paths, line numbers, and surrounding code context, allowing you to quickly review and verify the located syntax constructs.

Can I use language-agnostic pattern matching to find imports and classes?

Language-agnostic pattern matching applies to functions, classes, imports, and decorators by using AST-informed queries to find definitions and usages across multiple supported programming languages.