Skip to content
Back to search

code-cleanup-skill

Agent skill: clean up dead code, duplicated implementations and stale instructions after edits, context compaction or model upgrades. Read-only scanner included.

Safety scan

A static text scan, not a guarantee. Select the badge to see what was scanned and every finding.

Badge for your README
findsafeskills safety rating

Markdown

[![findsafeskills safety rating](/api/listings/0ct--code-cleanup-skill/badge.svg)](/listings/0ct--code-cleanup-skill)

HTML

<a href="/listings/0ct--code-cleanup-skill"><img src="/api/listings/0ct--code-cleanup-skill/badge.svg" alt="findsafeskills safety rating" /></a>

Install

i

Install instructions from the README

As written by the repo's author. findsafeskills has not verified these steps.

# 装到当前项目(写入 .agents/skills/,并 symlink 到已检测到的宿主)
npx skills add 0ct/code-cleanup-skill --skill code-cleanup

# 装到用户级,所有项目可用
npx skills add 0ct/code-cleanup-skill --skill code-cleanup -g

# 先看看仓库里有什么,不安装
npx skills add 0ct/code-cleanup-skill --list

也可以直接用仓库路径或完整 URL:

npx skills add https://github.com/0ct/code-cleanup-skill/tree/main/skills/code-cleanup

`npx skills add` 会把技能落到 `~/.agents/skills/`(项目级是 `./.agents/skills/`),再为检测到的宿主建软链:Claude Code、Cursor、Codex、Cline、Amp、Kimi Code CLI 等 20+ 个。装完重启会话即可,触发词:`清理代码`、`代码卫生`、`死代码`、`项目体检`、`deslop`、`code cleanup`。

WorkBuddy / CodeBuddy 需要多一步

这两个宿主的目录不在 CLI 的检测范围内(CLI 只认 `~/.codebuddy/skills`,而 WorkBuddy 用的是 `~/.workbuddy/skills`),装完要自己建软链:

npx skills add 0ct/code-cleanup-skill --skill code-cleanup -g
ln -s ~/.agents/skills/code-cleanup ~/.workbuddy/skills/code-cleanup   # WorkBuddy

不用 CLI 的装法

git clone https://github.com/0ct/code-cleanup-skill /tmp/cc
cp -R /tmp/cc/skills/code-cleanup ~/.workbuddy/skills/     # WorkBuddy
cp -R /tmp/cc/skills/code-cleanup ~/.claude/skills/        # Claude Code

