Skip to content

jiangfire/ast-grep-plugin

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

9 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

ast-grep Plugin

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.

Features

  • 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)

Installation

1. Install ast-grep CLI tool

First, install the ast-grep command-line tool:

npm install --global @ast-grep/cli
# or
pip install ast-grep-cli
# or
brew install ast-grep

Verify installation:

ast-grep --version

2. Install the plugin

Install the plugin via GitHub:

claude plugin install https://github.com/jiangfire/ast-grep-plugin

Or if published to the official marketplace:

claude plugin install ast-grep

3. Verify plugin installation

Check that the plugin is loaded:

claude plugin list

You should see ast-grep in the list of installed plugins.

Components

Skills

  • ast-grep-patterns: Learn pattern syntax and wildcards for structural search
  • ast-grep-rules: Configure YAML rules for linting and code quality

Commands

  • /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

Agents

  • ast-grep-search: Automatically generates and executes ast-grep patterns for code queries

Usage Examples

Search for function calls

/ast-grep:search "console.log($MSG)" --lang js

Refactor code

/ast-grep:rewrite "var $VAR = $VAL" "let $VAR = $VAL" --lang js

Scan with rules

/ast-grep:scan --rule ./rules/no-console.yml

When ast-grep is Used Automatically

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

Documentation

  • TESTING.md - Complete testing checklist and verification guide
  • ROADMAP.md - Future improvements and enhancement plans

Contributing

Contributions are welcome! See ROADMAP.md for planned features and how to contribute.

License

MIT

About

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.

Resources

License

Stars

Watchers

Forks

Packages

 
 
 

Contributors