Deslop a branch by deleting AI slop and unneeded code without changing behaviour, such as narrating comments, try/catch that hides errors, any casts, dead code, one-use wrappers, deep nesting and duplicated helpers, with tests green before and after and a separate commit. Use when the user types /subtract or asks to deslop, unslop, remove the slop or unnecessary comments, clean up AI-generated code, trim or simplify the branch before review, or delete what isn't needed. Not for bug fixes, new...
Installs into .claude/skills of the current project.
Sponsors
SSkills DirectorySkills Directory
Is that skill safe to install?
SSkills DirectorySkills Directory
Know which skills are safe — weekly.
Are you the author of Subtract?
Add the live security badge to your README. It updates with every re-scan.
[](https://www.skillsdirectory.com/skills/ilexpwh-subtract)
---
name: subtract
description: Deslop a branch by deleting AI slop and unneeded code without changing behaviour, such as narrating comments, try/catch that hides errors, any casts, dead code, one-use wrappers, deep nesting and duplicated helpers, with tests green before and after and a separate commit. Use when the user types /subtract or asks to deslop, unslop, remove the slop or unnecessary comments, clean up AI-generated code, trim or simplify the branch before review, or delete what isn't needed. Not for bug fixes, new features or reviewing someone else's PR (review-change).
disable-model-invocation: true
metadata:
phase: review
---
# Subtract
A smaller branch that does exactly what it did before, in its own commit.
## When to use
- A branch is about to go up for review and the agent-written code carries noise.
- A review flagged narrating comments, swallowed errors, casts or one-use helpers.
- The user asks to deslop, trim or simplify what this branch added.
**Not for:** changing behaviour, fixing bugs (`bug-fix` playbook), restructuring code this branch didn't touch (`smallest-change`), or reviewing a PR (`review-change`).
## Steps
1. **Fix the scope.** Find the base: `git merge-base origin/<default> HEAD`. The scope is the lines this branch added or changed, from `git diff <base>...HEAD`. Code the branch didn't touch is out of scope. Start from a clean tree; if there is uncommitted work, stop and ask whether to commit it first. Never run a bare `git stash` (`clean-shared-hosts`). *Done when:* the base commit and the in-scope file list are written down and `git status --short` is empty.
2. **Record a green baseline.** Run the project's tests, typecheck and lint (from `AGENTS.md` or CI config) and save each command with its result. If anything is red, stop: without a green baseline you can't show behaviour stayed the same. *Done when:* every check passes and the output is saved.
3. **List the candidates.** Scan the in-scope lines against `references/slop.md`. Record each candidate as `file:line`, category and the planned action (delete, reuse or rewrite). *Done when:* the list covers every in-scope file.
4. **Check each fence before removing it.** Ask why it exists. Find its callers (`rg -n <symbol>`), read the commit that added it (`git log -S '<line>' --oneline`), and read nearby comments. Keep a comment that records a constraint or a reason. Keep error handling at a trust boundary (user input, network, files, process exit). Keep anything a test, a public API or a caller outside the diff depends on. *Done when:* every candidate is marked remove or keep, and each keep has a reason.
5. **Subtract, one category at a time.** Prefer deletion, then reuse of an existing helper, then a rewrite such as early returns. Add no new abstraction, dependency or file. After each category, rerun the fast checks; if one fails, revert that category and mark its candidates keep. *Done when:* every remove candidate is applied or reverted with a reason.
6. **Prove nothing changed.** Rerun the exact baseline commands. Every check must pass with the same tests passing and no test edited. Exported names and signatures stay the same. Show `git diff --stat` for this step's changes: lines removed should exceed lines added. *Done when:* the results match the baseline and the net line count went down.
7. **Commit separately.** Commit only this cleanup, apart from feature commits, with a message such as `refactor: subtract slop from <branch>` that gives counts by category. Don't push unless the stake tier allows it (`autonomy-by-stakes`). With an active ledger, record the commit in the item's evidence. *Done when:* `git log -1 --stat` shows a commit containing only removals and rewrites.
## Red flags
| If you're thinking | Do this instead |
|---|---|
| "This catch might be needed someday." | If it only hides an error on a trusted path, delete it. Keep it at a real boundary, with a reason. |
| "I'll tidy the untouched file next door too." | Out of scope. Leave it for its own change (`smallest-change`). |
| "A test needed updating after the cleanup." | Behaviour changed. Revert that edit. |
| "A small helper would dedupe these two blocks." | Reuse an existing helper, or leave both. Don't add a layer to remove a layer. |
| "The comment explains what the code does." | Delete it. Keep comments that explain why or record a constraint. |
| "The `any` is easier than fixing the type." | Use the real type from the library or the caller. If you can't, keep the cast and note why. |
| "I'll fold the cleanup into the feature commit." | Commit it separately so it can be reviewed and reverted on its own. |
## Verify
- [ ] The baseline checks were green before any edit.
- [ ] Every edit is inside lines this branch added or changed.
- [ ] The same checks pass afterwards, and no test was edited, skipped or deleted.
- [ ] Exported names and signatures are unchanged.
- [ ] Net lines went down.
- [ ] The cleanup is its own commit, and every keep has a written reason.
## Reply
```
Subtracted <n> lines (+<added> / -<removed>) across <m> files in <short sha>.
| Category | Removed | Example |
|---|---|---|
| narrating comments | <n> | <file:line> |
Kept on purpose: <file:line, reason> (or "none")
Checks: <command> before -> <result>, after -> <result>
Not pushed | pushed to <branch>
```
## Credits
The slop categories and "keep behaviour unchanged" guardrail come from Cursor team kit's `deslop`. Treating comments as presumed dead unless they carry a constraint follows pstack's `no-comments`, and the AI-tell list behind narrating comments follows pstack's `unslop`, both by Lauren Tan. Checking why a fence exists before removing it, one change at a time with tests after each, and separating refactors from features come from Addy Osmani's `code-simplification`. The name is pstack's principle "subtract before you add".