Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions .claude-plugin/marketplace.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"name": "claude-skills-marketplace",
"owner": {
"name": "dylan"
},
"plugins": [
{
"name": "ast-grep",
"description": "Structural code search using Abstract Syntax Tree (AST) patterns. Search codebases based on code structure rather than text matching.",
"version": "1.0.0",
"source": "./plugins/ast-grep",
"author": {
"name": "dylan"
},
"license": "MIT",
"keywords": ["ast", "code-search", "structural-search", "ast-grep", "refactoring"]
}
]
}
64 changes: 64 additions & 0 deletions CLAUDE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
# CLAUDE.md

This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.

## Project Overview

This is a Claude Code plugin marketplace - a collection of plugins that extend Claude's capabilities with specialized skills, commands, and agents.

## Repository Structure

```
.claude-plugin/
└── marketplace.json # Marketplace registry (lists all plugins)
plugins/
└── <plugin-name>/
├── .claude-plugin/
│ └── plugin.json # Plugin manifest (required: name field)
├── skills/ # Skills extend Claude's autonomous capabilities
│ └── <skill-name>/
│ ├── SKILL.md # Skill instructions with YAML frontmatter
│ └── references/ # Supporting documentation
├── commands/ # Custom slash commands (markdown files)
├── agents/ # Specialized subagents (markdown files)
└── hooks/ # Event-driven automation (JSON files)
```

## Current Plugins

### ast-grep
Structural code search using AST patterns. Located at `plugins/ast-grep/`.

Key files:
- `plugins/ast-grep/skills/ast-grep/SKILL.md` - Main skill instructions
- `plugins/ast-grep/skills/ast-grep/references/rule_reference.md` - Rule syntax reference

## Adding a New Plugin

1. Create `plugins/<name>/.claude-plugin/plugin.json`:
```json
{"name": "<name>", "version": "1.0.0", "description": "..."}
```

2. Add components in appropriate directories (skills/, commands/, agents/, hooks/)

3. Register in `.claude-plugin/marketplace.json`:
```json
{"name": "<name>", "source": "./plugins/<name>", ...}
```

## Key Plugin Concepts

- **Skills**: SKILL.md files with YAML frontmatter (`name`, `description`) teach Claude new capabilities
- **Commands**: Markdown files that define custom `/command` operations
- **Agents**: Specialized subagents Claude can invoke for specific tasks
- **Hooks**: JSON configs that respond to events (PostToolUse, SessionStart, etc.)

## Critical Pattern for ast-grep Rules

Always use `stopBy: end` for relational rules:
```yaml
has:
pattern: await $EXPR
stopBy: end
```
234 changes: 59 additions & 175 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,24 +1,47 @@
# ast-grep Skill for Claude Code
# Claude Skills Marketplace

A Claude Code skill that enables powerful structural code search using Abstract Syntax Tree (AST) patterns. Search your codebase based on code structure rather than just text matching.
A collection of Claude Code plugins that extend Claude's capabilities with specialized skills.

## What is This?
## Available Plugins

Agent Skills are modular capabilities that extend Claude’s functionality. Each Skill packages instructions, metadata, and optional resources (scripts, templates) that Claude uses automatically when relevant.
### ast-grep

ast-grep skill 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:
Structural code search using Abstract Syntax Tree (AST) patterns. Search codebases based on code structure rather than text matching.

**Features:**
- Structure-aware search that understands code syntax
- Metavariables (`$VAR`, `$$$ARGS`) to match any expression or statement
- Relational queries to find code inside specific contexts
- Composite logic (AND, OR, NOT) for complex matching

**Example queries:**
- "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"

## Installation

### Add the Marketplace

```
/plugin marketplace add github:dylan/claude-skills-marketplace
```

### Install a Plugin

```
/plugin install ast-grep@claude-skills-marketplace
```

Or browse available plugins:

```
/plugin
```

## Prerequisites

You need to have ast-grep installed on your system:
For the ast-grep plugin, you need ast-grep installed:

```bash
# macOS
Expand All @@ -31,185 +54,46 @@ npm install -g @ast-grep/cli
cargo install ast-grep
```

Verify installation:
```bash
ast-grep --version
```

## Installation

1. Clone or download this repository to your Claude Code skills directory:

```bash
# If you have a skills directory configured
cp -r ast-grep ~/.claude/skills/

# Or place it wherever your Claude Code skills are located
```

2. The skill should be automatically detected by Claude Code. You can verify by checking available skills in Claude Code.

3. 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 pick up ast-grep for proper use cases automatically.

## How to Use
## Repository Structure

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
.claude-plugin/
└── marketplace.json # Marketplace configuration
plugins/
└── ast-grep/
├── .claude-plugin/
│ └── plugin.json # Plugin manifest
└── skills/
└── ast-grep/
├── SKILL.md # Skill instructions
└── references/
└── rule_reference.md
```

**Find missing error handling:**
```
Show me async functions that don't have try-catch blocks
```
## Creating a New Plugin

**Find specific function calls:**
```
Find all places where we call console.log with more than one argument
```
1. Create a directory under `plugins/`
2. Add `.claude-plugin/plugin.json` with required `name` field
3. Add components (skills, commands, agents, hooks) in appropriate directories
4. Register the plugin in `.claude-plugin/marketplace.json`

**Find code in specific contexts:**
```
Find all setState calls inside useEffect hooks
```
### Plugin Manifest Example

### 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:

```bash
# 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" .
```json
{
"name": "my-plugin",
"version": "1.0.0",
"description": "What the plugin does",
"author": "your-name"
}
```

### 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

## Files in This Skill

- `SKILL.md` - Main skill instructions for Claude
- `references/rule_reference.md` - Comprehensive ast-grep rule documentation
- `README.md` - This file

## 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

- [ast-grep Official Documentation](https://ast-grep.github.io/)
- [ast-grep Playground](https://ast-grep.github.io/playground.html) - Test patterns online
- [ast-grep GitHub](https://github.com/ast-grep/ast-grep)
- [ast-grep Documentation](https://ast-grep.github.io/)
- [ast-grep Playground](https://ast-grep.github.io/playground.html)
- [Claude Code Plugins Guide](https://code.claude.com/docs/en/plugins.md)

## License

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

## Support

For issues with:
- **This skill**: Open an issue in this repository
- **ast-grep itself**: Visit [ast-grep GitHub](https://github.com/ast-grep/ast-grep)
- **Claude Code**: Check [Claude Code documentation](https://code.claude.com/)
MIT
Binary file removed ast-grep.zip
Binary file not shown.
Loading