Code simplification
This is a behavior-preserving quality pass over the resolved change scope.
Use $ARGUMENTS when a target is explicit; otherwise review the current
change. Keep fixes inside that scope and leave correctness verdicts to a
read-only review workflow such as $change-verdict --mode code.
When NOT to Use
- A bug, security issue, or correctness concern needs judging: use the relevant
review or diagnosis workflow first.
- The requested change is a feature or architecture redesign rather than a
cleanup of existing changes.
- The target cannot be resolved, has no changes, or its baseline test fails
without explicit acceptance of that known failure.
Workflow
Resolve the scope. An explicit target always wins:
- Existing file/directory: review its full contents and run
git diff HEAD -- "$ARGUMENTS"; keep the path quoted after --.
- Pull request number, URL, or
#number: verify it and gather
gh pr diff "$ARGUMENTS".
- Branch or commit ref: verify it, identify its upstream or repository
default branch, compute
git merge-base <target> <base>, then gather the
target diff with git diff <merge-base>...<target>.
- Anything else is
BLOCKED; never fall back to the current branch for an
invalid explicit target.
Without an explicit target, try git diff @{upstream}...HEAD, then
git diff main...HEAD, then git diff HEAD~1. If the worktree is dirty or
the range is empty, also include git diff HEAD. Stop with nothing to simplify when the resolved scope has no changes.
Establish the baseline. Resolve the repository’s relevant test command,
run it before editing, and record the exact command and result. Stop when it
fails unless the caller explicitly accepts that known failure.
Review four angles. The current Host and Model review all four angles
directly in one pass as the standard path. When requested and supported by
the Host, optional read-only subagents may review separate angles. Complete
missing angles inline and record any angle that remains unreviewed. Each
finding records file, line, a one-line summary, and its concrete cost.
| Angle |
Look for |
| Reuse |
New code reimplementing an existing helper or pattern |
| Simplification |
Derivable state, copy-paste variation, deep nesting, dead code |
| Efficiency |
Repeated computation/I/O, sequential independent work, retained closures |
| Altitude |
Symptom patches or special cases where shared infrastructure is the root fix |
Apply safely. Deduplicate findings at the same line or mechanism. Apply
only behavior-preserving findings inside the resolved scope. Skip findings
that change intended behavior, require out-of-scope files, or are false
positives, and record each reason.
Handle heavy cleanup explicitly. A file over 800 lines, cross-file
deduplication, or a multi-module dead-code sweep needs a documented scoped
process. Work in small, evidence-backed batches within the current scope;
defer out-of-scope design decisions with a concrete handoff to the caller.
Close the loop. Run the exact baseline test command again. A failing
final test leaves the task incomplete and the result BLOCKED; do not claim
the cleanup is safe.
Output
Use the following report and record the actual execution mode:
## Refactoring Summary
Execution Mode: current Host/Model single-pass | optional fan-out | mixed
### Applied
- [file:line] <summary> — Cost: <concrete cost> — Fix: <change>
### Skipped
- [file:line] <summary> — Reason: <behavior change | out of scope | false positive>
## Test Results
- Baseline: PASS/FAIL — `<command>`
- Final: PASS/FAIL/NOT_RUN — `<same command>`
Record the reviewed angles and any missing evidence. Single-pass execution is
standard; optional fan-out supplies independent observations when used.
Return control to the caller after delivering findings and verification.
Verification
References
references/refactor-contract.md — finding, execution, heavy-cleanup, and
handoff details used when the inline workflow needs the extended contract.
- Native
git, gh, rg, file reads, and the repository’s test command are
the portable scope and verification tools.
1---2name: code-simplify3argument-hint: '[<target>]'4description: 'Use when cleaning changed code for reuse, simplicity, efficiency, and the right abstraction level without changing behavior. Not for correctness review, broad redesign, or unbounded cleanup. Output: four-angle findings, applied/skipped changes, and baseline/final test evidence.'5allowed-tools: 'Read, Grep, Glob, Edit, Bash'6metadata:7 source: https://skillmd.com/skills/hmj1026/code-simplify8 dhpk-capability-id: dhpk.skill.code-simplify9 dhpk-name-style: portable-skill10 dhpk-invocation-class: implicit-eligible11 dhpk-next:12 PASS: none13 FAIL: none14 BLOCKED: none15 NOT_RUN: none16 UNAVAILABLE: none17---1819# Code simplification2021This is a behavior-preserving quality pass over the resolved change scope.22Use `$ARGUMENTS` when a target is explicit; otherwise review the current23change. Keep fixes inside that scope and leave correctness verdicts to a24read-only review workflow such as `$change-verdict --mode code`.2526## When NOT to Use2728- A bug, security issue, or correctness concern needs judging: use the relevant29 review or diagnosis workflow first.30- The requested change is a feature or architecture redesign rather than a31 cleanup of existing changes.32- The target cannot be resolved, has no changes, or its baseline test fails33 without explicit acceptance of that known failure.3435## Workflow36371. **Resolve the scope.** An explicit target always wins:38 - Existing file/directory: review its full contents and run39 `git diff HEAD -- "$ARGUMENTS"`; keep the path quoted after `--`.40 - Pull request number, URL, or `#number`: verify it and gather41 `gh pr diff "$ARGUMENTS"`.42 - Branch or commit ref: verify it, identify its upstream or repository43 default branch, compute `git merge-base <target> <base>`, then gather the44 target diff with `git diff <merge-base>...<target>`.45 - Anything else is `BLOCKED`; never fall back to the current branch for an46 invalid explicit target.4748 Without an explicit target, try `git diff @{upstream}...HEAD`, then49 `git diff main...HEAD`, then `git diff HEAD~1`. If the worktree is dirty or50 the range is empty, also include `git diff HEAD`. Stop with `nothing to51 simplify` when the resolved scope has no changes.522. **Establish the baseline.** Resolve the repository’s relevant test command,53 run it before editing, and record the exact command and result. Stop when it54 fails unless the caller explicitly accepts that known failure.553. **Review four angles.** The current Host and Model review all four angles56 directly in one pass as the standard path. When requested and supported by57 the Host, optional read-only subagents may review separate angles. Complete58 missing angles inline and record any angle that remains unreviewed. Each59 finding records `file`, `line`, a one-line summary, and its concrete cost.6061 | Angle | Look for |62 | --- | --- |63 | Reuse | New code reimplementing an existing helper or pattern |64 | Simplification | Derivable state, copy-paste variation, deep nesting, dead code |65 | Efficiency | Repeated computation/I/O, sequential independent work, retained closures |66 | Altitude | Symptom patches or special cases where shared infrastructure is the root fix |67684. **Apply safely.** Deduplicate findings at the same line or mechanism. Apply69 only behavior-preserving findings inside the resolved scope. Skip findings70 that change intended behavior, require out-of-scope files, or are false71 positives, and record each reason.725. **Handle heavy cleanup explicitly.** A file over 800 lines, cross-file73 deduplication, or a multi-module dead-code sweep needs a documented scoped74 process. Work in small, evidence-backed batches within the current scope;75 defer out-of-scope design decisions with a concrete handoff to the caller.766. **Close the loop.** Run the exact baseline test command again. A failing77 final test leaves the task incomplete and the result `BLOCKED`; do not claim78 the cleanup is safe.7980## Output8182Use the following report and record the actual execution mode:8384```markdown85## Refactoring Summary8687Execution Mode: current Host/Model single-pass | optional fan-out | mixed8889### Applied9091- [file:line] <summary> — Cost: <concrete cost> — Fix: <change>9293### Skipped9495- [file:line] <summary> — Reason: <behavior change | out of scope | false positive>9697## Test Results9899- Baseline: PASS/FAIL — `<command>`100- Final: PASS/FAIL/NOT_RUN — `<same command>`101```102103Record the reviewed angles and any missing evidence. Single-pass execution is104standard; optional fan-out supplies independent observations when used.105Return control to the caller after delivering findings and verification.106107## Verification108109- [ ] Scope resolution and fallback order are recorded; invalid explicit input110 did not silently become the current branch.111- [ ] Baseline and final use the exact same test command, with failures and112 accepted known failures stated explicitly.113- [ ] Reuse, Simplification, Efficiency, and Altitude were each reviewed, or114 each missing angle is named in incomplete evidence.115- [ ] Every applied change is behavior-preserving and in scope; every skipped116 finding has a reason.117- [ ] Heavy cleanup has a documented bounded process and deferred work is118 handed back to the caller.119120## References121122- `references/refactor-contract.md` — finding, execution, heavy-cleanup, and123 handoff details used when the inline workflow needs the extended contract.124- Native `git`, `gh`, `rg`, file reads, and the repository’s test command are125 the portable scope and verification tools.