SuperAPI AI Directory

claude-code-plugin

Agents & models

View repository

Updated 10-16 01:15

About this skill

Complete Guide to Claude Code Plugin

Complete guide to creating, publishing, installing, updating, and syncing Claude Code Plugins

Use Cases

  • Developing a new Claude Code Plugin
  • Publishing a Plugin to a Marketplace
  • Installing and updating Plugins
  • Managing Plugin versions
  • Syncing the latest version
  • Creating a custom Marketplace

Part 1: Plugin Architecture

Directory Structure

my-plugin/
├── .claude-plugin/
│   ├── plugin.json          # Plugin manifest(必要)
│   └── marketplace.json     # Marketplace 索引(選用)
├── commands/                # Slash 命令(在根目錄!)
│   └── my-command.md
├── skills/                  # Agent Skills
│   └── my-skill/
│       └── SKILL.md
├── hooks/
│   └── hooks.json           # Hook 配置
├── agents/                  # Subagent 定義
├── .mcp.json               # MCP 伺服器配置
├── CHANGELOG.md
└── README.md

⚠️ Important: commands/, skills/, hooks/ must be in the root directory, do not put them in .claude-plugin/

plugin.json Specification

{
  "name": "my-plugin",
  "version": "1.0.0",
  "description": "Plugin 功能描述",
  "author": {
    "name": "作者名稱",
    "email": "email@example.com"
  },
  "license": "MIT",
  "keywords": ["keyword1", "keyword2"]
}

The Four Major Components

Component Purpose Trigger Method File Format
Commands Slash commands executed by the user /command Manual Markdown
Skills Teaching Claude how to do things Automatically based on context SKILL.md
Hooks Event-driven automation Triggered by system events JSON + Shell
MCP Providing tool capabilities Called by Claude .mcp.json

Part 2: Publishing a Plugin

Method 1: GitHub Marketplace (Recommended)

Step 1: Create marketplace.json

{
  "$schema": "https://anthropic.com/claude-code/marketplace.schema.json",
  "name": "my-marketplace",
  "description": "我的 Plugin 集合",
  "owner": {
    "name": "username",
    "email": "email@example.com"
  },
  "plugins": [
    {
      "name": "my-plugin",
      "version": "1.0.0",
      "source": "./",
      "description": "Plugin 描述",
      "category": "development"
    }
  ]
}

Step 2: Push to GitHub

git add .
git commit -m "feat: add Plugin marketplace format"
git tag -a v1.0.0 -m "Release v1.0.0"
git push origin main
git push origin v1.0.0

Step 3: User Installation

# 添加 marketplace
/plugin marketplace add owner/repo

# 安裝 plugin
/plugin install my-plugin@my-marketplace

Method 2: npm Publishing

# 1. 在 package.json 中命名(加 claude-plugin- 前綴)
{
  "name": "claude-plugin-my-plugin",
  "version": "1.0.0"
}

# 2. 發布
npm publish

# 3. 用戶安裝
npm install -g claude-plugin-my-plugin

Method 3: Direct Sharing

# 用戶下載後本地安裝
/plugin install /path/to/my-plugin

Part 3: Installing Plugins

Installing from a Marketplace

# 1. 先添加 marketplace(只需一次)
/plugin marketplace add owner/repo

# 2. 列出可用 plugins
/plugin marketplace list

# 3. 安裝 plugin
/plugin install plugin-name@marketplace-name

Installing Directly from GitHub

# 完整路徑安裝
/plugin install github:owner/repo#path/to/plugin

# 範例
/plugin install github:miles990/evolve-plugin

Local Installation

# 從本地目錄安裝
/plugin install /path/to/my-plugin

Viewing Installed

# 列出所有已安裝的 plugins
/plugin list

# 查看詳細資訊
/plugin info plugin-name@marketplace

Uninstalling

# 解除安裝特定 plugin
/plugin uninstall plugin-name@marketplace

# 範例
/plugin uninstall evolve@evolve-plugin

# 強制解除安裝(忽略相依性)
/plugin uninstall plugin-name@marketplace --force

Uninstallation Notes:

  • Uninstalling does not remove the marketplace, only the installed plugin
  • If other plugins depend on this plugin, a warning will appear
  • After uninstalling, it can be reinstalled at any time

