Simplify Code — Parallel Review & Cleanup
Review your recent code changes with three focused reviewers running in
parallel, aggregate their findings, and apply the fixes worth applying.
Core principle: Three narrow reviewers beat one broad reviewer. Each one
deeply searches the codebase for a single class of problem — reuse, quality,
efficiency — without diluting its attention across all three. They run
concurrently, so you pay the latency of one review, not three.
When to Use
Trigger this skill when the user says any of:
- "simplify" / "simplify my changes" / "simplify these changes"
- "review my code" / "review my recent changes" / "clean up my changes"
- "/simplify" (if they're carrying the Claude Code habit over)
Optional modifiers the user may add — honor them:
- Focus: "simplify focus on efficiency" → run only the efficiency reviewer
(or weight the aggregation toward it). Recognized focuses:
reuse,
quality, efficiency.
- Dry run: "simplify but don't change anything" / "just report" → run the
three reviewers, present findings, apply NOTHING. Ask before applying.
- Scope: "simplify the last commit" / "simplify staged" / "simplify
src/foo.py" → narrow the diff source accordingly (see Phase 1).
Do NOT auto-run this after every edit. It costs three subagents' worth of
tokens — invoke it only when the user explicitly asks.
The Process
Phase 1 — Identify the changes
Capture the diff to review. Pick the source by what the user asked for, in
this default order:
# 1. Default: uncommitted working-tree changes (tracked files)
git diff
# 2. If that's empty, include staged changes
git diff HEAD
# 3. Scoped variants the user may request:
git diff --staged # "staged changes"
git diff HEAD~1 # "the last commit"
git diff main...HEAD # "this branch" / "my PR"
git diff -- src/foo.py # specific file(s)
If git diff and git diff HEAD are both empty and there's no git repo or no
changes, fall back to the files the user explicitly named or that were
recently created/edited in this session. If you genuinely can't find any
changed code, say so and stop — there's nothing to simplify.
Capture the full diff text. Note its size: if it's very large (say >2000
changed lines), warn the user that three subagents each carrying the full diff
will be token-heavy, and offer to scope it down (per-directory, per-commit)
before proceeding.
Phase 2 — Launch three reviewers in parallel
Use delegate_task batch mode — pass all three tasks in one tasks
array so they run concurrently. Three is the right fan-out for this pattern;
it's well within the delegation.max_concurrent_children budget on any
default install.
Give every reviewer the complete diff (not fragments — cross-file
issues hide in the gaps) plus the absolute repo path so they can search the
wider codebase. Each reviewer gets terminal, file, and search
toolsets (so they can git, read_file, and search_files/grep).
Tell each reviewer to:
Pass these three goals (drop any the user's focus excludes):
Reviewer 1 — Code Reuse
Review this diff for code that duplicates functionality already in the
codebase. Search utility modules, shared helpers, and adjacent files
(use search_files / grep) for existing functions, constants, or patterns
the new code could call instead of reimplementing. Flag: new functions
that duplicate existing ones; hand-rolled logic that an existing utility
already does (manual string/path manipulation, custom env checks, ad-hoc
type guards, re-implemented parsing). For each, name the existing thing to
use and where it lives.
Reviewer 2 — Code Quality
Review this diff for quality problems. Look for: redundant state (values
that duplicate or could be derived from existing state; caches that don't
need to exist); parameter sprawl (new params bolted on where the function
should have been restructured); copy-paste-with-variation (near-duplicate
blocks that should share an abstraction); leaky abstractions (exposing
internals, breaking an existing encapsulation boundary); stringly-typed
code (raw strings where a constant/enum/registry already exists — check the
canonical registries before flagging); AI-generated slop patterns (extra
comments restating obvious code like // increment counter above count++;
unnecessary defensive null-checks on already-validated inputs; as any
casts that bypass the type system; patterns inconsistent with the rest of
the file). For each, give the concrete refactor.
Reviewer 3 — Efficiency
Review this diff for efficiency problems. Look for: unnecessary work
(redundant computation, repeated file reads, duplicate API calls, N+1
access patterns); missed concurrency (independent ops run sequentially);
hot-path bloat (heavy/blocking work on startup or per-request paths);
TOCTOU anti-patterns (existence pre-checks before an op instead of doing
the op and handling the error); memory issues (unbounded growth, missing
cleanup, listener/handle leaks); overly broad reads (loading whole files
when a slice would do); silent failures (empty catch blocks, ignored error
returns, except: pass, .catch(() => {}) with no handling, error
propagation gaps — these hide bugs and should at minimum log before
swallowing). For each, give the concrete fix and why it's faster or safer.
Phase 3 — Aggregate and apply
Wait for all three to return (batch mode returns them together).
- Merge the findings into one list, deduping where reviewers overlap.
- Discard false positives — you have the most context; you don't have to
argue with a reviewer, just drop weak or wrong suggestions silently.
- Resolve conflicts. Reviewers can disagree (Reviewer 1: "use existing
util X"; Reviewer 3: "X is slow, inline it"). Default resolution order:
correctness > the user's stated focus > readability/reuse > micro-perf.
Don't apply a perf "fix" that hurts clarity unless the path is genuinely
hot. When two suggestions are mutually exclusive and both defensible, pick
the one that touches less code and note the alternative.
- Apply in risk-tier order:
- SAFE first (auto-apply): unused imports, commented-out code,
pass-through wrappers, redundant type assertions. Run tests after.
- CAREFUL next (apply with verification, one file at a time): rename
locals, flatten ternaries, extract helpers, consolidate dupes. Run tests
after each file. Revert any that break.
- RISKY last (flag for review — do NOT auto-apply): N+1 restructuring,
public API changes, concurrency fixes, error-handling changes. Present
each with risk description and test coverage status.
If the user opted for a dry run, present all three tiers and apply nothing.
- Verify you didn't break anything: run the project's targeted tests for
the touched files (not the full suite), and re-run any linter/type check the
repo uses. If a fix breaks a test, revert that one fix and report it.
- Summarize what you changed: a short list of applied fixes grouped by
reviewer category and risk tier, plus any findings you deliberately skipped
and why.
Pitfalls
- Don't fan out wider than ~3. More reviewers means more cost and more
conflicting suggestions to reconcile, not better coverage. Three categories
cover the space.
- Give the WHOLE diff to each reviewer. Splitting the diff across reviewers
defeats the design — cross-file duplication and N+1s only show up with the
full picture.
- Reviewers search, they don't guess. A reuse finding with no pointer to
the existing utility ("there's probably a helper for this") is noise. Require
file:line evidence; drop findings that lack it.
- Apply ≠ rewrite. This is cleanup of the user's recent changes, not a
license to refactor the whole module. Keep edits scoped to what the diff
touched plus the minimal surrounding change a fix requires.
- Respect project conventions. If the repo has AGENTS.md / CLAUDE.md /
HERMES.md or a linter config, fold those rules into the reviewer prompts so
suggestions match house style instead of fighting it.
- Large diffs blow context. If the diff is huge, scope it down before
delegating — three subagents each carrying a 5000-line diff is expensive and
may truncate.
- Over-trusting dead code tools.
knip, ts-prune, and depcheck flag
exports that ARE used dynamically (string-based imports, reflection). Always
grep for the symbol name before removing — a clean tool report is not proof.
- Renaming without checking public contracts. Export names, API route
paths, DB column names, and config keys are contracts — even if the name is
bad, renaming breaks consumers. Tag public-contract changes as RISKY; never
auto-rename them.
- Removing "unnecessary" error handling. An empty catch block or ignored
error might be intentional — the error is expected and benign in that
context. Flag it, don't remove it; let the human decide.
Related
If your install has the subagent-driven-development skill (optional), it
covers the complementary case: parallel review during implementation, per
task. This skill is the standalone after-the-fact cleanup pass. Use
requesting-code-review for the pre-commit security/quality gate.
1---2name: simplify-code3description: "Parallel 3-agent cleanup of recent code changes."4version: 1.0.05author: Hermes Agent (inspired by Claude Code /simplify)6license: MIT7platforms: [linux, macos, windows]8metadata:9 source: https://skillmd.com/skills/peteedoo/simplify-code10 hermes:11 tags: [code-review, cleanup, refactor, delegation, subagent, parallel, simplify]12 related_skills: [requesting-code-review, test-driven-development, plan]13---1415# Simplify Code — Parallel Review & Cleanup1617Review your recent code changes with three focused reviewers running in18parallel, aggregate their findings, and apply the fixes worth applying.1920**Core principle:** Three narrow reviewers beat one broad reviewer. Each one21deeply searches the codebase for a single class of problem — reuse, quality,22efficiency — without diluting its attention across all three. They run23concurrently, so you pay the latency of one review, not three.2425## When to Use2627Trigger this skill when the user says any of:2829- "simplify" / "simplify my changes" / "simplify these changes"30- "review my code" / "review my recent changes" / "clean up my changes"31- "/simplify" (if they're carrying the Claude Code habit over)3233Optional modifiers the user may add — honor them:3435- **Focus:** "simplify focus on efficiency" → run only the efficiency reviewer36 (or weight the aggregation toward it). Recognized focuses: `reuse`,37 `quality`, `efficiency`.38- **Dry run:** "simplify but don't change anything" / "just report" → run the39 three reviewers, present findings, apply NOTHING. Ask before applying.40- **Scope:** "simplify the last commit" / "simplify staged" / "simplify41 src/foo.py" → narrow the diff source accordingly (see Phase 1).4243Do NOT auto-run this after every edit. It costs three subagents' worth of44tokens — invoke it only when the user explicitly asks.4546## The Process4748### Phase 1 — Identify the changes4950Capture the diff to review. Pick the source by what the user asked for, in51this default order:5253```bash54# 1. Default: uncommitted working-tree changes (tracked files)55git diff5657# 2. If that's empty, include staged changes58git diff HEAD5960# 3. Scoped variants the user may request:61git diff --staged # "staged changes"62git diff HEAD~1 # "the last commit"63git diff main...HEAD # "this branch" / "my PR"64git diff -- src/foo.py # specific file(s)65```6667If `git diff` and `git diff HEAD` are both empty and there's no git repo or no68changes, fall back to the files the user explicitly named or that were69recently created/edited in this session. If you genuinely can't find any70changed code, say so and stop — there's nothing to simplify.7172Capture the full diff text. Note its size: if it's very large (say >200073changed lines), warn the user that three subagents each carrying the full diff74will be token-heavy, and offer to scope it down (per-directory, per-commit)75before proceeding.7677### Phase 2 — Launch three reviewers in parallel7879Use `delegate_task` **batch mode** — pass all three tasks in one `tasks`80array so they run concurrently. Three is the right fan-out for this pattern;81it's well within the `delegation.max_concurrent_children` budget on any82default install.8384Give **every** reviewer the **complete diff** (not fragments — cross-file85issues hide in the gaps) plus the absolute repo path so they can search the86wider codebase. Each reviewer gets `terminal`, `file`, and `search`87toolsets (so they can `git`, `read_file`, and `search_files`/grep).8889Tell each reviewer to:90- Search the existing codebase for evidence (don't reason from the diff alone).91- **Apply Chesterton's Fence:** before flagging anything for removal, run92 `git blame` on the line to understand why it exists. If you can't determine93 the original purpose, mark it `confidence: low` — don't guess.94- Report findings as structured output with confidence and risk:95 ```96 file:line → problem → suggested fix | confidence: high/medium/low | risk: SAFE/CAREFUL/RISKY97 ```98 - **SAFE** = proven not to affect behavior (unused imports, commented-out99 code, pass-through wrappers). Auto-apply these.100 - **CAREFUL** = improves without changing semantics (rename local variable,101 flatten nested ternary, extract helper). Apply with test verification.102 - **RISKY** = may change behavior or breaks public contracts (N+1103 restructuring, public API rename, memory lifecycle change). Flag for104 human review — do NOT auto-apply.105- Skip nits and style-only churn. Only flag things that materially improve106 the code.107108Pass these three goals (drop any the user's focus excludes):109110**Reviewer 1 — Code Reuse**111> Review this diff for code that duplicates functionality already in the112> codebase. Search utility modules, shared helpers, and adjacent files113> (use search_files / grep) for existing functions, constants, or patterns114> the new code could call instead of reimplementing. Flag: new functions115> that duplicate existing ones; hand-rolled logic that an existing utility116> already does (manual string/path manipulation, custom env checks, ad-hoc117> type guards, re-implemented parsing). For each, name the existing thing to118> use and where it lives.119120**Reviewer 2 — Code Quality**121> Review this diff for quality problems. Look for: redundant state (values122> that duplicate or could be derived from existing state; caches that don't123> need to exist); parameter sprawl (new params bolted on where the function124> should have been restructured); copy-paste-with-variation (near-duplicate125> blocks that should share an abstraction); leaky abstractions (exposing126> internals, breaking an existing encapsulation boundary); stringly-typed127> code (raw strings where a constant/enum/registry already exists — check the128> canonical registries before flagging); AI-generated slop patterns (extra129> comments restating obvious code like `// increment counter` above `count++`;130> unnecessary defensive null-checks on already-validated inputs; `as any`131> casts that bypass the type system; patterns inconsistent with the rest of132> the file). For each, give the concrete refactor.133134**Reviewer 3 — Efficiency**135> Review this diff for efficiency problems. Look for: unnecessary work136> (redundant computation, repeated file reads, duplicate API calls, N+1137> access patterns); missed concurrency (independent ops run sequentially);138> hot-path bloat (heavy/blocking work on startup or per-request paths);139> TOCTOU anti-patterns (existence pre-checks before an op instead of doing140> the op and handling the error); memory issues (unbounded growth, missing141> cleanup, listener/handle leaks); overly broad reads (loading whole files142> when a slice would do); silent failures (empty catch blocks, ignored error143> returns, `except: pass`, `.catch(() => {})` with no handling, error144> propagation gaps — these hide bugs and should at minimum log before145> swallowing). For each, give the concrete fix and why it's faster or safer.146147### Phase 3 — Aggregate and apply148149Wait for all three to return (batch mode returns them together).1501511. **Merge** the findings into one list, deduping where reviewers overlap.1522. **Discard false positives** — you have the most context; you don't have to153 argue with a reviewer, just drop weak or wrong suggestions silently.1543. **Resolve conflicts.** Reviewers can disagree (Reviewer 1: "use existing155 util X"; Reviewer 3: "X is slow, inline it"). Default resolution order:156 **correctness > the user's stated focus > readability/reuse > micro-perf.**157 Don't apply a perf "fix" that hurts clarity unless the path is genuinely158 hot. When two suggestions are mutually exclusive and both defensible, pick159 the one that touches less code and note the alternative.1604. **Apply in risk-tier order:**161 - **SAFE first** (auto-apply): unused imports, commented-out code,162 pass-through wrappers, redundant type assertions. Run tests after.163 - **CAREFUL next** (apply with verification, one file at a time): rename164 locals, flatten ternaries, extract helpers, consolidate dupes. Run tests165 after each file. Revert any that break.166 - **RISKY last** (flag for review — do NOT auto-apply): N+1 restructuring,167 public API changes, concurrency fixes, error-handling changes. Present168 each with risk description and test coverage status.169 If the user opted for a dry run, present all three tiers and apply nothing.1705. **Verify** you didn't break anything: run the project's targeted tests for171 the touched files (not the full suite), and re-run any linter/type check the172 repo uses. If a fix breaks a test, revert that one fix and report it.1736. **Summarize** what you changed: a short list of applied fixes grouped by174 reviewer category and risk tier, plus any findings you deliberately skipped175 and why.176177## Pitfalls178179- **Don't fan out wider than ~3.** More reviewers means more cost and more180 conflicting suggestions to reconcile, not better coverage. Three categories181 cover the space.182- **Give the WHOLE diff to each reviewer.** Splitting the diff across reviewers183 defeats the design — cross-file duplication and N+1s only show up with the184 full picture.185- **Reviewers search, they don't guess.** A reuse finding with no pointer to186 the existing utility ("there's probably a helper for this") is noise. Require187 `file:line` evidence; drop findings that lack it.188- **Apply ≠ rewrite.** This is cleanup of the user's recent changes, not a189 license to refactor the whole module. Keep edits scoped to what the diff190 touched plus the minimal surrounding change a fix requires.191- **Respect project conventions.** If the repo has AGENTS.md / CLAUDE.md /192 HERMES.md or a linter config, fold those rules into the reviewer prompts so193 suggestions match house style instead of fighting it.194- **Large diffs blow context.** If the diff is huge, scope it down before195 delegating — three subagents each carrying a 5000-line diff is expensive and196 may truncate.197- **Over-trusting dead code tools.** `knip`, `ts-prune`, and `depcheck` flag198 exports that ARE used dynamically (string-based imports, reflection). Always199 grep for the symbol name before removing — a clean tool report is not proof.200- **Renaming without checking public contracts.** Export names, API route201 paths, DB column names, and config keys are contracts — even if the name is202 bad, renaming breaks consumers. Tag public-contract changes as RISKY; never203 auto-rename them.204- **Removing "unnecessary" error handling.** An empty catch block or ignored205 error might be intentional — the error is expected and benign in that206 context. Flag it, don't remove it; let the human decide.207208## Related209210If your install has the `subagent-driven-development` skill (optional), it211covers the complementary case: parallel review *during* implementation, per212task. This skill is the standalone *after-the-fact* cleanup pass. Use213`requesting-code-review` for the pre-commit security/quality gate.