ast-grep
Originally fromast-grep/claude-skill
Installation
Summary
Structural code search using Abstract Syntax Tree patterns for precise codebase queries.
- Translates natural language queries into ast-grep YAML rules to match code by structure rather than text, supporting complex patterns like "async functions without error handling"
- Provides step-by-step workflow: understand the query, create example code, write the rule, test with CLI, then search the codebase
- Includes debugging tools (
--debug-query) to inspect AST structure and understand how code is parsed, plus inline rule testing via--stdin - Supports both simple pattern-based searches (
ast-grep run) and complex rule-based searches with relational operators (has,inside,precedes) and composite logic (all,any,not)
SKILL.md
ast-grep Code Search
Overview
This skill helps translate natural language queries into ast-grep rules for structural code search. ast-grep uses Abstract Syntax Tree (AST) patterns to match code based on its structure rather than just text, enabling powerful and precise code search across large codebases.
When to Use This Skill
Use this skill when users:
- Need to search for code patterns using structural matching (e.g., "find all async functions that don't have error handling")
- Want to locate specific language constructs (e.g., "find all function calls with specific parameters")
- Request searches that require understanding code structure rather than just text
- Ask to search for code with particular AST characteristics
- Need to perform complex code queries that traditional text search cannot handle
General Workflow
Follow this process to help users write effective ast-grep rules: