Now liveThe Skillselion MCP - thousands of ranked skills, loaded into your agent mid-task. No install.Get it →
pproenca avatar

Ast Grep

  • 279 installs
  • 191 repo stars
  • Updated July 24, 2026
  • pproenca/dot-skills

ast-grep is a Claude Code skill that teaches YAML ast-grep rule authoring and debugging for developers who need structural code search, linting, and automated rewrites.

About

ast-grep is a pproenca/dot-skills package (version 1.0.1) that codifies community best practices for writing, reviewing, and optimizing ast-grep YAML rules across large repositories. The skill walks developers from a natural-language query through example code, pattern or relational rule design, meta-variable constraints, and CLI test commands before deployment. It flags pitfalls such as missing stopBy:end on relational rules, improper meta reuse, and risky rewrite semantics. ast-grep triggers on tasks involving pattern syntax, kind/has/inside queries, all/any/not composition, and code transformation pipelines. Developers reach for ast-grep when ripgrep text search is too brittle to find language constructs like async functions missing error handling or calls with specific parameter shapes.

  • ast-grep

Ast Grep by the numbers

  • 279 all-time installs (skills.sh)
  • +7 installs in the week ending Aug 4, 2026 (Skillselion tracking)
  • Ranked #1,394 of 4,347 Backend & APIs skills by installs in the Skillselion catalog
  • Data as of Aug 4, 2026 (Skillselion catalog sync)
npx skills add https://github.com/pproenca/dot-skills --skill ast-grep

Add your badge

Show developers this skill is listed on Skillselion. Paste this into your README.

Listed on Skillselion
Installs279
repo stars191
Last updatedJuly 24, 2026
Repositorypproenca/dot-skills

How do you write ast-grep YAML rules correctly?

Use ast-grep for development tasks

Who is it for?

Developers authoring or reviewing ast-grep lint rules who need AST-accurate search and codemods beyond text grep.

Skip if: Teams that only need simple string search with ripgrep and have no structural refactor or lint automation requirements.

When should I use this skill?

A developer is writing, debugging, or reviewing ast-grep YAML rules for code search, linting, or transformation.

What you get

Validated ast-grep YAML rules, tested pattern matches, and documented rewrite fixes ready for sg scan or sg test.

  • ast-grep YAML rule files
  • tested sg scan results

By the numbers

  • Packages version 1.0.1 with 46 rules across 8 prioritized categories

Files

SKILL.mdMarkdownGitHub ↗

ast-grep Community Best Practices

Comprehensive best practices guide for ast-grep rule writing and usage, maintained by the ast-grep community. Contains 46 rules across 8 categories, prioritized by impact to guide automated rule generation and code transformation.

When to Apply

Reference these guidelines when:

  • Writing new ast-grep rules for linting or search
  • Debugging patterns that don't match expected code
  • Optimizing rule performance for large codebases
  • Setting up ast-grep projects with proper organization
  • Reviewing ast-grep rules for correctness and maintainability

General Workflow

Follow this workflow when creating ast-grep rules for code search:

Step 1: Understand the Query

Clarify what you want to find:

  • Target programming language
  • Edge cases to handle
  • What to include vs exclude

Step 2: Create Example Code

Write a sample code snippet representing the desired match pattern.

Step 3: Write the ast-grep Rule

Choose the right approach:

  • Use pattern for simple structures
  • Use kind with has/inside for complex structures
  • Combine with all, any, or not for compound queries
  • Always use `stopBy: end` for relational rules (inside, has) to ensure complete search

Step 4: Test the Rule

# Inspect AST structure
ast-grep run --pattern '[code]' --lang [language] --debug-query=ast

# Test inline rule
echo "[code]" | ast-grep scan --inline-rules "[rule]" --stdin

# Test from file
ast-grep scan --rule [file.yml] [path]

Step 5: Search the Codebase

Deploy the validated rule:

# Search with pattern (simple matches)
ast-grep run --pattern '[pattern]' --lang [language] [path]

# Search with rule file (complex queries)
ast-grep scan --rule [file.yml] [path]

# Apply fixes interactively
ast-grep scan --rule [file.yml] --interactive [path]

Quick Tips

1. Always use `stopBy: end` - Ensures complete subtree traversal for relational rules 2. Start simple, add complexity - Begin with patterns, progress to kinds, then relational rules 3. Debug with AST inspection - Use --debug-query=ast to verify structure matching 4. Escape in inline rules - Use \$VAR or single quotes for shell commands 5. Test in playground first - Use https://ast-grep.github.io/playground.html for rapid iteration

Rule Categories by Priority

PriorityCategoryImpactPrefix
1Pattern CorrectnessCRITICALpattern-
2Meta Variable UsageCRITICALmeta-
3Rule CompositionHIGHcompose-
4Constraint DesignHIGHconst-
5Rewrite CorrectnessMEDIUM-HIGHrewrite-
6Project OrganizationMEDIUMorg-
7Performance OptimizationMEDIUMperf-
8Testing & DebuggingLOW-MEDIUMtest-

Quick Reference

1. Pattern Correctness (CRITICAL)

  • `pattern-valid-syntax` - Use valid parseable code as patterns
  • `pattern-language-aware` - Account for language-specific syntax differences
  • `pattern-context-selector` - Use context and selector for code fragments
  • `pattern-avoid-comments-strings` - Avoid matching inside comments and strings
  • `pattern-strictness-levels` - Configure pattern strictness appropriately
  • `pattern-kind-vs-pattern` - Choose kind or pattern based on specificity needs
  • `pattern-debug-ast` - Use debug query to inspect AST structure
  • `pattern-nthchild-matching` - Use nthChild for index-based positional matching
  • `pattern-range-matching` - Use range for character position matching

2. Meta Variable Usage (CRITICAL)

  • `meta-naming-convention` - Follow meta variable naming conventions
  • `meta-single-node` - Match single AST nodes with meta variables
  • `meta-reuse-binding` - Reuse meta variables to enforce equality
  • `meta-underscore-noncapture` - Use underscore prefix for non-capturing matches
  • `meta-named-vs-unnamed` - Use double dollar for unnamed node matching
  • `meta-multi-match-lazy` - Understand multi-match variables are lazy

3. Rule Composition (HIGH)

  • `compose-all-for-and-logic` - Use all for AND logic between rules
  • `compose-any-for-or-logic` - Use any for OR logic between rules
  • `compose-not-for-exclusion` - Use not for exclusion patterns
  • `compose-inside-for-context` - Use inside for contextual matching
  • `compose-has-for-children` - Use has for child node requirements
  • `compose-matches-for-reuse` - Use matches for rule reusability
  • `compose-precedes-follows` - Use precedes and follows for sequential positioning
  • `compose-field-targeting` - Use field to target specific sub-nodes

4. Constraint Design (HIGH)

  • `const-kind-filter` - Use kind constraints to filter meta variables
  • `const-regex-filter` - Use regex constraints for text patterns
  • `const-not-inside-not` - Avoid constraints inside not rules
  • `const-pattern-constraint` - Use pattern constraints for structural filtering
  • `const-post-match-timing` - Understand constraints apply after matching

5. Rewrite Correctness (MEDIUM-HIGH)

  • `rewrite-preserve-semantics` - Preserve program semantics in rewrites
  • `rewrite-meta-variable-reference` - Reference all necessary meta variables in fix
  • `rewrite-transform-operations` - Use transform for complex rewrites
  • `rewrite-test-before-deploy` - Test rewrites on representative code
  • `rewrite-syntax-validity` - Ensure fix templates produce valid syntax

6. Project Organization (MEDIUM)

  • `org-project-structure` - Use standard project directory structure
  • `org-unique-rule-ids` - Use unique descriptive rule IDs
  • `org-severity-levels` - Assign appropriate severity levels
  • `org-file-filtering` - Use file filtering for targeted rules
  • `org-message-clarity` - Write clear actionable messages

7. Performance Optimization (MEDIUM)

  • `perf-specific-patterns` - Use specific patterns over generic ones
  • `perf-stopby-boundaries` - Use stopBy to limit search depth
  • `perf-thread-parallelism` - Leverage parallel scanning with threads
  • `perf-avoid-regex-heavy` - Avoid heavy regex in hot paths

8. Testing & Debugging (LOW-MEDIUM)

  • `test-valid-invalid-cases` - Write both valid and invalid test cases
  • `test-snapshot-updates` - Use snapshot testing for fix verification
  • `test-playground-first` - Test patterns in playground first
  • `test-edge-cases` - Test edge cases and boundary conditions

How to Use

Read individual reference files for detailed explanations and code examples:

  • Section definitions - Category structure and impact levels
  • Rule template - Template for adding new rules

Full Compiled Document

  • AGENTS.md - Complete compiled guide with all rules

Reference Files

FileDescription
AGENTS.mdComplete compiled guide with all rules
references/_sections.mdCategory definitions and ordering
assets/templates/_template.mdTemplate for new rules
metadata.jsonVersion and reference information

Related skills

How it compares

Pick ast-grep over plain grep or ripgrep skills when queries must match code structure such as function signatures, imports, or nested language constructs.

FAQ

When should developers invoke the ast-grep skill?

The ast-grep skill triggers when writing, reviewing, or debugging YAML rules for code search, linting, or transformation. It applies to pattern syntax, meta variables, relational has/inside queries, constraints, and rewrite testing with the ast-grep CLI.

What ast-grep pitfalls does the skill address?

The ast-grep skill warns about missing stopBy:end on relational rules, improper meta-variable reuse, overly broad pattern matches, and unsafe rewrite semantics. It recommends starting from a clear query and example code before authoring rules and testing with sg test.

Backend & APIsbackendintegrations

This week in AI coding

Five minutes, every Monday - the tools, releases and tactics for developers.

unsubscribe anytime.