Clean Code
Audit modified files and unpushed commits for dead code, duplication, unnecessary complexity, naming conventions, and import hygiene. Fix issues with user approval.
Editor's Note
Before running the skill, ensure that the working tree and unpushed commits are available for audit. The skill will process all modified files and unpushed commits, and will not alter code logic or behavior — only clean up debug prints, dead code, and imports.
When to Use It
- Removing debug prints from production code
- Auditing unpushed commits for dead code
- Fixing naming conventions in modified files
- Cleaning up imports in modified files
SKILL.md
SkillsHunter provides this listing for informational purposes only. Review the skill’s source, license, and required permissions before use. You are responsible for deciding whether to install or run it. Terms of Use
Clean Code
Audit modified files for dead code, duplication, needless complexity, naming conventions, and import hygiene. Fix issues with user approval.
Context
- Uncommitted changes: !
git status --short - Diff summary: !
git diff --stat $(git rev-parse -q --verify HEAD || echo 4b825dc642cb6eb9a060e54bf8d69288fbee4904) - Full diff: !
git diff --no-textconv $(git rev-parse -q --verify HEAD || echo 4b825dc642cb6eb9a060e54bf8d69288fbee4904) - Code in unpushed commits (empty when there is none): !
git log --stat --oneline HEAD --not --remotes
Process
When /wrap-up runs this skill, do not stop for approval. It collects every question of a close-out into one
summary, so make the changes that need none (debug prints, imports), and return each proposal the Process steps would
wait on as a list — what, where, why — for that summary. Apply the approved ones when the caller says so.
The scope is the working tree AND the unpushed commits, not whichever of the two the first
two probes happen to show. Code that has not been pushed is unreviewed whether or not it is still
in the tree, and /wrap-up sends this skill here for code sitting in a commit as readily as for
an edit on disk. When Code in unpushed commits is non-empty, read that patch with
git log -p --no-textconv HEAD --not --remotes and audit those files too. Measured 2026-10-01:
three unpushed commits changing two C# files were invisible to the git diff HEAD probes, so this
skill reported on a one-line installer edit while the code it was summoned for went unexamined.
-
Remove debug prints (
print(),console.log(),Debug.Log(), etc.) added during development — do not commit temporary debug output -
Dead code audit — iterate until clean: Run the project's own dead-code tooling first, when it has some configured: an unused-symbol rule in its linter (ruff
F401/F841, ESLintno-unused-vars), knip, vulture, or atscrun withnoUnusedLocals. Read the project's lint config andpackage.json/pyproject.tomlscripts to find it, and run only what is already configured — adopting a new tool is an offer under the global Best-Practice Adoption rule, never something this step installs. A tool finds unused symbols more reliably than reading does; what it cannot see is the rest of this step — a cascade across files, a method only tests call, a field written and never read.Then start with modified files, then expand outward: use Grep to find all production files that import, call, or reference symbols defined in modified files. These consumers may now contain dead code if the symbols they depended on were changed, removed, or renamed. For each file in this expanded set, look for:
- Dead methods/functions: defined but never called from production code (only from tests or not at all). Trace callers — if a method is only called from another dead method, both are dead.
- Dead fields/variables: only written (never read), or only set to a constant value that makes guarding branches unreachable.
- Dead imports: symbols imported but unused after other cleanup.
- Dead type members: union/enum members never constructed or matched.
- Cascading dead code: after each removal, re-check whether anything new became unreachable (deleted code may have been the only caller of other code).
For each finding, describe what you found, why it's dead, and propose removal. If the user agrees, make the change. If the user disagrees or wants to keep it, move on. Keep iterating — after each batch of removals, re-scan the affected files for newly dead code. Stop only when a full pass finds nothing actionable, or the user says to stop.
Production code that is public only because tests call it directly (e.g. unit-testing internal methods) is NOT dead — it runs in production via internal calls and is exposed for testability. Do not flag these.
-
Duplication audit: Check modified files for duplicated logic — repeated code blocks, near-identical functions, copy-pasted patterns with minor variations. For each finding:
- Describe the duplication and where it occurs
- Propose a consolidation (shared function, base class method, helper, etc.)
- Wait for user approval before refactoring
Only flag duplication that hurts maintainability — two similar 2-line blocks are fine; three similar 10-line blocks are not.
-
Complexity audit: Check modified code for complexity that buys nothing, and simplify it without changing behaviour:
- Nesting deeper than the logic needs, where an early return or a flattened condition reads the same.
- Nested ternaries; an
if/elsechain or aswitchreads better. - An abstraction with one caller and no second in sight — a wrapper, an interface, a parameter that only ever takes one value. Inline it.
- Generality nobody asked for: configuration, hooks or extension points for a case the code does not have.
- Comments that restate the code; the global Code Comments rule says what a comment is for.
Leave alone what makes code longer but clearer: an explicit branch over a dense one-liner, a named intermediate over a long expression. For each finding, describe it and propose the simplification; wait for approval before changing it.
-
Naming convention audit (Python files only): Check visibility naming in modified Python files:
- A method or module-level function referenced only from inside its own class/module should carry a
_prefix. - A
_-prefixed member referenced from outside its class/module should either lose the prefix or have the external access refactored away.
Skip dunder methods and members that are public API by design (a library's surface stays public even while temporarily uncalled; tests calling an internal member directly do not make it public). For each mismatch, propose the rename and wait for approval; when renaming, update every usage including tests.
- A method or module-level function referenced only from inside its own class/module should carry a
-
Optimize imports in modified source code files — if the project has a linter/formatter that organizes imports (ruff, isort, …), run its autofix (e.g.
ruff check --fix) rather than hand-editing; only hand-optimize when none exists. Some projects deliberately exclude import cleanup from their edit-time lint hook and defer it to commit time, so this step is where it actually gets applied. -
Re-run the project's real gate if you changed anything — the command the deploy runs, not the cheap one. Everything this skill does is a refactor, and a refactor is precisely what slips past tests and lint: extracting a helper gives a value an explicit type it never had inline, so a parameter narrower than what callers pass becomes a type error neither a test suite nor a linter can see. Prefer the build (
npm run build,cargo build,go build) over a standalone type-check script — on a clean tree the latter may fail to resolve framework-generated types and will then pass while the build fails. Judge it by exit status, not by grepping the output for error text, since a pipe throughgrepthrows the status away. If the gate fails, fix it here rather than handing back a change set that does not build. -
Report what was cleaned up, and name the gate you re-ran. If nothing was found, say so.
Out of scope
- Do NOT change code logic or behavior — only the Process steps: remove debug prints and dead code, consolidate duplicates, simplify needless complexity, fix naming, and clean imports
- Do NOT touch files that aren't modified or directly affected by modifications
View original Markdown
---
name: clean-code
description: Remove dead code, fix duplication and needless complexity, enforce naming conventions, and optimize imports in modified files
allowed-tools: Read, Edit, Write, Grep, Glob, Bash(git diff:*), Bash(git log:*), Bash(git status:*), Bash(git rev-parse:*)
---
# Clean Code
Audit modified files for dead code, duplication, needless complexity, naming conventions, and import hygiene. Fix issues with user approval.
## Context
- Uncommitted changes: !`git status --short`
- Diff summary: !`git diff --stat $(git rev-parse -q --verify HEAD || echo 4b825dc642cb6eb9a060e54bf8d69288fbee4904)`
- Full diff: !`git diff --no-textconv $(git rev-parse -q --verify HEAD || echo 4b825dc642cb6eb9a060e54bf8d69288fbee4904)`
- Code in unpushed commits (empty when there is none): !`git log --stat --oneline HEAD --not --remotes`
## Process
**When `/wrap-up` runs this skill, do not stop for approval.** It collects every question of a close-out into one
summary, so make the changes that need none (debug prints, imports), and return each proposal the Process steps would
wait on as a list — what, where, why — for that summary. Apply the approved ones when the caller says so.
**The scope is the working tree AND the unpushed commits**, not whichever of the two the first
two probes happen to show. Code that has not been pushed is unreviewed whether or not it is still
in the tree, and `/wrap-up` sends this skill here for code sitting in a commit as readily as for
an edit on disk. When **Code in unpushed commits** is non-empty, read that patch with
`git log -p --no-textconv HEAD --not --remotes` and audit those files too. Measured 2026-10-01:
three unpushed commits changing two C# files were invisible to the `git diff HEAD` probes, so this
skill reported on a one-line installer edit while the code it was summoned for went unexamined.
1. **Remove debug prints** (`print()`, `console.log()`, `Debug.Log()`, etc.) added during development — do not commit temporary debug output
2. **Dead code audit — iterate until clean:**
Run the project's own dead-code tooling first, when it has some configured: an unused-symbol rule in its linter (ruff `F401`/`F841`, ESLint `no-unused-vars`), knip, vulture, or a `tsc` run with `noUnusedLocals`. Read the project's lint config and `package.json`/`pyproject.toml` scripts to find it, and run only what is already configured — adopting a new tool is an offer under the global Best-Practice Adoption rule, never something this step installs. A tool finds unused symbols more reliably than reading does; what it cannot see is the rest of this step — a cascade across files, a method only tests call, a field written and never read.
Then start with modified files, then expand outward: use Grep to find all production files that import, call, or reference symbols defined in modified files. These consumers may now contain dead code if the symbols they depended on were changed, removed, or renamed. For each file in this expanded set, look for:
- **Dead methods/functions**: defined but never called from production code (only from tests or not at all). Trace callers — if a method is only called from another dead method, both are dead.
- **Dead fields/variables**: only written (never read), or only set to a constant value that makes guarding branches unreachable.
- **Dead imports**: symbols imported but unused after other cleanup.
- **Dead type members**: union/enum members never constructed or matched.
- **Cascading dead code**: after each removal, re-check whether anything new became unreachable (deleted code may have been the only caller of other code).
For each finding, describe what you found, why it's dead, and propose removal. If the user agrees, make the change. If the user disagrees or wants to keep it, move on. **Keep iterating** — after each batch of removals, re-scan the affected files for newly dead code. Stop only when a full pass finds nothing actionable, or the user says to stop.
Production code that is public only because tests call it directly (e.g. unit-testing internal methods) is NOT dead — it runs in production via internal calls and is exposed for testability. Do not flag these.
3. **Duplication audit:**
Check modified files for duplicated logic — repeated code blocks, near-identical functions, copy-pasted patterns with minor variations. For each finding:
- Describe the duplication and where it occurs
- Propose a consolidation (shared function, base class method, helper, etc.)
- Wait for user approval before refactoring
Only flag duplication that hurts maintainability — two similar 2-line blocks are fine; three similar 10-line blocks are not.
4. **Complexity audit:**
Check modified code for complexity that buys nothing, and simplify it without changing behaviour:
- Nesting deeper than the logic needs, where an early return or a flattened condition reads the same.
- Nested ternaries; an `if`/`else` chain or a `switch` reads better.
- An abstraction with one caller and no second in sight — a wrapper, an interface, a parameter that only ever takes one value. Inline it.
- Generality nobody asked for: configuration, hooks or extension points for a case the code does not have.
- Comments that restate the code; the global Code Comments rule says what a comment is for.
Leave alone what makes code longer but clearer: an explicit branch over a dense one-liner, a named intermediate over a long expression. For each finding, describe it and propose the simplification; wait for approval before changing it.
5. **Naming convention audit (Python files only):**
Check visibility naming in modified Python files:
- A method or module-level function referenced only from inside its own class/module should carry a `_` prefix.
- A `_`-prefixed member referenced from outside its class/module should either lose the prefix or have the external access refactored away.
Skip dunder methods and members that are public API by design (a library's surface stays public even while temporarily uncalled; tests calling an internal member directly do not make it public). For each mismatch, propose the rename and wait for approval; when renaming, update every usage including tests.
6. **Optimize imports in modified source code files** — if the project has a linter/formatter that organizes imports (ruff, isort, …), run its autofix (e.g. `ruff check --fix`) rather than hand-editing; only hand-optimize when none exists. Some projects deliberately exclude import cleanup from their edit-time lint hook and defer it to commit time, so this step is where it actually gets applied.
7. **Re-run the project's real gate if you changed anything** — the command the deploy runs, not the cheap one. Everything this skill does is a refactor, and a refactor is precisely what slips past tests and lint: extracting a helper gives a value an explicit type it never had inline, so a parameter narrower than what callers pass becomes a type error neither a test suite nor a linter can see. Prefer the build (`npm run build`, `cargo build`, `go build`) over a standalone type-check script — on a clean tree the latter may fail to resolve framework-generated types and will then pass while the build fails. Judge it by exit status, not by grepping the output for error text, since a pipe through `grep` throws the status away. If the gate fails, fix it here rather than handing back a change set that does not build.
8. **Report** what was cleaned up, and name the gate you re-ran. If nothing was found, say so.
## Out of scope
- Do NOT change code logic or behavior — only the Process steps: remove debug prints and dead code, consolidate duplicates, simplify needless complexity, fix naming, and clean imports
- Do NOT touch files that aren't modified or directly affected by modifications
Community Reviews & Field Notes
Tried this skill on your own project? Share the model you used and the results you got.