2.8 KiB
2.8 KiB
Example: Simple Plugin
This example shows a minimal but complete Claude Code plugin.
Directory Structure
my-greeting-plugin/
├── .claude-plugin/
│ └── plugin.json
├── commands/
│ └── greet.md
└── README.md
plugin.json
{
"name": "my-greeting-plugin",
"version": "1.0.0",
"description": "A simple greeting plugin",
"author": {
"name": "Your Name"
},
"license": "MIT",
"keywords": ["greeting", "example"]
}
Note: No commands field needed since we're using the standard commands/ directory.
commands/greet.md
---
description: Greet the user with a personalized message
argument-hint: [name]
---
# Greet Command
Provide a warm, friendly greeting to the user.
## Instructions
1. If the user provided a name via `$ARGUMENTS`, greet them personally
2. If no name provided, use a generic friendly greeting
3. Add a fun emoji to make it welcoming
## Examples
**Input**: `/my-greeting-plugin:greet Alice`
**Output**: "Hello, Alice! 👋 Great to see you!"
**Input**: `/my-greeting-plugin:greet`
**Output**: "Hello there! 👋 How can I help you today?"
README.md
# My Greeting Plugin
A simple example plugin that demonstrates Claude Code plugin basics.
## Installation
From a marketplace:
```bash
/plugin install my-greeting-plugin@marketplace-name
Usage
/my-greeting-plugin:greet [name]
Examples
/my-greeting-plugin:greet World- Greet with a name/my-greeting-plugin:greet- Generic greeting
## Adding to a Marketplace
In your marketplace's `.claude-plugin/marketplace.json`:
```json
{
"plugins": [
{
"name": "my-greeting-plugin",
"description": "A simple greeting plugin",
"version": "1.0.0",
"author": {
"name": "Your Name"
},
"source": "./plugins/my-greeting-plugin",
"category": "examples",
"tags": ["greeting", "example"]
}
]
}
Testing Locally
- Create the plugin structure
- Create a dev marketplace:
mkdir -p dev-marketplace/.claude-plugin - Create
dev-marketplace/.claude-plugin/marketplace.json(see above) - Add marketplace:
/plugin marketplace add ./dev-marketplace - Install plugin:
/plugin install my-greeting-plugin@dev-marketplace - Test command:
/my-greeting-plugin:greet World
Key Takeaways
- Minimal structure: Only
.claude-plugin/plugin.jsonandcommands/are required - Frontmatter: Commands need
description(and optionallyargument-hint) - Namespacing: Commands are called with
/plugin-name:command-name - Arguments: Access via
$ARGUMENTSor$1,$2, etc. - Standard paths: No need to specify component fields in
plugin.jsonwhen using standard directories