$npx -y skills add parcadei/Continuous-Claude-v3 --skill ast-grep-findAST-based code search and refactoring via ast-grep MCP
| 1 | # AST-Grep Find |
| 2 | |
| 3 | Structural code search that understands syntax. Find patterns like function calls, imports, class definitions - not just text. |
| 4 | |
| 5 | ## When to Use |
| 6 | |
| 7 | - Find code patterns (ignores strings/comments) |
| 8 | - Search for function calls, class definitions, imports |
| 9 | - Refactor code with AST precision |
| 10 | - Rename variables/functions across codebase |
| 11 | |
| 12 | ## Usage |
| 13 | |
| 14 | ### Search for a pattern |
| 15 | ```bash |
| 16 | uv run python -m runtime.harness scripts/ast_grep_find.py \ |
| 17 | --pattern "import asyncio" --language python |
| 18 | ``` |
| 19 | |
| 20 | ### Search in specific directory |
| 21 | ```bash |
| 22 | uv run python -m runtime.harness scripts/ast_grep_find.py \ |
| 23 | --pattern "async def \$FUNC(\$\$\$)" --language python --path "./src" |
| 24 | ``` |
| 25 | |
| 26 | ### Refactor/replace pattern |
| 27 | ```bash |
| 28 | uv run python -m runtime.harness scripts/ast_grep_find.py \ |
| 29 | --pattern "console.log(\$MSG)" --replace "logger.info(\$MSG)" \ |
| 30 | --language javascript |
| 31 | ``` |
| 32 | |
| 33 | ### Dry run (preview changes) |
| 34 | ```bash |
| 35 | uv run python -m runtime.harness scripts/ast_grep_find.py \ |
| 36 | --pattern "print(\$X)" --replace "logger.info(\$X)" \ |
| 37 | --language python --dry-run |
| 38 | ``` |
| 39 | |
| 40 | ## Parameters |
| 41 | |
| 42 | | Parameter | Description | |
| 43 | |-----------|-------------| |
| 44 | | `--pattern` | AST pattern to search (required) | |
| 45 | | `--language` | Language: `python`, `javascript`, `typescript`, `go`, etc. | |
| 46 | | `--path` | Directory to search (default: `.`) | |
| 47 | | `--glob` | File glob pattern (e.g., `**/*.py`) | |
| 48 | | `--replace` | Replacement pattern for refactoring | |
| 49 | | `--dry-run` | Preview changes without applying | |
| 50 | | `--context` | Lines of context (default: 2) | |
| 51 | |
| 52 | ## Pattern Syntax |
| 53 | |
| 54 | | Syntax | Meaning | |
| 55 | |--------|---------| |
| 56 | | `$NAME` | Match single node (variable, expression) | |
| 57 | | `$$$` | Match multiple nodes (arguments, statements) | |
| 58 | | `$_` | Match any single node (wildcard) | |
| 59 | |
| 60 | ## Examples |
| 61 | |
| 62 | ```bash |
| 63 | # Find all function definitions |
| 64 | uv run python -m runtime.harness scripts/ast_grep_find.py \ |
| 65 | --pattern "def \$FUNC(\$\$\$):" --language python |
| 66 | |
| 67 | # Find console.log calls |
| 68 | uv run python -m runtime.harness scripts/ast_grep_find.py \ |
| 69 | --pattern "console.log(\$\$\$)" --language javascript |
| 70 | |
| 71 | # Replace print with logging |
| 72 | uv run python -m runtime.harness scripts/ast_grep_find.py \ |
| 73 | --pattern "print(\$X)" --replace "logging.info(\$X)" \ |
| 74 | --language python --dry-run |
| 75 | ``` |
| 76 | |
| 77 | ## vs morph/warpgrep |
| 78 | |
| 79 | | Tool | Best For | |
| 80 | |------|----------| |
| 81 | | **ast-grep** | Structural patterns (understands code syntax) | |
| 82 | | **warpgrep** | Fast text/regex search (20x faster grep) | |
| 83 | |
| 84 | Use ast-grep when you need syntax-aware matching. Use warpgrep for raw speed. |
| 85 | |
| 86 | ## MCP Server Required |
| 87 | |
| 88 | Requires `ast-grep` server in mcp_config.json. |