Code Simplification Skill#
Review recently changed code for opportunities to improve reuse, quality, and efficiency. Then apply the improvements.
Procedure#
- Identify changes:
- Run
git diff HEADto see all uncommitted changes. - If no uncommitted changes, run
git diff HEAD~1to review the last commit. - Read the changed files in full to understand context.
- Run
- Analyze for improvements:
- Duplication: Look for repeated logic that can be extracted into shared functions or utilities.
- Complexity: Identify overly nested conditionals, long functions, or convoluted control flow.
- Naming: Flag unclear variable or function names that obscure intent.
- Dead code: Find unused imports, unreachable branches, or commented-out code.
- Error handling: Check for swallowed errors, missing edge cases, or inconsistent error patterns.
- Performance: Spot unnecessary allocations, redundant computations, or missing early returns.
- Security: Identify potential injection points, unvalidated inputs, or exposed secrets.
- Prioritize:
- Fix correctness issues first.
- Then address clarity and maintainability.
- Performance last (unless a clear bottleneck).
- Apply fixes:
- Make targeted edits using the Edit tool. Do not rewrite entire files.
- Preserve existing code style (indentation, quotes, semicolons).
- Add brief comments only where the "why" is non-obvious.
- Report:
- Summarize what was changed and why.
- List any issues found but intentionally left unchanged (with reasoning).
Constraints#
- Do not change public API signatures without explicit approval.
- Do not introduce new dependencies.
- Keep refactoring scope limited to the changed files and their direct callers.