Part 4: Updating Plugins

Checking for Updates

# 檢查所有 plugins 是否有更新
/plugin update --check

# 檢查特定 plugin
/plugin update --check plugin-name@marketplace

Performing Updates

# 更新特定 plugin
/plugin update plugin-name@marketplace

# 更新所有 plugins
/plugin update --all

Automatic Version Check Process

本地版本 → 遠端版本 → 比較
    ↓           ↓
plugin.json  GitHub API / marketplace.json
    ↓
若遠端較新 → 提示用戶更新

Manual Version Check

# 取得本地版本
cat ~/.claude/plugins/installed_plugins.json | jq '.plugins["plugin@marketplace"][0].version'

# 取得遠端版本
curl -s https://raw.githubusercontent.com/owner/repo/main/.claude-plugin/plugin.json | jq -r '.version'

Part 5: Version Control

Version Locations (Must Be Synchronized)

Location Description
.claude-plugin/plugin.json Plugin manifest
.claude-plugin/marketplace.json Marketplace Index
skills/*/SKILL.md Skill Version (if applicable)
CHANGELOG.md Change Log
Git tag Release Tag

Semantic Versioning

MAJOR.MINOR.PATCH
  │     │     └── Bug fixes(修復)
  │     └── 新功能(向後相容)
  └── 破壞性變更(不相容)

Release Checklist

# 更新所有版本位置
- [ ] plugin.json → version
- [ ] marketplace.json → plugins[].version
- [ ] SKILL.md → version: (如適用)
- [ ] CHANGELOG.md → 新條目
- [ ] README.md → 版本徽章

# Git 操作
git add .
git commit -m "chore: bump version to vX.Y.Z"
git tag -a vX.Y.Z -m "Release vX.Y.Z: 描述"
git push origin main
git push origin vX.Y.Z

CHANGELOG.md Format

## [1.1.0] - 2026-01-16

### Added
- 新功能描述

### Changed
- 變更描述

### Fixed
- 修復描述

### Security
- 安全修復

Part 6: Syncing the Latest Version

Syncing from the Main repo to a Standalone Plugin repo

When the plugin was split off from the main project:

# 1. 複製 skills 目錄
cp -r /path/to/main-project/skills /path/to/plugin-repo/

# 2. 更新版本
# 編輯 plugin.json, marketplace.json

# 3. 提交並推送
cd /path/to/plugin-repo
git add -A
git commit -m "chore: sync with main-project vX.Y.Z"
git push origin main

Sync Script Example

#!/bin/bash
# sync-plugin.sh - 同步 plugin 到獨立 repo

MAIN_REPO="$1"
PLUGIN_REPO="$2"
VERSION="$3"

# 複製 skills
rm -rf "$PLUGIN_REPO/skills"
cp -r "$MAIN_REPO/skills" "$PLUGIN_REPO/"

# 更新版本
sed -i '' "s/\"version\": \".*\"/\"version\": \"$VERSION\"/" \
    "$PLUGIN_REPO/.claude-plugin/plugin.json"

# 提交
cd "$PLUGIN_REPO"
git add -A
git commit -m "chore: sync with main-project v$VERSION"
git push origin main

Automatic Sync (Using GitHub Actions)

# .github/workflows/sync-plugin.yml
name: Sync Plugin

on:
  push:
    branches: [main]
    paths:
      - 'skills/**'
      - 'evolve-plugin/**'

jobs:
  sync:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v3

      - name: Sync to plugin repo
        run: |
          # Clone plugin repo
          git clone https://github.com/owner/plugin-repo.git

          # Copy files
          cp -r skills/ plugin-repo/
          cp evolve-plugin/.claude-plugin/* plugin-repo/.claude-plugin/

          # Push
          cd plugin-repo
          git add -A
          git commit -m "chore: auto-sync from main repo"
          git push

Part 7: Marketplace Management

Creating Your Own Marketplace

Step 1: Create marketplace.json

{
  "$schema": "https://anthropic.com/claude-code/marketplace.schema.json",
  "name": "my-marketplace",
  "description": "我的 Plugin 集合",
  "owner": {
    "name": "username"
  },
  "plugins": [
    {
      "name": "plugin-a",
      "version": "1.0.0",
      "source": "./plugin-a",
      "description": "Plugin A 描述",
      "category": "development"
    },
    {
      "name": "plugin-b",
      "version": "2.0.0",
      "source": "./plugin-b",
      "description": "Plugin B 描述",
      "category": "productivity"
    }
  ]
}

Step 2: Organize the Directory Structure

my-marketplace/
├── .claude-plugin/
│   └── marketplace.json
├── plugin-a/
│   ├── .claude-plugin/
│   │   └── plugin.json
│   ├── commands/
│   └── skills/
├── plugin-b/
│   ├── .claude-plugin/
│   │   └── plugin.json
│   └── commands/
└── README.md

Managing Added Marketplaces

# 列出已添加的 marketplaces
/plugin marketplace list

# 添加新 marketplace
/plugin marketplace add owner/repo

# 移除 marketplace
/plugin marketplace remove marketplace-name

# 更新 marketplace 索引
/plugin marketplace refresh

Known Marketplaces Storage Locations

~/.claude/plugins/known_marketplaces.json

Part 8: Hooks Development

Hook Event Types

Event Timing Purpose
PreToolUse Before tool execution Block/modify tool calls
PostToolUse After tool execution Post-processing, notification
UserPromptSubmit On user input Input validation
SessionStart Session start Initialization
SessionEnd Session end Cleanup
Stop AI completes response Post-processing
SubagentStop Subagent completed Subtask processing

hooks.json configuration

{
  "hooks": [
    {
      "type": "command",
      "event": "PreToolUse",
      "command": "./hooks/protect-env.sh"
    },
    {
      "type": "command",
      "event": "PostToolUse",
      "command": "./hooks/format-code.sh"
    },
    {
      "type": "command",
      "event": "SessionStart",
      "command": "./hooks/init.sh"
    }
  ]
}

Example Hook: Protect sensitive files

#!/bin/bash
# hooks/protect-env.sh

FILE_PATH=$(echo "$1" | jq -r '.tool.input.path // .tool.input.file_path // empty')

if [[ "$FILE_PATH" =~ \.(env|key|secret|credentials)$ ]]; then
    echo '{"decision": "block", "reason": "Protected file type"}' >&2
    exit 1
fi

exit 0

Example Hook: Auto-format

#!/bin/bash
# hooks/format-code.sh

FILE_PATH=$(echo "$1" | jq -r '.tool.input.path // empty')

if [[ "$FILE_PATH" =~ \.(ts|tsx|js|jsx)$ ]]; then
    prettier --write "$FILE_PATH" 2>/dev/null
fi

exit 0

Part 9: Common Errors and Solutions

Sharp Edges

SE-1: Incorrect directory structure

  • Severity: critical
  • Symptom: /plugin list Shows plugin but command does not exist
  • Cause: commands/, skills/ placed under the .claude-plugin/ directory
  • Solution: Move all component directories to the plugin root directory

SE-2: Version out of sync

  • Severity: high
  • Symptom: /plugin list does not match CHANGELOG version
  • Cause: plugin.json and marketplace.json versions are inconsistent
  • Solution: Create a release checklist and check all locations every time

SE-3: Hook permissions too high

  • Severity: high
  • Symptom: Unexpected file changes, data loss
  • Cause: Hook runs with user permissions, scope is too broad
  • Solution: Precisely specify Hook targets and add safety checks

SE-4: MCP Prompt Injection

  • Severity: critical
  • Symptom: Claude performs unexpected operations
  • Cause: MCP retrieves content from untrusted sources
  • Solution: Only use MCP from trusted sources

Common Errors Comparison Table

Error Correct Approach
Place commands/ in .claude-plugin/ Place in the plugin root directory
Version numbers inconsistent Update all locations in sync
Hook scope too broad Precisely specify target tool
Forgetting git tag Tag on every release
Deploy directly without testing Test with --plugin-dir first

Part 10: Local Testing

# 測試 plugin(不安裝)
claude-code --plugin-dir /path/to/my-plugin

# 驗證結構
tree /path/to/my-plugin

# 檢查 plugin.json 語法
cat /path/to/my-plugin/.claude-plugin/plugin.json | jq .

# 驗證 hooks
cat /path/to/my-plugin/hooks/hooks.json | jq .

Official Documentation

Further Resources