hai-ast-grep

Generates validated ast-grep patterns and YAML rules for structural code search, lint, and rewrite.

Updated Jan 10, 2026
One-click install
npx skills add https://github.com/Rabbit-Ivan/Ivan-skills --skill hai-ast-grep-rabbit-ivan
Or copy as Structured Prompt for Agent▼
Please help me install this Agent Skill.
Skill: hai-ast-grep
Source: https://github.com/Rabbit-Ivan/Ivan-skills/tree/main/skills/hai-ast-grep
Command: npx skills add https://github.com/Rabbit-Ivan/Ivan-skills --skill hai-ast-grep-rabbit-ivan

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes references (resource) components.

What problem does it solve? Text-based grep and regex searches over-match comments and strings or miss formatting variants, making structural code search and repo-wide refactoring error-prone. This Skill produces ast-grep patterns and YAML rules that match code by tree-sitter AST structure, validated against positive and negative fixtures. ## Core Features & Use Cases - Structural Search: Find every call site of a function or API regardless of formatting, using CLI patterns like ast-grep run -p 'fetch($URL)'. - Batch Rewrite & Codemods: Rename functions, swap argument order, or migrate APIs repo-wide with rewrite templates and interactive or full-apply modes. - Lint Rules for CI: Write YAML rules with severity and messages to ban patterns like console.log in production, optionally adding a fix: line for auto-remediation. - Use Case: Before refactoring a shared utility, list every call site structurally, then apply a signature change across all files with a validated rewrite rule. ## Quick Start Ask the agent to write an ast-grep rule that finds all console.log calls in your src directory and validates it against a positive and negative example.

Frequently Asked Questions about hai-ast-grep

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

FAQPage Schema
How do I find all call sites of a function with ast-grep?▼

Run ast-grep run -p 'functionName($$$ARGS)' -l ts src/ to match every call site structurally, regardless of line breaks or formatting. Add -C 2 for context lines or --json for machine-readable output.

How do I write an ast-grep lint rule for CI?▼

Create a YAML file with id, language, severity, message, and a rule containing a pattern such as console.log($$$ARGS). Run ast-grep scan -r rules/your-rule.yml src/ to check code, and add a fix: line if you want automatic rewriting.

What is the difference between ast-grep run and ast-grep scan?▼

ast-grep run executes one-off pattern searches directly from the CLI without configuration. ast-grep scan loads YAML rule files and requires an sgconfig.yml for project-wide scans, making it suited for CI and reusable rules.

Which languages does ast-grep support?▼

ast-grep supports over 25 languages including JavaScript, TypeScript, Tsx, Python, Go, Rust, Java, C, Cpp, Ruby, Swift, Kotlin, and more. Language is set with the -l flag or inferred from file extensions.

When should I use ast-grep instead of grep or regex?▼

Use ast-grep when matching depends on syntax structure, such as finding call sites or rewriting code patterns, since grep hits comments and strings and misses formatting variants. For plain text replacement or single-file edits, grep or sed is sufficient.

Why does my ast-grep pattern not match expected code?▼

Patterns fail when the written syntax does not align with the actual AST node structure. Run ast-grep with --debug-query ast to inspect node types, then adjust the pattern or add kind, constraints, or relational rules like inside or has.