AST-based code search and rewrite tool integration for Claude Code. This plugin reduces token usage by performing structural code queries instead of reading entire files.
- Structural Code Search: Search code by AST patterns instead of text matching
- Code Rewriting: Refactor code at scale using pattern-based replacements
- YAML Rules: Define custom linting and rewriting rules
- Multi-language Support: TypeScript, JavaScript, Python, Go, Java, Rust, and more
- Token Optimization: Automatically uses ast-grep for large-scale searches (>5 files)
First, install the ast-grep command-line tool:
npm install --global @ast-grep/cli
# or
pip install ast-grep-cli
# or
brew install ast-grepVerify installation:
ast-grep --versionInstall the plugin via GitHub:
claude plugin install https://github.com/jiangfire/ast-grep-pluginOr if published to the official marketplace:
claude plugin install ast-grepCheck that the plugin is loaded:
claude plugin listYou should see ast-grep in the list of installed plugins.
- ast-grep-patterns: Learn pattern syntax and wildcards for structural search
- ast-grep-rules: Configure YAML rules for linting and code quality
/ast-grep:search <pattern> [paths...]- Search code with AST patterns/ast-grep:rewrite <pattern> <replacement> [paths...]- Rewrite code with patterns/ast-grep:scan [--rule <file>]- Scan code with YAML rules
- ast-grep-search: Automatically generates and executes ast-grep patterns for code queries
/ast-grep:search "console.log($MSG)" --lang js
/ast-grep:rewrite "var $VAR = $VAL" "let $VAR = $VAL" --lang js
/ast-grep:scan --rule ./rules/no-console.yml
The ast-grep-search agent automatically uses ast-grep when:
- Searching across more than 5 files
- Looking for specific code structures (functions, classes, imports)
- Performing batch refactoring operations
- TESTING.md - Complete testing checklist and verification guide
- ROADMAP.md - Future improvements and enhancement plans
Contributions are welcome! See ROADMAP.md for planned features and how to contribute.
MIT