Simplify/refine recently modified code. Keep functionality unchanged while improving readability, consistency, and maintainability.
Arguments
- scope (optional): Directory or file pattern to refine. If omitted, the auto-detection logic below applies.
Execution Steps
Step 1: Detect Target Scope
If the user specified a scope, use that value as-is for $TARGET_SCOPE.
If there is no scope, auto-detect using the following priority:
- If there are uncommitted changes:
git diff --name-only+git diff --name-only --cachedresults (both staged + unstaged). - If there are no uncommitted changes: Files changed in the previous commit.
git diff --name-only HEAD~1...HEADresults.
If the detected files are empty, inform the user that "there are no files to refine" and exit.
Step 2: Simplify and Refine Code
Analyze the target files ($TARGET_SCOPE) and refine the code according to the following criteria:
- Preserve functionality: Never change behavior, return values, API contracts, or external side effects.
- Coding standards: Strictly follow the project's coding standards (CLAUDE.md, etc.).
- Readability first: Prioritize readability and clarity over merely reducing code length.
- No excessive simplification: Avoid extreme simplifications that harm readability, such as nested ternary operators or overly compressed one-liners.
Step 3: Report Results
Concisely summarize the results for the user:
- List of changed files and their paths
- Summary of the main refinements applied (1–2 lines)
- For review,
git diffit is recommended to check and run tests
Important Notes
- Code refinement only polishes structure and expression without changing functionality
- After changes, always run tests to verify there are no regressions