Co-Pilot / 辅助式
更新于 a month ago

agent-skill

Aast-grep
0.5k
ast-grep/agent-skill
82
Agent 评分

💡 摘要

一个 Claude Code 插件,支持使用抽象语法树(AST)模式进行结构化的代码搜索,超越了简单的文本匹配。

🎯 适合人群

执行代码审计的高级开发工程师管理大型代码库的技术负责人寻找漏洞的安全工程师重构遗留系统的代码迁移工程师

🤖 AI 吐槽:这就像给一位锁匠大师一套配钥匙工具,但他仍然需要你完美地描述锁的每一个细节。

安全分析中风险

风险:该技能会执行外部的 `ast-grep` CLI 工具,该工具根据用户提示读取和遍历本地文件系统,如果该工具或其依赖项被破坏,则存在数据暴露风险。缓解措施:使用已验证的安装源(例如官方包管理器)安装 ast-grep,并定期审计其依赖项。

ast-grep Plugin Marketplace for AI Agents

A Claude Code plugin marketplace containing the ast-grep skill for powerful structural code search using Abstract Syntax Tree (AST) patterns. Search your codebase based on code structure rather than just text matching.

What is This?

This is a Claude Code plugin marketplace that provides the ast-grep plugin. The plugin includes a skill that teaches Claude how to write and use ast-grep rules to perform advanced code searches. Unlike traditional text-based search (grep, ripgrep), ast-grep understands the structure of your code, allowing you to find patterns like:

  • "Find all async functions that don't have error handling"
  • "Locate all React components that use a specific hook"
  • "Find functions with more than 3 parameters"
  • "Search for console.log calls inside class methods"

Prerequisites

You need to have ast-grep installed on your system:

# macOS brew install ast-grep # npm npm install -g @ast-grep/cli # cargo cargo install ast-grep

Verify installation:

ast-grep --version

Installation

Option 1: Install via skills.sh (Recommended)

npx skills add ast-grep/agent-skill

Option 2: Install via Marketplace

  1. Add the marketplace to your Claude Code:
/plugin marketplace add ast-grep/agent-skill
  1. Install the ast-grep plugin:
/plugin install ast-grep
  1. Restart Claude Code to activate the plugin

  2. Verify installation: Use /help to see if ast-grep skill is available

Option 3: Install Locally for Development

If you're developing or testing locally:

# Clone the repository git clone https://github.com/ast-grep/claude-skill.git /path/to/local-marketplace # Add as local marketplace /plugin marketplace add /path/to/local-marketplace # Install the plugin /plugin install ast-grep

Usage Notes

You will need to ask Claude to use this skill explicitly in your queries, like "Use ast-grep to find...". Claude Code, as of Nov 2025, cannot automatically detect when to use ast-grep for all appropriate use cases.

How to Use

Once installed, simply ask Claude to search your code using structural patterns. Claude will automatically use this skill when appropriate.

Example Queries

Find async functions with await:

Find all async functions in this project that use await

Find missing error handling:

Show me async functions that don't have try-catch blocks

Find specific function calls:

Find all places where we call console.log with more than one argument

Find code in specific contexts:

Find all setState calls inside useEffect hooks

How It Works

When you ask Claude to search for code patterns:

  1. Claude analyzes your query and determines if ast-grep is appropriate
  2. It creates example code that matches your search criteria
  3. It writes an ast-grep rule to match the pattern
  4. It tests the rule against the example code
  5. Once verified, it searches your entire codebase
  6. Results are presented with file paths and line numbers

Supported Languages

ast-grep supports many programming languages including:

  • JavaScript/TypeScript
  • Python
  • Rust
  • Go
  • Java
  • C/C++
  • Ruby
  • PHP
  • And many more

Key Features

  • Structure-aware search: Matches code based on AST structure, not just text
  • Metavariables: Use $VAR to match any expression, statement, or identifier
  • Relational queries: Find code inside specific contexts (e.g., "find X inside Y")
  • Composite logic: Combine rules with AND, OR, NOT operations
  • Test-driven approach: Rules are tested before running on your codebase

Advanced Usage

