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.
npx skills add danhuaxiansheng/claude-code-cleanup-skills --skill necessary-code-auditgit clone --depth 1 https://github.com/danhuaxiansheng/claude-code-cleanup-skillsWrote 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.
[](https://agentmods.dev/skills/danhuaxiansheng/claude-code-cleanup-skills/necessary-code-audit)<a href="https://agentmods.dev/skills/danhuaxiansheng/claude-code-cleanup-skills/necessary-code-audit"><img src="https://agentmods.dev/badge/skills/danhuaxiansheng/claude-code-cleanup-skills/necessary-code-audit/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.
<a href="https://agentmods.dev/skills/danhuaxiansheng/claude-code-cleanup-skills/necessary-code-audit"><img src="https://agentmods.dev/badge/skills/danhuaxiansheng/claude-code-cleanup-skills/necessary-code-audit.svg" alt="Reviewed on agentmods" width="80" height="20"></a>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.
| Model | Per session | Once invoked |
|---|---|---|
| Fable 5.1 | $0.00119 | $0.02348 |
| Opus 5 | $0.00060 | $0.01174 |
| Sonnet 5 | $0.00024 | $0.00470 |
| Haiku 4.5 | $0.00012 | $0.00235 |
Grade A, and why
necessary-code-audit 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 10d ago.
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.
How it starts
The opening of the file, as written. The whole thing — 165 lines — stays where its author put it; the contents beside it link to each section on GitHub.
必要性代码审计
原则
优化目标是“当前是否必要”,不只是“是否零引用”。一个符号即使仍有调用,也可能只是包装层、兼容面、防御分支、陈旧公共 API 或假设性的扩展点。
核心问题是:这个代码被用了,但当前代码真的还需要它吗?
不要删除真实运行约束。必须保留代表加载、空数据、错误、权限、生命周期、浏览器、SSR、配额、外部输入或领域可空状态的分支。
不要把普通注释当作清理目标。只有注释已经过期、错误、误导,或因为代码删除而孤立时,才删除或改写注释。
不要在发现第一个明显清理点后停止。对于用户指定的目录或功能,必须先审完整个作用域,再报告“没有更多”或要求用户继续。
技能协作
本技能是三个清理技能的主入口:
- 用
necessary-code-audit判断“已被使用的代码是否仍然必要”。 - 用
unused-code-audit证明删除候选是否仍有消费者。 - 目标涉及页面状态、查询/变更流、权限、错误或用户可见行为时,用
page-flow-cleanup-audit。
不依赖仓库专属图工具。优先使用当前环境可用的文件列表、语言工具、构建/类型检查、manifest、导入图和文本搜索。
边界
本技能只回答“即使有人在用,这个抽象/行为/API 是否仍然必要?”。
适合本技能:
- 有调用方的 wrapper、facade、兼容别名、默认值、fallback、可选字段或配置。
- 多处调用但调用方可以直接使用更基础 primitive 的 helper。
- 公共 API 仍被 import,但只是历史兼容面或陈旧入口。
- 防御分支、try/catch、可选链、
as any或旧格式兼容是否代表真实约束。 - 两份 source of truth、重复 cache/store/query/派生计算是否需要合并。
不适合本技能单独完成:
- 只想证明某文件、导出或类型是否零消费者;改用
unused-code-audit。 - 删除没有调用方的死代码;先用
unused-code-audit完成消费者证明。 - 页面状态、权限、查询/变更链路或用户可见流程清理;改用
page-flow-cleanup-audit。
协作规则:
- 若候选看起来零消费者,暂停必要性判断,转为
unused-code-audit的删除证明。 - 若候选仍有消费者,再继续判断是否必要、是否能替换调用方、是否应收缩公共面。
unused-code-audit的结论只能说明“能否安全删除未使用项”,不能替代本技能对“已使用但不必要”的判断。
基线
开始时必须收集:
git status --short --untracked-files=allgit diff --name-status -- <scope>git diff --cached --name-status -- <scope>- 目标作用域文件清单,优先用
rg --files <scope>。 - 当前导入、导出、公共入口和直接消费者。
- 作用域符号清单:导出的函数/类型/常量、非导出 helper、配置字段和重复字面量。
- 影响面图:同包消费者、包入口、直接 app/package import,以及 manifest 中的下游包。
不要假设 staged 或 dirty 变更是自己造成的。不要回滚无关变更。
深度门槛
编辑前和完成前都必须完成这些检查:
- 盘点作用域内每个文件和有意义的导出/helper,而不是只看用户最先提到的文件。
- 将候选分成“零消费者候选”和“有消费者但可能不必要候选”;零消费者候选交给
unused-code-audit证明。 - 对有消费者的候选,至少检查每个消费区域的一个代表调用点,再判断抽象是否必要。
- 对可替换候选,确认调用方能否直接使用现有 primitive,以及替换后会孤立哪些 export/helper/type。
- 对公共 API 变更,确认 package exports 以及能覆盖变更面的下游包/app typecheck。
- 每批清理后重新搜索残留名称、旧 import path、重复字面量和新孤立 helper。
- 只有剩余候选都已归类为真实约束、刻意保留的公共 API,或超出当前请求风险范围时,才停止。
如果这些检查发现更多工作,要在同一轮继续处理。不要要求用户说“继续深度检查”才推进。
候选分类
对目标作用域中的每个有意义文件、导出、方法、字段、选项、fallback 和分支分类:
当前必要:当前产品行为或平台/运行时约束需要。可直接替代:调用方可以直接使用底层 primitive 的 wrapper/facade。兼容面:为外部或历史消费者保留的旧导出、可选字段、默认值、别名、工厂、配置或公共类型。防御分支:try/catch、fallback、可选链、空值保护、特性检测或脏数据处理。假设性能力:没有当前调用方,或只有假想未来价值的 API 面。重复来源:第二份 cache、store、query、invalidation 路径、状态源或派生计算。疑似死代码:看起来没有真实消费者;不要在本技能内直接删除,转交unused-code-audit证明。真实约束:SSR、浏览器存储可用性、配额、权限、加载/错误/空态生命周期、外部输入或合法领域可空状态。仅文档:注释或文档。除非过期、误导或被代码变更孤立,否则保留。
What ships with it
1 file 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.
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.
- 10d ago First seen · 165 lines · 119 tokens per session scan A f3d1490cad62
necessary-code-audit is a skill published in the GitHub repository danhuaxiansheng/claude-code-cleanup-skills (2 stars, last pushed 2mo ago), licensed MIT. It adds 119 tokens to every session and 2,348 once invoked, about $0.0006 per session on Opus 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-08-31.
Other skills, from other repositories
ship-it-or-fix-it
Oracle-frozen Builder and independent-Judge convergence cycle. Load ONLY when the operator explicitly sets Governance Dial G2 for the task, or explicitly names this skill or an active work unit already running it. Never auto-activate on task class, such as security, auth, or payments. If a task seems to warrant G2 and…
test-verification
Requires behavioral, failure-path, and durable-seam evidence for tests and review. Use when writing tests, reviewing test coverage, assessing behavioral test quality, or accepting high-risk behavior on test evidence.
dotnet-techne-cross-repo-impact
Use when reviewing a .NET pull request for breaking changes that may affect other microservice repositories. Detects cross-repo API, DTO, endpoint, EF entity, and NuGet-package breaks, and checks whether a compatible downstream PR already exists. Keywords: cross-repo impact, breaking change, microservice…
dotnet-techne-csharp-api-design
Use when designing or changing public C#/.NET APIs with compatibility and versioning constraints. Keywords: breaking change, API design, backward compatibility, binary compatibility, deprecation strategy, versioning.
dotnet-techne-csharp-type-design-performance
Use when designing types and collections for hot paths and low-allocation .NET code. Keywords: readonly struct, sealed class, ValueTask, Span, FrozenDictionary, FrozenSet, allocation optimisation.
dotnet-techne-synopsis
Use when you need blast-radius analysis, dependency graphs, cross-repo impact, breaking-change diff, or architectural overview of .NET workspaces. Keywords: blast radius, dependency graph, impact analysis, cross-repo, call graph, endpoint map, EF Core lineage, breaking change, daemon, reindex.