Agent skill
refactoring-plugins
Use when refactoring, migrating, or auditing a Claude Code plugin package. Use when user says "refactor plugin", "audit plugin", "plugin health check", "migrate plugin structure". Use when plugin structure drifts from official best practices.
Install this agent skill to your Project
npx add-skill https://github.com/wayne930242/Reflexive-Claude-Code/tree/main/plugins/rcc/skills/refactoring-plugins
SKILL.md
Refactoring Plugins
Overview
Refactoring plugins IS aligning plugin structure with official Claude Code best practices.
Run health checks, detect structural drift, fix anti-patterns, and verify the result. Plugins differ from agent systems — they have an official schema (plugin.json), auto-discovery conventions, and distribution requirements.
Core principle: A plugin that fails health check will fail in production. Measure first, then fix.
Violating the letter of the rules is violating the spirit of the rules.
Task Initialization (MANDATORY)
Before ANY action, create task list using TaskCreate:
TaskCreate for EACH task below:
- Subject: "[refactoring-plugins] Task N: <action>"
- ActiveForm: "<doing action>"
Tasks:
- Identify plugin target
- Run health check
- Analyze findings against checklist
- Present refactoring plan
- Execute refactoring
- Verify fixes
Announce: "Created 6 tasks. Starting execution..."
Execution rules:
TaskUpdate status="in_progress"BEFORE starting each taskTaskUpdate status="completed"ONLY after verification passes- If task fails → stay in_progress, diagnose, retry
- NEVER skip to next task until current is completed
- At end,
TaskListto confirm all completed
Task 1: Identify Plugin Target
Goal: Locate the plugin to refactor.
Discovery order:
- User provided a path → use it
- Current directory has
.claude-plugin/plugin.json→ use it - Search for
*/.claude-plugin/plugin.jsonin working directory - Ask user to specify
Record:
- Plugin root path
- Plugin name (from plugin.json or directory name)
- Whether a marketplace.json exists upstream
Verification: Have a valid plugin directory with .claude-plugin/plugin.json.
Task 2: Run Health Check
Goal: Execute the automated health check script.
Step 1 — Official CLI validation (if available):
claude plugin validate <plugin-path>
Step 2 — Extended health check script:
uv run scripts/validate_plugin.py <plugin-path>
# or: python3 scripts/validate_plugin.py <plugin-path>
The script integrates claude plugin validate automatically and adds extended checks:
- Manifest integrity (JSON syntax, required fields, naming, semver)
- Directory structure (components at root, not inside
.claude-plugin/) - Skills quality (frontmatter, gerund naming, line count, mandatory sections, trigger overlap)
- Commands and agents validation
- Path safety (no absolute paths)
- Version sync with marketplace.json
Capture output: Save results for analysis in Task 3.
Verification: Health check completed with error/warning counts.
Task 3: Analyze Findings Against Checklist
Goal: Deep analysis beyond the automated script.
CRITICAL: Read references/plugin-health-checklist.md for the full checklist.
The script catches structural issues. Manual analysis catches:
- Skill trigger overlaps
- Cross-component duplication
- Distribution readiness problems
- README documentation gaps
- Hook safety concerns
For each finding, record:
- Category (from checklist)
- Severity: CRITICAL / WARNING / INFO
- Component affected
- Specific issue
- Suggested fix
Verification: All 8 checklist categories evaluated.
Task 4: Present Refactoring Plan
Goal: Show user the full findings and planned fixes.
Present ALL findings with detail. Do NOT summarize:
- Health check script output (errors and warnings)
- Manual analysis findings by severity
- Planned fix for each issue
Format:
| # | Severity | Category | Component | Issue | Planned Fix |
|---|
Ask: "以上是插件健康檢查結果,要開始修正嗎?"
Verification: User has confirmed the refactoring plan.
Task 5: Execute Refactoring
Goal: Fix all confirmed issues.
CRITICAL: Read references/plugin-structure-rules.md for official rules and execution order.
CRITICAL: All edits in main conversation. Never delegate writes to subagents.
Verification: Each fix applied and individually verified.
Task 6: Verify Fixes
Goal: Re-run health check to confirm all issues resolved.
Process:
- Re-run
validate_plugin.pyon the refactored plugin - Verify zero CRITICAL errors
- Verify all WARNING items from Task 3 are resolved
- Check no new issues introduced
If issues remain: Return to Task 5 and fix.
Produce final report:
# Plugin Refactoring Report
**Date:** YYYY-MM-DD HH:MM
**Plugin:** [name]
## Changes Made
| # | Component | Change | Rationale |
|---|-----------|--------|-----------|
## Health Check Results
| Metric | Before | After |
|--------|--------|-------|
| Errors | N | 0 |
| Warnings | N | N |
| Skills | N | N |
| Commands | N | N |
| Agents | N | N |
Verification: Health check passes with zero errors.
Red Flags - STOP
These thoughts mean you're rationalizing. STOP and reconsider:
- "Skip the health check script, I can see the issues"
- "The structure looks fine, skip the checklist"
- "Fix it directly without showing the user"
- "Skip re-verification, I just fixed it"
- "This plugin is simple, skip manual analysis"
- "Move components without checking references"
All of these mean: You're about to leave a broken plugin. Follow the process.
Common Rationalizations
| Excuse | Reality |
|---|---|
| "Skip health check" | Scripts catch what eyes miss. Always run it. |
| "Structure looks fine" | Anti-patterns hide in config files. Check all 8 categories. |
| "Fix without showing" | User must confirm before structural changes. |
| "Skip re-verification" | Fixes can break other things. Re-run the script. |
| "Simple plugin" | Simple plugins still need valid manifests and naming. |
| "I know the official structure" | Official structure evolves. Verify against the checklist. |
Flowchart: Plugin Refactoring
digraph refactor_plugin {
rankdir=TB;
start [label="Refactor\nplugin", shape=doublecircle];
identify [label="Task 1: Identify\nplugin target", shape=box];
health [label="Task 2: Run\nhealth check", shape=box];
analyze [label="Task 3: Analyze\nfindings", shape=box];
present [label="Task 4: Present\nrefactoring plan", shape=box];
confirm [label="User\nconfirms?", shape=diamond];
execute [label="Task 5: Execute\nrefactoring", shape=box];
verify [label="Task 6: Verify\nfixes", shape=box];
pass [label="Zero\nerrors?", shape=diamond];
done [label="Refactoring\ncomplete", shape=doublecircle];
start -> identify;
identify -> health;
health -> analyze;
analyze -> present;
present -> confirm;
confirm -> execute [label="yes"];
confirm -> done [label="no"];
execute -> verify;
verify -> pass;
pass -> done [label="yes"];
pass -> execute [label="no\nfix more"];
}
References
- references/plugin-health-checklist.md — Full 8-category plugin health checklist
- Health check script:
scripts/validate_plugin.py(cross-platform, supportsuv run)
Didn't find tool you were looking for?