From rcc
Refactors agent systems post-creation or modification: loads review findings, prioritizes issues, executes fixes, verifies changes, and generates reports. Activates on 'review agent system' or similar phrases.
npx claudepluginhub wayne930242/reflexive-claude-codeThis skill uses the workspace's default tool permissions.
**Refactoring agent systems IS applying clean code principles to agent configurations.**
Audits Claude Code agents for violations, gaps, and improvements across 7 dimensions like description quality and frontmatter, outputting structured repair plans.
Reviews Claude agent system components including CLAUDE.md, skills, rules, hooks, and subagents by collecting inventory, invoking dedicated reviewer agents, generating reports, and awaiting user confirmation.
Provides AI agent design consulting and reviews Skills/workflows against 12-Factor AgentOps best practices for reliability, quality, learning, and scaling.
Share bugs, ideas, or general feedback.
Refactoring agent systems IS applying clean code principles to agent configurations.
Re-analyze after changes, compare before/after, fix remaining issues, simplify over-engineering.
Core principle: Refactoring without measurement is guessing. Analyze, then change, then verify.
Violating the letter of the rules is violating the spirit of the rules.
Pattern: Skill Steps Handoff: none Next: none Chain: main (terminal)
Before ANY action, create task list using TaskCreate:
TaskCreate for EACH task below:
- Subject: "[refactoring-agent-systems] Task N: <action>"
- ActiveForm: "<doing action>"
Tasks:
Announce: "Created 5 tasks. Starting execution..."
Execution rules:
TaskUpdate status="in_progress" BEFORE starting each taskTaskUpdate status="completed" ONLY after verification passesTaskList to confirm all completedGoal: Load the review report as the basis for refactoring.
If review report path was provided (from reviewing-agent-systems):
If no review report (standalone invocation):
reviewing-agent-systems skill first to produce a reportVerification: Have a list of specific issues to fix from the review report.
Goal: Classify and order issues from the review report for fixing.
Priority order:
Present the prioritized list to user. Do NOT summarize — show each issue with its component, severity, and planned fix.
Ask: "這些修正項目正確嗎?要開始修正嗎?"
Verification: User has confirmed the prioritized fix list.
Goal: Fix remaining and new issues.
Refactoring actions (in priority order):
| Issue Type | Action | Method |
|---|---|---|
| Duplicate logic across components | Merge or extract to rule | Main conversation edits |
| Conflicting instructions | Unify or remove one | Main conversation edits |
| Over-engineered component | Simplify (YAGNI) | Main conversation edits |
| Weak skill trigger | Improve description | Main conversation edits |
| Missing isolation | Add context: fork to agent | Main conversation edits |
| CLAUDE.md too long | Move content to rules/skills | Main conversation edits |
CRITICAL: All edits happen in main conversation. Never delegate refactoring writes to subagents.
For each refactoring action:
Verification: All REMAINING and NEW issues addressed.
Goal: Confirm no critical issues remain.
Re-run the relevant reviewer agents on components that were modified in Task 3.
Pass criteria:
If critical issues remain: Return to Task 3 and fix.
Verification: All modified components pass their reviewer.
Goal: Document what was changed and why.
Write to: docs/agent-system/{timestamp}-refactoring-report.md
Report format:
# Agent System Refactoring Report
**Date:** YYYY-MM-DD HH:MM
## Changes Made
| # | Component | Change | Rationale |
|---|-----------|--------|-----------|
## Before/After Comparison
| Metric | Before | After |
|--------|--------|-------|
| Components | N | N |
| Critical issues | N | 0 |
| Warnings | N | N |
| Total lines (CLAUDE.md) | N | N |
## Remaining Items (INFO)
- [Low priority items for future consideration]
Verification: Report accurately reflects all changes.
These thoughts mean you're rationalizing. STOP and reconsider:
All of these mean: You're about to leave mess behind. Follow the process.
| Excuse | Reality |
|---|---|
| "Skip re-analysis" | Building introduces new issues. Always re-analyze. |
| "Skip comparison" | Without before/after, you can't prove improvement. |
| "Subagent edits" | Subagents can't write to .claude/. Use main conversation. |
| "Skip verification" | Refactoring can break things. Verify. |
| "Skip report" | Report documents decisions for future maintainers. |
digraph refactor_agent {
rankdir=TB;
start [label="Refactor agent\nsystem", shape=doublecircle];
analyze [label="Task 1: Load\nreview findings", shape=box];
compare [label="Task 2: Prioritize\nissues", shape=box];
refactor [label="Task 3: Execute\nrefactoring", shape=box];
verify [label="Task 4: Final\nverification", shape=box];
clean [label="Zero\ncritical?", shape=diamond];
report [label="Task 5: Produce\nreport", shape=box];
done [label="Refactoring complete", shape=doublecircle];
start -> analyze;
analyze -> compare;
compare -> refactor;
refactor -> verify;
verify -> clean;
clean -> report [label="yes"];
clean -> refactor [label="no\nfix more"];
report -> done;
}