ast-grep-find

Search code patterns with ASTs across Python and JavaScript codebases.

3|Updated Dec 31, 2025
One-click install
npx skills add https://github.com/Overdrive-Consulting/overdrive-ai-devkit --skill ast-grep-find-overdrive-consulting
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: ast-grep-find
Source: https://github.com/Overdrive-Consulting/overdrive-ai-devkit/tree/main/skills/ast-grep-find
Command: npx skills add https://github.com/Overdrive-Consulting/overdrive-ai-devkit --skill ast-grep-find-overdrive-consulting

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes scripts (resource) and references (resource) components.

What problem does it solve?

Structural code search and refactoring driven by abstract syntax trees (ASTs) to locate and modify code patterns without brittle text matches.

Core Features & Use Cases

  • AST-aware search for syntax-based patterns such as function definitions, imports, and class declarations.
  • Safe refactoring and code navigation across multiple languages with pattern-based replacements.
  • Use Case: Audit a large codebase to rename a function across files while preserving behavior.

Quick Start

Use the ast-grep-find skill to search for Python function definitions or imports across your repository. Example: uv run python -m runtime.harness scripts/ast_grep_find.py --pattern "def $FUNC($$$):" --language python

Frequently Asked Questions about ast-grep-find

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

FAQPage Schema
How do I find and rename a function across a large codebase without breaking syntax?

AST-based code search locates function definitions using abstract syntax trees to ensure syntax-aware pattern matching and safe refactoring without brittle text matches. It applies structural rules to preserve code behavior across multiple files.

What is AST-based pattern matching for static code analysis?

AST-based pattern matching is a static analysis technique that parses code into abstract syntax trees to locate syntax-aware structures like imports and class declarations. It identifies exact structural definitions rather than relying on fragile regular expressions.

Can I use ast-grep to search for Python and JavaScript imports in the same repository?

Yes, AST-based code search supports locating imports and class declarations across multiple languages like Python and JavaScript. It applies syntax-aware rules to parse and match structural patterns specific to each programming language within your codebase.

How do I run a dry-run for a code refactoring operation before applying changes?

You can execute a dry-run by applying a pattern syntax argument with the search script to preview structural matches before modifying files. This safe refactoring approach verifies AST pattern matching results across the codebase without committing changes.

Does AST code search work better than regex for refactoring variable names?

AST-based code search outperforms regex for refactoring by using abstract syntax trees to understand code structure, avoiding false positives from string literals or comments. This syntax-aware approach ensures safe replacements of function definitions and variables.

What are the limitations of using AST pattern matching for code search?

AST pattern matching requires specifying the target language like Python or JavaScript to parse syntax trees correctly. It may not locate patterns in unsupported file formats or dynamically generated code outside the static analysis scope of the codebase.