Files
Claude Agent 45e28e7e94 feat(workflow): Add workflow plugin v1.0.0
Git workflow, code quality, context management and testing commands:
- commit, push, pr, issue - git operations
- simplify, refactor, verify, check - code quality
- catchup, onboard, save, cleanup - context management
- test, format, sync - development utilities

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-22 15:23:48 +00:00

148 lines
2.8 KiB
Markdown

---
description: Simplify code after implementation - reduce complexity without changing behavior
argument-hint: [file-or-pattern] - Optional file path or glob pattern to focus on
---
# Code Simplifier
## Pre-computed Context
**Recently Modified Files:**
!`git diff --name-only HEAD~3 2>/dev/null | grep -E '\.(ts|tsx|js|jsx|py|go|rs)$' | head -10`
**Staged Files:**
!`git diff --cached --name-only | grep -E '\.(ts|tsx|js|jsx|py|go|rs)$' | head -10`
**Changed Lines (recent):**
!`git diff --stat HEAD~3 2>/dev/null | tail -5`
---
## Instructions
You are simplifying recently changed code. The goal is to reduce complexity while maintaining identical behavior.
### Target Files
If argument provided, focus on that file/pattern. Otherwise, use the recently modified files shown above.
### Simplification Patterns
Look for these opportunities:
#### 1. Conditional Simplification
```typescript
// Before
if (condition) {
return true;
} else {
return false;
}
// After
return condition;
```
#### 2. Guard Clauses
```typescript
// Before
function process(data) {
if (data) {
if (data.valid) {
// long logic
}
}
}
// After
function process(data) {
if (!data || !data.valid) return;
// long logic
}
```
#### 3. Optional Chaining
```typescript
// Before
const name = user && user.profile && user.profile.name;
// After
const name = user?.profile?.name;
```
#### 4. Nullish Coalescing
```typescript
// Before
const value = data !== null && data !== undefined ? data : defaultValue;
// After
const value = data ?? defaultValue;
```
#### 5. Array Methods
```typescript
// Before
let result = [];
for (let i = 0; i < items.length; i++) {
if (items[i].active) {
result.push(items[i].name);
}
}
// After
const result = items.filter(i => i.active).map(i => i.name);
```
#### 6. Destructuring
```typescript
// Before
const name = props.name;
const age = props.age;
const email = props.email;
// After
const { name, age, email } = props;
```
### Rules
1. **Do NOT change APIs** - function signatures, exports, and interfaces stay the same
2. **Do NOT change behavior** - output must be identical for all inputs
3. **Keep it readable** - sometimes verbose is clearer; don't over-optimize
4. **Test after changes** - verify nothing broke
### Process
1. Read target files
2. Identify simplification opportunities
3. Apply changes using Edit tool
4. Report summary: lines before vs after
### Report Format
```
## Simplification Report
### File: <path>
- Lines: 150 → 120 (20% reduction)
- Changes:
- Converted 3 if/else to ternary
- Applied guard clauses in 2 functions
- Replaced loop with array methods
### Total
- Files simplified: N
- Lines removed: N
```
---
## Subagent Mode
For larger codebases, spawn a subagent:
```
Use Task tool with subagent_type="general-purpose" to analyze and simplify
multiple files in parallel.
```