refactor
Behavior-preserving restructuring of code that is NOT in your current diff — extract modules, rename across files, untangle abstractions, pay down tech debt. For tightening just-changed code use `/zero-tech-debt` instead. Triggers "refactor X", "reorganize this module", "restructure", "extract Y from Z", "pay down tech debt".
适合你,如果希望在不改变行为的前提下改善代码结构
npx oh-my-skill add darkroomengineering/cc-settings/refactorcurl -fsSL https://oh-my-skill.com/install.sh | bash -s -- darkroomengineering/cc-settings/refactornpx oh-my-skill verify darkroomengineering/cc-settings/refactor怎么用
商店整理自技能原文 · 版本 fa04efc · 表述以原文为准当你要求重构代码时,Claude会自动协调多个子助手完成分析、规划、实现、测试和审查,最终输出一份包含变更内容、文件列表、测试结果和改进建议的摘要。
当你提到“重构”、“重组”、“提取”等代码重构关键词,且操作的不是你当前正在编辑的代码时触发。
技能原文 SKILL.md
Refactoring Workflow
Before starting work, create a marker: mkdir -p ~/.claude/tmp && echo "refactor" > ~/.claude/tmp/heavy-skill-active && date -u +"%Y-%m-%dT%H:%M:%SZ" >> ~/.claude/tmp/heavy-skill-active
You are in Maestro orchestration mode. Delegate immediately.
Workflow
- Explore - Spawn
exploreagent to analyze current code - Plan - Spawn
planneragent to design refactoring approach - Implement - Spawn
implementeragent to refactor - Test - Spawn
testeragent to verify behavior unchanged - Review - Spawn
revieweragent to check quality - Learn - Store patterns discovered during refactoring
Agent Delegation
Spawn explore and planner first — they accept thin prompts because they discover what they need from the codebase:
Agent(explore, "Analyze the code to refactor: $ARGUMENTS. Identify patterns, issues, dependencies.") Agent(planner, "Design refactoring approach based on analysis. Keep behavior unchanged.")
Then assemble the implementer prompt from the actual planner output. Implementer runs in an isolated worktree with no access to prior agent results, so paste the real plan — not "according to plan":
- The user's refactor target (
$ARGUMENTS) verbatim - The planner's step-by-step plan, including file paths and each move/rename/extract operation
- Any "preserve behavior" invariants the planner called out
- The test command that must remain green
- Scope: "only the files in the plan; do not touch anything else"
Now spawn:
Agent(implementer, "<the assembled briefing above — all five items inline>") Agent(tester, "Verify refactored code behaves identically to original.") Agent(reviewer, "Review refactoring for quality and completeness.")
Refactors are a top source of subtle regressions — behavior that "shouldn't change" quietly does. When the Codex bridge is available, run a cross-model review in parallel with the reviewer:
Agent(codex-verifier, "Cross-model review of the refactor diff. Confirm behavior is preserved; report findings by severity.")
The bridge is gated and fails open: if Codex is unavailable, the reviewer agent alone is fine.
If the codex-verifier spawn fails, or it reports that Bash was stripped (forked skill contexts), run bun "$HOME/.claude/src/scripts/codex-run.ts" review directly instead — never skip the cross-model pass.
Output
Return a summary:
- What changed: Brief description
- Files modified: List of files
- Tests passing: Verification status
- Improvements: What's better now
- Learnings: Patterns worth remembering