ast-grep

Perform syntax-aware structural code search and refactoring with ast-grep patterns.

3|Updated Jun 4, 2021
One-click install
npx skills add https://github.com/tizee/dotfiles --skill ast-grep-tizee
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: ast-grep
Source: https://github.com/tizee/dotfiles/tree/main/claude/skills/ast-grep
Command: npx skills add https://github.com/tizee/dotfiles --skill ast-grep-tizee

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

ast-grep provides syntax-aware code search and refactoring, allowing you to find and modify code by structure rather than plain text.

Core Features & Use Cases

  • Structural searches across languages (JS/TS, Python, etc.)
  • Language-aware refactoring (rename, move, adjust imports)
  • Cross-language pattern detection in monorepos

Quick Start

Find all class definitions in TypeScript: sg -p 'class $NAME { $$ }' -l typescript .

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 specific code structures across my codebase?

Structural code search locates functions, classes, imports, and other syntax patterns by their structure rather than plain text. ast-grep uses pattern syntax to match code across JavaScript, TypeScript, Python, Ruby, Go, Rust, and other languages, returning precise results that text search cannot.

Can I refactor code patterns across multiple files and languages?

Yes. Language-aware refactoring rewrites matching code structures—renaming, moving, adjusting imports—across your entire codebase. ast-grep handles multi-language environments and monorepos, applying consistent changes without breaking syntax.

What's the best way to find and replace code by structure instead of text?

Define a pattern using ast-grep's syntax to describe the code structure you want to find, then apply automated or interactive rewrites. This catches variations text search misses and ensures replacements respect language grammar.

Does ast-grep work with TypeScript and Python in the same project?

Yes. ast-grep supports cross-language pattern detection in monorepos, letting you search and refactor TypeScript, Python, JavaScript, and other languages within a single codebase using language-specific syntax rules.

How do I extract code search results for downstream processing?

ast-grep outputs JSON, making results easy to pipe into other tools for analysis, reporting, or automation. This enables integration into CI/CD pipelines and custom workflows.

What syntax do I need to know to write search patterns?

ast-grep uses pattern syntax that describes code structure declaratively—for example, `class $NAME { $$ }` matches any class. Patterns use placeholders and wildcards aligned with the language's grammar, not regex or text matching.