Agent skill
ast-grep
Search code using Abstract Syntax Tree patterns with ast-grep. Use when finding code structures, bug patterns, or refactoring candidates that depend on syntax rather than text.
Install this agent skill to your Project
npx add-skill https://github.com/majiayu000/claude-skill-registry/tree/main/skills/development/ast-grep
SKILL.md
ast-grep - Structural Code Search
ast-grep searches code by matching AST patterns, not text. This finds code based on structure regardless of formatting or variable names.
Basic Usage
ast-grep run -p 'PATTERN' -l LANGUAGE
Pattern Syntax
$VAR- Match any single node (like a wildcard)$$$- Match zero or more nodes- Literal code matches itself
Common Patterns
| Goal | Pattern | Language |
|---|---|---|
| Find subtraction with specific left operand | discount - $VAR |
typescript |
| Find all useEffect with empty deps | useEffect($FN, []) |
tsx |
| Find console.log calls | console.log($$$) |
typescript |
| Find async functions | async function $NAME($$$) { $$$ } |
typescript |
Example: Finding Reversed Operands
To find where discount appears on the left side of subtraction:
ast-grep run -p 'discount - $VAR' -l typescript
This would find bugs like discount - basePrice (should be basePrice - discount).
When to Use
- Finding bug patterns based on code structure
- Locating specific API usage patterns
- Identifying refactoring candidates
- Searching for security anti-patterns
Recommended Agent Skills
Expand your agent's capabilities with these related and highly-rated skills.
agent-ops-spec
Manage specification documents in .agent/specs/. Use when user provides requirements, acceptance criteria, or feature descriptions that need to be tracked and validated against implementation.
agent-ops-state
Maintain .agent state files. Use at session start, after meaningful steps, and before concluding: read/update constitution/memory/focus/issues/baseline consistently.
agent-ops-spec
Manage specification documents in .agent/specs/. Use when user provides requirements, acceptance criteria, or feature descriptions that need to be tracked and validated against implementation.
agent-ops-testing
Test strategy, execution, and coverage analysis. Use when designing tests, running test suites, or analyzing test results beyond baseline checks.
agent-ops-testing
Test strategy, execution, and coverage analysis. Use when designing tests, running test suites, or analyzing test results beyond baseline checks.
agent-ops-state
Maintain .agent state files. Use at session start, after meaningful steps, and before concluding: read/update constitution/memory/focus/issues/baseline consistently.
Didn't find tool you were looking for?