safe-refactor

safe-refactor is a skill for Claude Code, Codex from hxy91819/mason-skills. It costs 31 tokens per session (2,352 once invoked), scanned A, original, MIT.

A guided process for making code changes smaller without changing its observable behaviour. It can also review an existing refactor by examining the actual code difference and the evidence that behaviour was preserved.

In plain words
What is it for?
Use it for shared-component changes, data-access fixes such as removing repeated database queries, asynchronous rewrites, cross-language replacements, or review of a refactor someone else already made.
Why use it?
Refactoring can accidentally change what a program does or grow beyond its original goal. This process sets a boundary, records a baseline, checks callers and tests, and leaves gaps or risks visible instead of claiming the change is safe for production.

Skill for Claude CodeCodex

Written for Claude Code and Codex: disable-model-invocation in frontmatter, but also agents/openai.yaml present. Also seen: mentions subagents; $skill-name invocation.

Good fit Use it for shared-component changes, data-access fixes such as removing repeated database queries, asynchronous rewrites, cross-language replacements, or review of a refactor someone else already made.

Compare 6 skills from other repositories ↓
Install with agentmods
npx agentmods add skills/hxy91819/mason-skills/safe-refactor
Install

Getting it into your agent

One page per mod, every tool's command on it. A separate URL per tool would split the same page into five that compete with each other.

Any agent
npx skills add hxy91819/mason-skills --skill safe-refactor
Clone the repo
git clone --depth 1 https://github.com/hxy91819/mason-skills

Made for: Claude Code, Codex.

Wrote this? Show the measurements

A badge with what this costs and how it scanned, read live from this page, so it follows the numbers instead of freezing them. Markdown for a README, HTML for a documentation site or a project page.

agentmods badge for safe-refactor

