Mass rename/replace across codebase. Use when user asks to rename functions, replace patterns, or refactor code across files. Better than grep for code changes.
Performs syntax-aware code search and refactoring across files using AST patterns. Triggers when you ask to rename functions, replace patterns, or refactor code across the codebase.
/plugin marketplace add settlemint/agent-marketplace/plugin install crew@settlemintThis skill inherits all available tools. When active, it can use any tool Claude has access to.
Search and refactor code using AST patterns. Unlike grep, ast-grep understands syntax - finds code structures, ignores strings/comments.
</objective><quick_start>
# Search
sg --pattern "console.log($$$)" --lang typescript
sg -p "async function $FUNC($$$)" -l typescript src/
# Refactor (preview first)
sg -p "console.log($MSG)" -r "logger.info($MSG)" -l typescript --debug-query
sg -p "console.log($MSG)" -r "logger.info($MSG)" -l typescript # Apply
</quick_start>
<pattern_syntax>
| Syntax | Meaning | Example |
|---|---|---|
$NAME | Single node | $FUNC($ARG) |
$$$ | Multiple nodes | function($$$ARGS) |
$_ | Any single node | $_.map($$$) |
</pattern_syntax>
<common_patterns>
# Functions
sg -p "async function $FUNC($$$)" -l typescript
sg -p "const $NAME = ($$$) => $BODY" -l typescript
# Imports
sg -p 'import { $$$IMPORTS } from "$MODULE"' -l typescript
# React
sg -p "use$HOOK($$$)" -l tsx
sg -p "<$COMPONENT $$$PROPS />" -l tsx
# Types
sg -p "interface $NAME { $$$BODY }" -l typescript
sg -p "type $NAME = $TYPE" -l typescript
</common_patterns>
<parameters>| Flag | Description |
|---|---|
-p, --pattern | AST pattern (required) |
-l, --lang | Language: typescript, tsx, javascript, go, rust, python |
-r, --rewrite | Replacement pattern |
--debug-query | Preview without changing |
--json | JSON output |
<vs_grep>
| ast-grep (sg) | ripgrep (rg) |
|---|---|
| Syntax-aware | Raw text/regex |
| Ignores strings/comments | All text |
| Precise refactoring | Fast file search |
</vs_grep>
<success_criteria>
--debug-query shows correct matches before refactoringtsx for JSX, typescript for pure TS)</success_criteria>