ast-grep

Search code structurally using AST patterns across multiple languages.

2|Updated Aug 20, 2025
One-click install
npx skills add https://github.com/disusered/dotfiles-universal --skill ast-grep
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: ast-grep
Source: https://github.com/disusered/dotfiles-universal/tree/main/ai/claude/skills/tools/ast-grep
Command: npx skills add https://github.com/disusered/dotfiles-universal --skill ast-grep

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

This Skill solves the problem of imprecise code searching and refactoring by understanding code structure rather than just text. It helps developers quickly find specific patterns, identify deprecated APIs, and enforce coding standards, saving time and reducing errors in large codebases.

Core Features & Use Cases

  • Syntax-Aware Search: Finds code patterns based on Abstract Syntax Trees (AST), avoiding false positives from comments or or strings.
  • Multi-Language Support: Works across JavaScript, TypeScript, Python, Go, Rust, Java, and more, making it versatile for polyglot environments.
  • Refactoring Aid: Ideal for identifying all instances of a deprecated function or a specific code structure before a large-scale refactor.
  • Use Case: You need to refactor all console.log() statements in your TypeScript project. Instead of a naive text search, use ast-grep --pattern 'console.log($MSG)' --lang ts to precisely locate only executable console.log calls, ignoring those in comments or strings.

Quick Start

Use ast-grep to find all useState calls in my TypeScript files. ast-grep --pattern 'useState($INIT)' --lang ts

Frequently Asked Questions about ast-grep

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

FAQPage Schema
How do I find specific code patterns across a large codebase without false positives?

Structural code search using Abstract Syntax Trees (AST) identifies patterns based on code structure rather than text, eliminating false matches in comments or strings. ast-grep applies this to JavaScript, TypeScript, Python, Go, Rust, Java, and other languages, making it precise for large repositories.

Can I use AST-based search to refactor deprecated functions across multiple files?

Yes. Structural refactoring pinpoints all instances of a specific function call or code pattern before large-scale refactors. You specify a syntax pattern and language, and it returns exact matches with optional context for planning and tooling integration.

What's the best way to enforce coding standards and identify API usage patterns in my repository?

Syntax-aware code inspection using AST patterns enforces standards by finding specific code structures consistently across your codebase. Define a pattern for the standard or anti-pattern you want to detect, and retrieve all violations with JSON output for downstream analysis.

Does structural code search work with polyglot projects using multiple programming languages?

Yes. Multi-language support covers JavaScript, TypeScript, Python, Go, Rust, Java, and more. Specify the target language with each search, allowing you to apply consistent refactoring strategies across different parts of a polyglot environment.

How do I output search results in a format that integrates with other tools or planning workflows?

Search results are returned in JSON format with optional context, enabling integration with downstream tooling, reporting systems, and migration planning. This structured output supports automation and batch processing for large refactoring initiatives.

Why does text-based search fail for code refactoring compared to syntax-aware approaches?

Text search matches strings in comments, documentation, and non-executable locations, creating false positives and incomplete refactors. Syntax-aware search uses AST parsing to identify only executable code matching your pattern, ensuring accuracy and safety.