Direct ast-grep Commands

While Claude will handle most use cases automatically, you can also use ast-grep directly:

# Simple pattern search ast-grep run --pattern 'console.log($ARG)' --lang javascript . # Complex rule-based search ast-grep scan --inline-rules "id: my-rule language: javascript rule: kind: function_declaration has: pattern: await \$EXPR stopBy: end" .

Debugging

If a search isn't working as expected, ask Claude to:

  • Show you the ast-grep rule it created
  • Inspect the AST structure of your code
  • Test the rule against example code

Repository Structure

This is a Claude Code plugin marketplace repository with the following structure:

claude-skill/
├── .claude-plugin/
│   └── marketplace.json           # Marketplace manifest
├── ast-grep/                       # ast-grep plugin
│   ├── .claude-plugin/
│   │   └── plugin.json            # Plugin manifest
│   └── skills/
│       └── ast-grep/
│           ├── SKILL.md           # Skill instructions for Claude
│           └── references/
│               └── rule_reference.md  # ast-grep rule documentation
├── ast-grep.zip                    # Archived version
└── README.md                       # This file

Key Files

  • .claude-plugin/marketplace.json: Marketplace manifest defining available plugins
  • ast-grep/.claude-plugin/plugin.json: Plugin manifest for the ast-grep plugin
  • ast-grep/skills/ast-grep/SKILL.md: Main skill instructions that Claude uses
  • ast-grep/skills/ast-grep/references/: Supporting documentation and reference materials

Tips for Best Results

  1. Be specific: The more details you provide, the better the search results
  2. Provide examples: If possible, show Claude an example of what you want to find
  3. Iterate: Start with a broad search and narrow it down
  4. Ask for explanations: Ask Claude to explain the ast-grep rule it creates

Examples of What You Can Search For

Code Quality

  • Functions without return statements
  • Functions with too many parameters
  • Unused variables
  • Missing null checks

Patterns

  • React hooks usage patterns
  • API call patterns
  • Database query patterns
  • Error handling patterns

Refactoring

  • Find all uses of deprecated functions
  • Locate code that needs migration
  • Find inconsistent patterns across codebase

Security

  • Potential SQL injection points
  • Unsafe eval usage
  • Missing input validation

Troubleshooting

Claude isn't using the skill:

  • Make sure ast-grep is installed (ast-grep --version)
  • Try being more explicit: "Use ast-grep to search for..."

No results found:

  • Try a simpler query first
  • Ask Claude to show you the rule and test it
  • Provide an example of code you want to match

Unexpected results:

  • Refine your query with more details
  • Ask Claude to exclude certain patterns
  • Request to see the AST structure of your code

Contributing

To improve this skill:

  1. Edit SKILL.md to update Claude's instructions
  2. Add examples to references/ directory
  3. Test with various code patterns

Resources

License

This skill follows ast-grep's MIT license for any included documentation or examples.

Support

For issues with:

五维分析
清晰度8/10
创新性7/10
实用性9/10
完整性9/10
可维护性8/10
优缺点分析

优点

  • 通过 AST 实现强大、上下文感知的代码搜索。
  • 直接集成到 Claude Code 工作流中。
  • 支持广泛的编程语言。
  • 包含清晰的示例和故障排除指南。

缺点

  • 需要用户明确提示,非全自动。
  • 依赖外部 ast-grep CLI 工具的安装。
  • 制定有效的结构模式存在学习曲线。

相关技能

pytorch

S
toolCode Lib / 代码库
92/ 100

“它是深度学习的瑞士军刀,但祝你好运能从47种安装方法里找到那个不会搞崩你系统的那一个。”

agno

S
toolCode Lib / 代码库
90/ 100

“它承诺成为智能体领域的Kubernetes,但得看开发者有没有耐心学习又一个编排层。”

nuxt-skills

S
toolCo-Pilot / 辅助式
90/ 100

“这本质上是一份组织良好的小抄,能把你的 AI 助手变成一只 Nuxt 框架的复读机。”

免责声明:本内容来源于 GitHub 开源项目,仅供展示和评分分析使用。

版权归原作者所有 ast-grep.