或者从 [Releases](https://github.com/0ct/code-cleanup-skill/releases) 下载 `code-cleanup-1.0.0.zip`,解压后把 `code-cleanup/` 放进宿主的 skills 目录。

What was scanned

The files the safety scan read, as written by the repository's author and shown as plain text. Lines with a finding are marked.

README.md · README · 163 lines
  1. # code-cleanup
  2. [![skills.sh](https://skills.sh/b/0ct/code-cleanup-skill)](https://github.com/0ct/code-cleanup-skill)
  3. [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](./LICENSE)
  4. [![Agent Skills](https://img.shields.io/badge/format-agent--skills-blue)](https://agentskills.io)
  5. 一个给 AI 编码 agent 用的代码卫生清理 skill。目标是**让仓库重新成为唯一可信的上下文源** —— 清掉上一轮改动、上下文压缩、agent 模型更新之后留在项目里的残留与自相矛盾,并把"我改了什么"变成可核查的增量。
  6. An agent skill for post-edit repo hygiene: remove dead code, duplicated implementations and stale instructions left behind by half-finished edits, context compaction and model upgrades. Chinese-language instructions; read-only scanner is language-agnostic.
  7. ## 安装
  8. ```bash
  9. # 装到当前项目(写入 .agents/skills/,并 symlink 到已检测到的宿主)
  10. npx skills add 0ct/code-cleanup-skill --skill code-cleanup
  11. # 装到用户级,所有项目可用
  12. npx skills add 0ct/code-cleanup-skill --skill code-cleanup -g
  13. # 先看看仓库里有什么,不安装
  14. npx skills add 0ct/code-cleanup-skill --list
  15. ```
  16. 也可以直接用仓库路径或完整 URL:
  17. ```bash
  18. npx skills add https://github.com/0ct/code-cleanup-skill/tree/main/skills/code-cleanup
  19. ```
  20. `npx skills add` 会把技能落到 `~/.agents/skills/`(项目级是 `./.agents/skills/`),再为检测到的宿主建软链:Claude Code、Cursor、Codex、Cline、Amp、Kimi Code CLI 等 20+ 个。装完重启会话即可,触发词:`清理代码`、`代码卫生`、`死代码`、`项目体检`、`deslop`、`code cleanup`。
  21. ### WorkBuddy / CodeBuddy 需要多一步
  22. 这两个宿主的目录不在 CLI 的检测范围内(CLI 只认 `~/.codebuddy/skills`,而 WorkBuddy 用的是 `~/.workbuddy/skills`),装完要自己建软链:
  23. ```bash
  24. npx skills add 0ct/code-cleanup-skill --skill code-cleanup -g
  25. ln -s ~/.agents/skills/code-cleanup ~/.workbuddy/skills/code-cleanup # WorkBuddy
  26. ```
  27. ### 不用 CLI 的装法
  28. ```bash
  29. git clone https://github.com/0ct/code-cleanup-skill /tmp/cc
  30. cp -R /tmp/cc/skills/code-cleanup ~/.workbuddy/skills/ # WorkBuddy
  31. cp -R /tmp/cc/skills/code-cleanup ~/.claude/skills/ # Claude Code
  32. ```
  33. 或者从 [Releases](https://github.com/0ct/code-cleanup-skill/releases) 下载 `code-cleanup-1.0.0.zip`,解压后把 `code-cleanup/` 放进宿主的 skills 目录。
  34. ## 它解决的问题
  35. 不是"代码不够整洁",是**仓库和"关于仓库的描述"脱钩了**。四种漂移源:
  36. | 漂移源 | 表现 | 清理动作 |
  37. | --- | --- | --- |
  38. | 代码漂移 | 上一轮改到一半的尝试、被放弃的分支、绕开报错的临时补丁留在原处 | 删除死代码与被取代的实现 |
  39. | 记忆漂移 | 上下文压缩后 agent 凭摘要判断"这函数没人用",于是在旁边又写一份(zombie pattern) | 用引用与调用链重建事实,删掉重复的那份 |
  40. | 习惯漂移 | 模型/工具链更新后,旧的冗余防御、隐式 `any`、过时 API 还在被复制 | 按当前写法收敛,不改行为 |
  41. | 指令漂移 | `AGENTS.md`/README 描述的模块已删,下一个 agent 照着文档把它写回来 | 让文档与代码对齐,或标记为待确认 |
  42. ## 检查范围
  43. 十类,每类都在 `references/audit-checklist.md` 里给了判定证据标准、检索手段、常见误判和可自动修的条件:
  44. 损坏/不可达代码 · 前后矛盾逻辑 · 重复实现 · 过时/未使用实现 · 无谓抽象与过度防御 · 低效写法 · 过期注释与文档 · 过期配置/测试 · 依赖漂移 · 指令漂移
  45. ## 工作流
  46. 八个阶段,不可跳步:
  47. 1. **建立事实基线** —— `git status` / 最近改动 / 构建与测试是否可跑
  48. 2. **通读整个项目** —— 入口约定 → 入口代码 → 核心模块 → 周边 → 文档;读完的判据是能不看文件答出入口、数据流、接口面、怎么构建测试
  49. 3. **跑只读扫描器** —— 拿线索,不下结论
  50. 4. **逐条定性** —— 四个必要条件全满足才动手(见下)
  51. 5. **最小改动修复** —— 按类别分批,每批独立可回退
  52. 6. **验证** —— 基线对比:测试数不减、通过数不降、类型错误不增
  53. 7. **复扫** —— 删除会制造新的死代码,级联影响必须再看一遍
  54. 8. **输出** —— 已修复摘要 + 待确认清单 + 未覆盖声明
  55. ## 只读扫描器
  56. `scripts/repo_scan.py` 是纯 stdlib 单文件脚本,不装依赖、不改文件、不发网络请求。
  57. ```bash
  58. python3 skills/code-cleanup/scripts/repo_scan.py <repo> --md scan.md --json scan.json
  59. ```
  60. | 参数 | 作用 |
  61. | --- | --- |
  62. | `--focus <subdir>` | 只扫某个子目录 |
  63. | `--since-days N` | 给近 N 天改动过的文件打 `🆕`(默认 30) |
  64. | `--baseline old.json` | 与上一次扫描对比,输出「清理效果对比」表 |
  65. | `--limit N` | 每类最多输出 N 条(默认 200) |
  66. | `--max-total-bytes` | 读取总预算,默认 120MB,防大仓库 OOM |
  67. | `--no-git` | 跳过 git 相关检查 |
  68. | `--quiet` | 不打印进度 |
  69. 覆盖 JS/TS/monorepo(逐包 `package.json`)、Python(`pyproject`/`requirements`)、Go(`go.mod` require vs import,含 indirect 排除)、Rust(`Cargo.toml` vs `use`)。
  70. 输出示例(故意植入 12 类问题的夹具仓库,命中 18 条):
  71. ```
  72. - 扫描文件:8 个 / 可读文本 8 个 / 代码 5 个
  73. - 命中条目:18 条,其中 14 条落在近 30 天改动过的文件里
  74. | 分类 | 条目 | 其中高置信可核实 |
  75. | --- | --- | --- |
  76. | 失效引用 | 1 | 1 |
  77. | 声明未使用的依赖 | 1 | 0 |
  78. | 硬编码路径与疑似凭据 | 2 | 1 |
  79. ```
  80. ## 安全边界
  81. **能自动改的只有那些满足四个必要条件的**:不可达性可证 + 接口不变 + 局部可逆 + 可验证。缺一条就进待确认清单,不擅自改。
  82. 风险分级:
  83. | 级别 | 含义 | 处理 |
  84. | --- | --- | --- |
  85. | R0 | 无行为影响,纯文本订正 | 直接改 |
  86. | R1 | 删除静态可证的死代码,不在导出面 | 直接改 + 复扫 |
  87. | R2 | 涉及导出面、错误路径、跨模块契约 | 只进清单 |
  88. | R3 | 鉴权/加密/并发/序列化/迁移/生成代码/vendored/凭据/用户未提交改动 | 只报告,绝不动手 |
  89. 硬编码凭据只报告不清除 —— 删掉不等于轮换,留着痕迹才有追溯价值。
  90. ## 已知短板
  91. - `commented_code` 会把 docstring 里的 ASCII 图、缩进代码示例误判成"被注释掉的代码"。脚本标 `likely`,需要人过一眼;根治需要 AST,会让脚本从"任何环境能跑"变成"需要装依赖"。
  92. - 无引用文件检测是纯文本级:反射、字符串路由、barrel 导出、`__init__` 副作用、装饰器注册、feature gate 都会绕过它。所以那类结论一律 `speculative`,`references/` 里专门列了"看起来死了其实活着"的清单。
  93. - 单文件脚本做不了真实调用图,跨语言/跨进程的引用(配置驱动、gRPC、消息队列)看不到。
  94. - 指令是中文的;扫描器输出也是中文。
  95. ## 仓库结构
  96. ```
  97. skills/code-cleanup/
  98. ├── SKILL.md # 主流程:8 阶段 + 四条漂移源 + 收敛判据
  99. ├── references/
  100. │ ├── audit-checklist.md # 十类问题的判定证据标准与误判陷阱
  101. │ ├── agent-residue.md # 六种 agent 残留形态与归属判定
  102. │ ├── risk-and-fix-rules.md # R0–R3 分级、白名单/黑名单、验证矩阵
  103. │ ├── tooling.md # knip / vulture / staticcheck 等工具梯子与纪律
  104. │ └── report-template.md # 四段式输出模板 + 硬约束 + 反例
  105. └── scripts/repo_scan.py # 只读事实扫描器(纯 stdlib,1315 行)
  106. ```
  107. ## 开发与同步
  108. 仓库是发布源,宿主目录里装的是副本。改完技能后同步过去:
  109. ```bash
  110. rsync -a --delete ~/Projects/code-cleanup-skill/skills/code-cleanup/ ~/.workbuddy/skills/code-cleanup/
  111. ```
  112. CI 只做冒烟测试:`SKILL.md` frontmatter 合法、`repo_scan.py` 语法通过、在夹具仓库上能产出报告。
  113. ## License
  114. MIT

Ratings and comments

Sign in to rate this skill.

Sign in

Free to use. If it’s helped, pass it on.