astgrep

Combine AST-based structural search with ripgrep text search to locate code patterns.

Updated Aug 23, 2026
One-click install
npx skills add https://github.com/raystyle/skills --skill astgrep
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: astgrep
Source: https://github.com/raystyle/skills/tree/main/skills/astgrep
Command: npx skills add https://github.com/raystyle/skills --skill astgrep

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes references (resource) components.

What problem does it solve?

AST-based code search enables precise structural matching that textual searches often miss, accelerating code exploration and safer refactoring by focusing on syntax and node relationships rather than just text.

Core Features & Use Cases

  • SG-search: structural pattern matching using ASTs to find code constructs.
  • RG-search: text search fallback for broad coverage.
  • SG-rewrite: safe, previewable code rewriting to apply structural changes.
  • Language support: sg-langs and sg-check coordinate language support and tooling readiness.
  • Use Case: locate function-call patterns, identify refactor opportunities, audit legacy code across large codebases.

Quick Start

Start by running sg-search with a query to locate code patterns across your codebase and review results before optionally applying sg-rewrite changes with --apply.

Frequently Asked Questions about astgrep

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

FAQPage Schema
How do I search for code patterns using AST matching across a large codebase?

You can search code patterns using AST matching by running sg-search with a structural query to locate specific code constructs across your codebase. This structural pattern matching focuses on syntax and node relationships rather than just text to accelerate code exploration.

What is the best way to plan a refactoring by finding function-call patterns in legacy code?

The best way to plan refactoring is using AST-based code search to find function-call patterns and identify refactor opportunities in legacy code. SG-search performs structural matching on syntax trees to locate exact code constructs safely.

How does combining AST search with ripgrep improve code discovery over text search?

Combining AST search with ripgrep improves code discovery by reconciling precise structural matching with broad textual coverage. AST search finds syntax constructs that text search misses, while ripgrep handles general keyword hits across large codebases.

Can I safely apply structural code changes after finding a pattern match?

You can safely apply structural code changes by using sg-rewrite to preview changes before applying them. After locating patterns with sg-search, run sg-rewrite to apply structural changes safely across the matched code constructs.

Does astgrep support security audits across multiple programming languages?

Yes, astgrep supports security audits across multiple programming languages by using sg-langs and sg-check to coordinate language support and tooling readiness. This enables structural pattern matching for auditing legacy code across large codebases.