README.md
[![agentmods](https://agentmods.dev/badge/skills/hxy91819/mason-skills/safe-refactor/github.svg)](https://agentmods.dev/skills/hxy91819/mason-skills/safe-refactor)
Your own site
<a href="https://agentmods.dev/skills/hxy91819/mason-skills/safe-refactor"><img src="https://agentmods.dev/badge/skills/hxy91819/mason-skills/safe-refactor/github.svg" alt="Measured on agentmods" height="20"></a>

Or the 80×15 button, for a site that already has a row of RSS and ATOM ones. Only the verdict fits; the numbers stay here.

agentmods 80×15 button for safe-refactor

Your own site · 80×15
<a href="https://agentmods.dev/skills/hxy91819/mason-skills/safe-refactor"><img src="https://agentmods.dev/badge/skills/hxy91819/mason-skills/safe-refactor.svg" alt="Reviewed on agentmods" width="80" height="20"></a>
Per session 31 Skills are progressive disclosure: only the name and description are preloaded; the body loads when the skill is used.
When invoked 2,352 The whole file, excluding the scripts and references it only reads on demand.
Security scan A 0 findings. A grade says what 26 rules found in the file — not that it is safe.
Origin original No closer match found in the catalogue.
Token cost

What it costs to keep this loaded

Counted locally with the o200k_base tokenizer, which is exact for GPT models; Claude uses its own tokenizer and its counts differ. Treat this as one consistent yardstick across the catalogue rather than a bill. Prices are per million input tokens.

ModelPer sessionOnce invoked
Fable 5.1 $0.00031 $0.02352
Opus 5.5 $0.00012 $0.00941
Sonnet 5.5 $0.00006 $0.00470
Haiku 4.5 $0.00003 $0.00235

Measured 29d ago against content hash 88b6ca6d4e63, method: parsed. Prices are Anthropic first-party input rates as of 2026-10-07, from the pricing page.

Security

Grade A, and why

safe-refactor scanned grade A with 0 findings against 26 rules in 11 categories — prompt injection, anti-refusal, data exfiltration, privilege escalation, supply chain, agent snooping, system-prompt leakage, SSRF and excessive agency — measured 29d ago.

The scan reads SKILL.md. This mod also ships 15 executable files (examples/n-plus-one/candidate/api.py, examples/n-plus-one/candidate/batch.py, examples/n-plus-one/fixture/benchmark.py, …), listed below but not scanned — reading those needs a real analyzer, not pattern matching.

A static scan of the body, not an audit. Every finding is printed with the line that produced it so you can judge whether it matters here. A mod is markdown that instructs an agent; that is exactly why what it instructs is worth reading.

Nothing flagged

None of the 26 patterns this scan looks for appear in this file: no shell pipes, no recursive deletes, no credential paths, no hidden text, no instruction-override or anti-refusal phrasing, no agent-config snooping. That is not a guarantee, it is the absence of the things that are checkable.

common-skills/safe-refactor/SKILL.md · 126 lines

How it starts

The opening of the file, as written. The whole thing — 126 lines — stays where its author put it; the contents beside it link to each section on GitHub.

Safe Refactor:先圈边界,再改代码

这是流程类 Skill,仅在用户显式调用 $safe-refactor 时运行。完整流程把重构推进到“具备进入发布流程的证据”;只做 review 时停在审查结论。不负责宣布生产安全,也不自动推送、合并、部署。

适合共享组件、数据访问(如 N+1)、异步化、跨语言替换,或审查/接手一份没有事前验证的重构 diff。小范围纯函数整理只需按下文“小任务”走轻量路径。

入口与模式

接受自然语言目标;不要求用户填写整份表。先读仓库说明、当前分支、已有任务单、测试与发布约定,能查到的信息不反复询问。

请求 模式 读取
新的重构目标 完整流程(下文 1–7) 全部阶段按到达时读取
“只分析影响面” plan 或 actual 影响分析,不改生产代码 change-impact.md
“只补基线/测试” 行为基线 behavior-baseline.md
“重构已完成,只做 review” 事后审查实际 diff 和现有证据,不继续实现 verify.md 的事后 review 分支
协调者派来的独立验收,或明确要求正式证据门禁 verify,不改生产代码 verify.md 的正式验收分支
已有 diff,要求继续重构或补齐事前基线 下文“接手并继续已有改动” —
继续任务 读取工作单及当前 Git 状态,先检查版本和证据是否仍匹配 —

所有模式先读 共享规则。完整流程和接手实施用 工作单 持久化状态;仅做事后 review 可直接使用现有材料。运行脚本时读 工具说明。

用户只要求 review 时,优先按其指定的旧版和候选版划界;未指定则从当前分支、Git 历史及未提交改动确定实际范围,并说明候选是固定提交还是工作区状态。只报告发现的问题、验证结果和证据缺口,不补写“事前”批准或进入下文实施步骤。

手动调用示例:$safe-refactor 只做 review:审查当前分支相对 main 的已完成重构,包含未提交改动;检查行为变化、调用方和现有测试,不修改代码。

1. 收敛任务

记录一句话目标、可观察的收益标准、不做什么、原始版本 origin_revision、当前候选版本、环境限制和授权边界。不要把重构顺便升级为改需求、修全部历史 bug 或重写技术栈。

性能优化先确认瓶颈证据;结构重构也要有可验收收益,例如依赖方向、重复规则数量、模块公开面,而不只是“代码更漂亮”。没有足够收益时推荐不改或缩减目标。

默认最多两轮局部修复、一轮重新规划;这是可调整默认值,不是最佳次数的事实判断。沿用用户或项目已有预算;不得自行续费式增加预算。耗尽则保留工作并报告下一项决策。

2. 影响面分析(plan)

按 change-impact.md 的 plan 模式,基于目标、原始版本、现有改动和约束给出最小可验证方案。

必须得到:改动的语义、受影响业务入口与资源、必要契约、未知项、推荐策略、允许/保护路径、最小验证集。不要把路径清单当语义影响的完整证明。

将方案写入 policy.json 和工作单。范围由用户明确授权或项目已有可信策略批准;低风险、已授权范围内可自动继续,不必每个文件都问一次。共享语义扩大、删除数据、改变权限、改变需求、放宽验收或超预算,需要明确的新决策。

3. 行为基线

按 behavior-baseline.md 在旧生产实现上建立测试,不先改实现再反推答案。

测试准备可能需要一个仅增加测试/夹具的提交:

  • origin_revision:开始任务时的旧代码。
  • base_revision:测试基线准备完成后的固定提交,生产行为仍是旧的。
  • 对这两版的差异单独审查;基线准备若必须改变生产代码,拆成有证据的小步骤,不偷偷夹带。

记录契约、断言依据、基线执行、针对关键规则的红控结果。性能目标的旧版测量与业务回归分开。

基线就绪后,冻结 policy.json 的批准摘要及 seal.json;冻结的是受保护的断言/夹具/规范边界,不是整个测试仓库。没有实际执行能力时标记 INSUFFICIENT,不能宣称基线已建立。

Read the full file on GitHub · 126 lines

Files

What ships with it

36 files beside SKILL.md in the same directory: the scripts, references and assets a skill reads on demand. Not counted in the per-session cost; read them before you install if any of them is executable.

Changes

What this file has done since we first saw it

Hashed on every crawl. A supply-chain change to an agent config is a question of when, not whether, so the history is kept rather than the latest state alone.

  1. 29d ago First seen · 126 lines · 31 tokens per session scan A 88b6ca6d4e63

Subscribe to this mod's changes

safe-refactor is a skill published in the GitHub repository hxy91819/mason-skills (3 stars, last pushed yesterday), licensed MIT. It adds 31 tokens to every session and 2,352 once invoked, about $0.0001 per session on Opus 5.5. A static security scan graded it A with 0 findings. No closer match exists in the catalogue, so it is treated as the original; first seen 2026-09-27.

Related

Other skills, from other repositories

adk-go-self-review

Review an ADK Go change the way a maintainer will — a fresh-context pass over the whole diff, five lenses (correctness and tests, scope, simplicity, style, adk-python parity), and the mutation check that proves your tests pin the change. Use before opening a PR, before any later push that changes code, and when asked…

google/adk-go · 87 tokens

adversarial-reviewer

Stress-test a code change for concrete correctness defects, unsafe assumptions, and failure modes. Use when the user explicitly asks for an adversarial review, a deep bug hunt, or to tear a change apart, or to check your own change before submitting it. Do not use for ordinary review, style feedback, or general…

emdash-cms/emdash · 72 tokens

go-testing

Trigger: Go tests, go test coverage, Bubbletea teatest, golden files. Apply focused Go testing patterns.

Gentleman-Programming/gentle-ai · 26 tokens

semgrep-rule-variant-creator

Creates language variants of existing Semgrep rules. Use when porting a Semgrep rule to specified target languages. Takes an existing rule and target languages as input, produces independent rule+test directories for each language.

waybarrios/opencode-power-pack · 50 tokens

brooks-sweep

Full-sweep mode: runs a unified analysis across all quality dimensions — code decay, architecture, tech debt, and test quality — then applies fixes directly to the codebase. Safe changes are auto-applied; risky changes are confirmed before execution. Drawing on twelve classic engineering books. Triggers when: user…

hyhmrright/brooks-lint · 178 tokens

plugin-review

Review plugin quality with tiered checks and dependency scoping. Use for PR and pre-release audits.

athola/claude-night-market · 23 tokens