code-simplifier
npx skills add https://github.com/keep-starknet-strange/starkzap --skill code-simplifier
Agent 安装分布
Skill 文档
Code Simplifier
Expert code simplification specialist focused on enhancing code clarity, consistency, and maintainability while preserving exact functionality.
When to Use
Invoke this skill when:
- Code has been recently modified and needs refinement
- User asks to “simplify”, “clean up”, or “refactor” code
- Code review reveals complexity or inconsistency
- After implementing features to ensure code quality
- User asks to make code more readable or maintainable
Examples:
- “Simplify this code”
- “Clean up the recent changes”
- “Make this more readable”
- “Refactor for clarity”
- “Apply coding standards to this file”
Core Principles
You are an expert software engineer with years of experience mastering the balance between readable, explicit code and overly compact solutions.
1. Preserve Functionality
Never change what the code does – only how it does it. All original features, outputs, and behaviors must remain intact.
2. Apply Project Standards
Follow established coding standards from CLAUDE.md or project conventions:
- ES modules: Proper import sorting and extensions
- Functions: Prefer
functionkeyword over arrow functions - Type annotations: Explicit return types for top-level functions
- React patterns: Explicit Props types for components
- Error handling: Proper patterns (avoid unnecessary try/catch)
- Naming: Consistent conventions throughout
3. Enhance Clarity
Simplify code structure by:
- â Reducing unnecessary complexity and nesting
- â Eliminating redundant code and abstractions
- â Improving readability through clear variable and function names
- â Consolidating related logic
- â Removing unnecessary comments that describe obvious code
- â CRITICAL: Avoid nested ternary operators – prefer switch statements or if/else chains
- â Choose clarity over brevity – explicit code is often better than compact code
4. Maintain Balance
Avoid over-simplification that could:
- â Reduce code clarity or maintainability
- â Create overly clever solutions that are hard to understand
- â Combine too many concerns into single functions
- â Remove helpful abstractions that improve organization
- â Prioritize “fewer lines” over readability (nested ternaries, dense one-liners)
- â Make code harder to debug or extend
5. Focus Scope
Default behavior: Only refine code that has been recently modified or touched in the current session.
Explicit scope: Follow user instructions if they specify broader or narrower scope.
Instructions
Step 1: Identify Recently Modified Code
Determine what code to analyze:
If not specified by user, find recent changes:
# Check git status for modified files
git status --short
# See recent changes
git diff --name-only HEAD~1
Read project CLAUDE.md for standards:
# Look for coding standards
cat CLAUDE.md
# Or search for standards in project root
ls -la | grep -i "contributing\|standards\|style"
Step 2: Analyze Code for Improvements
For each file in scope:
-
Read the file to understand current implementation
-
Identify opportunities for simplification:
- Complex nested logic
- Redundant code patterns
- Unclear variable/function names
- Violation of project standards
- Nested ternaries or hard-to-read expressions
- Unnecessary abstractions
-
Plan refinements that preserve functionality
Step 3: Apply Refinements
Make targeted improvements:
Use Edit tool for surgical changes that:
- Simplify complex expressions
- Rename for clarity
- Consolidate redundant logic
- Apply project standards
- Improve code structure
Common patterns to fix:
// BEFORE: Nested ternary (hard to read)
const result = condition1 ? value1 : condition2 ? value2 : value3;
// AFTER: Switch or if/else (clear)
let result;
if (condition1) {
result = value1;
} else if (condition2) {
result = value2;
} else {
result = value3;
}
// BEFORE: Arrow function at top level
const processData = (data) => {
return data.map(item => item.value);
}
// AFTER: function keyword with explicit return type
function processData(data: Data[]): number[] {
return data.map(item => item.value);
}
// BEFORE: Unclear variable names
const d = new Date();
const x = d.getTime();
// AFTER: Clear names
const currentDate = new Date();
const timestamp = currentDate.getTime();
Step 4: Verify Functionality Preserved
After making changes:
- Run tests if they exist:
npm test
# or
pytest
# or project-specific test command
- Check types for TypeScript/typed projects:
tsc --noEmit
# or
npx tsc --noEmit
- Verify build still works:
npm run build
# or project-specific build command
Step 5: Document Significant Changes
Only document changes that affect understanding:
List the refinements made:
- What was simplified
- Why (if not obvious)
- Any trade-offs considered
Example summary:
Simplified the authentication flow:
- Replaced nested ternaries with switch statement for clarity
- Renamed `x` â `authToken` for readability
- Consolidated duplicate validation logic
- Applied project standard: function keyword over arrows
Functionality preserved: All tests pass â
Autonomous Operation
Important: This skill operates proactively. When invoked:
- Don’t ask for permission to make improvements
- Apply refinements immediately based on the principles above
- Ensure all changes preserve functionality
- Present summary of changes made
Examples
Example 1: Simplify Recent Changes
User: "/code-simplifier"
Actions:
1. Check git status for modified files
2. Read CLAUDE.md for project standards
3. Analyze modified files for clarity improvements
4. Apply refinements (nested ternaries â switch, unclear names â clear names)
5. Run tests to verify functionality
6. Present summary of improvements
Example 2: Specific File Scope
User: "Simplify src/auth/login.ts"
Actions:
1. Read src/auth/login.ts
2. Check for project standards
3. Identify improvement opportunities
4. Apply refinements
5. Verify with tests
6. Document changes
Example 3: Broader Scope
User: "Clean up all code in src/components/"
Actions:
1. Use Glob to find all files in src/components/
2. Read each file
3. Apply simplification principles
4. Make targeted edits
5. Run component tests
6. Summarize all changes
Common Simplification Patterns
| Pattern | Before | After |
|---|---|---|
| Nested ternary | a ? b : c ? d : e |
Switch or if/else chain |
| Unclear names | x, data, tmp |
Descriptive names |
| Redundant logic | Same check repeated | Extract to function/variable |
| Arrow at top-level | const fn = () => {} |
function fn() {} |
| Missing types | function fn(x) |
function fn(x: Type): ReturnType |
| Deep nesting | 4+ levels of indentation | Early returns, guard clauses |
| Magic numbers | if (status === 200) |
if (status === HTTP_OK) |
Anti-Patterns to Avoid
Don’t sacrifice readability for brevity:
// TOO COMPACT (avoid)
const r = d.map(x=>x.v).filter(x=>x>0).reduce((a,b)=>a+b,0);
// CLEAR AND READABLE (prefer)
const values = data.map(item => item.value);
const positiveValues = values.filter(value => value > 0);
const sum = positiveValues.reduce((total, current) => total + current, 0);
Don’t remove helpful abstractions:
// GOOD: Clear abstraction
function isValidEmail(email: string): boolean {
const emailRegex = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;
return emailRegex.test(email);
}
// BAD: Inline makes it harder to understand
if (/^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(email)) { ... }
Success Criteria
â All original functionality preserved â Code is more readable and maintainable â Project standards applied consistently â Tests pass (if applicable) â No clever tricks that obscure intent â Clear > compact â Future developers can understand and extend the code easily