Refactor Changes
Workflow
- •Run
git status --shortandgit diff HEAD. - •Read modified files in full to understand surrounding patterns.
- •Confirm intent from user context and current diff behavior.
- •Evaluate changes in priority order: correctness, clarity, structure, conciseness.
- •Apply minimal, behavior-preserving refactors.
Refactoring Checklist
- •Extract magic numbers/strings into named constants when it improves clarity.
- •Rename unclear identifiers to reveal intent.
- •Split large functions into focused units.
- •Remove duplication and dead code.
- •Simplify nested conditionals with guard clauses.
- •Consolidate related logic and reduce unnecessary parameters.
- •Replace redundant comments with self-documenting code.
- •Improve type annotations where ambiguity exists.
Language Guidance
Python
- •Prefer
X | NoneoverOptional[X]. - •Use context managers for resource handling.
- •Use consistent f-string formatting.
TypeScript/React
- •Remove
anywhere concrete types are available. - •Split oversized components into focused pieces.
- •Extract repeated logic into hooks/utilities only when reused.
Output Format
Use this structure:
- •Summary (1-2 sentences)
- •Refactorings (what, why, risk, and code-level change)
- •Optional Improvements (lower priority)
Notes
- •Preserve behavior; call out any non-zero risk.
- •Focus on changed code first, then adjacent cleanup.
- •For extra pattern examples, read
.claude/commands/patterns.mdif present.