Agent skill
code-simplifying
Simplify and refine code for clarity, consistency, and maintainability. Use when asked to simplify code, reduce complexity, remove duplication, improve readability, refactor for clarity, or clean up messy code. Triggers on requests like "simplify this", "clean up this code", "make this more readable", "reduce complexity", or "refactor for clarity".
Install this agent skill to your Project
npx add-skill https://github.com/majiayu000/claude-skill-registry/tree/main/skills/other/code-simplifying
SKILL.md
Code Simplifying
Analyze and simplify code to improve clarity, reduce complexity, and enhance maintainability.
Process
- Identify the target code - Read the file(s) to be simplified
- Analyze complexity indicators:
- Deeply nested conditionals (>3 levels)
- Long functions (>50 lines)
- Duplicated logic
- Complex boolean expressions
- Unclear variable/function names
- Mixed concerns in single functions
- Apply simplification techniques
- Verify behavior preserved - Run tests if available
Simplification Techniques
Extract and Name
// Before: unclear intent
if (user.role === 'admin' || (user.role === 'editor' && resource.authorId === user.id)) {
// After: named condition
const canEdit = user.role === 'admin' || (user.role === 'editor' && resource.authorId === user.id);
if (canEdit) {
Early Returns
// Before: nested
function process(data) {
if (data) {
if (data.valid) {
return transform(data);
}
}
return null;
}
// After: early returns
function process(data) {
if (!data) return null;
if (!data.valid) return null;
return transform(data);
}
Extract Functions
// Before: inline logic
const articles = data.map(item => ({
id: item.id,
title: item.title.trim(),
slug: item.title.toLowerCase().replace(/\s+/g, '-'),
date: new Date(item.created_at).toISOString(),
}));
// After: extracted transformer
function toArticle(item) {
return {
id: item.id,
title: item.title.trim(),
slug: slugify(item.title),
date: formatDate(item.created_at),
};
}
const articles = data.map(toArticle);
Reduce Nesting with Object Lookups
// Before: switch statement
switch (status) {
case 'draft': return 'gray';
case 'published': return 'green';
case 'archived': return 'red';
default: return 'gray';
}
// After: object lookup
const statusColors = { draft: 'gray', published: 'green', archived: 'red' };
return statusColors[status] ?? 'gray';
Consolidate Conditionals
// Before: repeated conditions
if (type === 'image') handleImage(file);
if (type === 'video') handleVideo(file);
if (type === 'document') handleDocument(file);
// After: handler map
const handlers = { image: handleImage, video: handleVideo, document: handleDocument };
handlers[type]?.(file);
Project-Specific Patterns
For this Next.js/Cloudflare project:
- API routes: Use the auth middleware pattern consistently (
requireAdmin,requireEditor, etc.) - Database queries: Prefer parameterized queries, extract common query patterns
- React components: Keep components focused, extract hooks for shared logic
- Error handling: Use consistent error response format
{ success: false, error: string }
Output
After simplifying, provide:
- Summary of changes made
- Complexity reduction metrics (if measurable)
- Any trade-offs or considerations
Recommended Agent Skills
Expand your agent's capabilities with these related and highly-rated skills.
agent-ops-spec
Manage specification documents in .agent/specs/. Use when user provides requirements, acceptance criteria, or feature descriptions that need to be tracked and validated against implementation.
agent-ops-state
Maintain .agent state files. Use at session start, after meaningful steps, and before concluding: read/update constitution/memory/focus/issues/baseline consistently.
agent-ops-spec
Manage specification documents in .agent/specs/. Use when user provides requirements, acceptance criteria, or feature descriptions that need to be tracked and validated against implementation.
agent-ops-testing
Test strategy, execution, and coverage analysis. Use when designing tests, running test suites, or analyzing test results beyond baseline checks.
agent-ops-testing
Test strategy, execution, and coverage analysis. Use when designing tests, running test suites, or analyzing test results beyond baseline checks.
agent-ops-state
Maintain .agent state files. Use at session start, after meaningful steps, and before concluding: read/update constitution/memory/focus/issues/baseline consistently.
Didn't find tool you were looking for?