| name | simplify |
| description | Simplify and refactor code while preserving functionality and library constraints. |
| disable-model-invocation | true |
Simplify Code
Simplify and refactor $ARGUMENTS.
Simplification Principles
- Single Responsibility - 1 function = 1 thing
- Short Functions - Target under 20 lines
- Shallow Nesting - Early return, depth <= 2
- Clear Naming - Clear enough to not need comments
- Type Hints Required - On all functions
Steps
1. Analyze Target Code
- Read the file(s) to understand current structure
- Identify complexity hotspots (deep nesting, long functions)
- List functions/classes to simplify
2. Check Library Constraints
- Identify libraries used in target code
- Check constraints in
.claude/docs/libraries/
- Web search for unclear library behaviors
3. Plan Refactoring
For each complexity issue:
- What change to make
- Why it improves readability
- Verify it doesn't break library usage
4. Execute Refactoring
Apply changes following these patterns:
Early Return:
def process(value):
if value is not None:
if value > 0:
return do_something(value)
return None
def process(value):
if value is None:
return None
if value <= 0:
return None
return do_something(value)
Extract Function:
def main():
...
def main():
data = load_data()
result = process_data(data)
save_result(result)
5. Verify
Run the project's verification commands to confirm no regressions:
uv run ruff check --fix {file}
uv run ruff format {file}
pwsh -NoProfile -Command "Invoke-ScriptAnalyzer -Path '{file}' -Severity Warning,Error"
Notes
- Always preserve library features/constraints
- Web search for unclear points
- Don't change behavior (refactoring only)
- Run checks after each significant change