refactor
Refactor existing code without changing behavior. Use when the user wants to improve readability, modularity, performance, type safety, or reduce duplication.
适合你,如果经常需要改善代码结构而不改变功能
/ 通过 npx 安装 校验哈希
npx oh-my-skill add hawkyre/hawk-skills/refactor/ 通过 bash 安装
curl -fsSL https://oh-my-skill.com/install.sh | bash -s -- hawkyre/hawk-skills/refactor/ 已经装过?验证本机副本,不用重装
npx oh-my-skill verify hawkyre/hawk-skills/refactor安装目标可用 --agent / --scope 或 --to 明确指定;省略时只会在唯一已存在的 agent 目录上自动选择,零命中或多命中会停止并提示。content_hash 缺失或不一致均拒装。
28GitHub stars
~473上下文体积 · 单文件
索引托管
怎么用
商店整理自技能原文 · 版本 6ffb2d6 · 表述以原文为准它做什么
当您要求重构代码时,Claude 会遵循一个严谨流程:先确认重构目标和不变项(如行为、API),然后逐步修改,每步确保测试通过,最后验证没有改变外部行为。它一次只改进一个方面,比如可读性或性能。
什么时候触发
当您想改进代码的可读性、模块化、性能、类型安全或减少重复时,可以直接提出重构要求。Claude 会在您给出具体代码后启动重构过程。
装好后可以这样说
Claude 会按可读性维度重构
Claude 会专注于性能维度
Claude 会执行去重维度
技能原文 SKILL.md
Refactor Code
Process
- Confirm the constraint (ask if not provided):
- Invariant: what must NOT change (behavior, API, tests passing)
- Dimension (pick ONE):
- Readability (clearer naming, simpler control flow)
- Modularity (break apart, extract, separate concerns)
- Performance (reduce allocations, optimize hot paths)
- Type safety (tighten types, eliminate
any, add guards) - Deduplication (consolidate repeated patterns)
- Context: why this refactor, what pain it solves
Always pick ONE dimension. Multi-axis refactors produce unreadable diffs and are impossible to review.
- Load context:
- Read relevant standards from
.agents/standards/ - Read relevant common-mistakes from
.agents/common-mistakes/
- Outline the plan:
- Specific transformations to apply
- Order (each step leaves the check command passing)
- What the code will look like after (brief description, not full code)
- Risks or tricky parts
- Execute incrementally: One step at a time. Confirm tests pass between steps. If something breaks, roll back one step, not the whole refactor.
- Verify the invariant:
- Run the project's check command
- Diff the public API/interface — confirm nothing changed externally
- List any behavioral differences (there should be zero)
Rules
- ALWAYS constrain to ONE dimension. Multi-axis refactors produce unreadable diffs.
- Each step must leave tests passing
- A refactor diff should be "boring" — moves, renames, restructures. No logic changes.
- If you discover a bug during refactoring, note it for a separate fix PR. Never mix refactoring and bug fixes.
- Check
.agents/common-mistakes/for relevant patterns before and after - Big-output discipline. Heavy command output (project check, full
git diff, repo-wide search, long log, large fetch) goes to/tmp/hawk-<skill>-<step>.log, thenrg -n '<pattern>' /tmp/hawk-<skill>-<step>.log | head -50extracts what you need.Readthe file only withoffset/limit. See README → Big-output discipline.
按 MIT 许可原样转载,未经改动 · 在 GitHub 查看 →
评论
登录即可评论;带「已验证安装」的,是发布者名下有本店的安装或持有记录。
…