agentleFS
viksantviksant/swe-skills/skills/code-simplifier/SKILL.md

code-simplifier

Skill4 starsChanged 5 months agoMITView on GitHub

Simplifies and refines code for clarity, consistency, and maintainability while preserving all functionality. Use when: after ANY implementation/refactor, user says "simplify this", "too complex", "make it cleaner", "hard to read", "refine this code", before meticulous-code-review in post-implementation chain. NOT for: adding new functionality, fixing bugs, or making behavioral changes.

42 other projects use a version of this, 12 of them edited.

Adopted by

Most recently taken up by

Used with

Projects with it also use comment-analyzer, performance and 7 more.

Other files people use alongside this one.

Files found in the same public projects as a version of this one, more often than they turn up anywhere else. Each project counts once, large collections count for less, and this file's own repository is left out.
  • lin30Skill

    comment-analyzer

    微博评论抓取与深度分析,生成可视化HTML报告。Use when user asks to analyze weibo comments, analyze social media comments, or requests sentiment analysis from weibo posts

    Also in 3 projects that use this

  • pluginagentmarketplaceSkill

    performance

    Optimize application performance through caching strategies, load balancing, database scaling, and monitoring. Build systems handling thousands of concurrent users.

    Also in 3 projects that use this

  • AWSSkill

    setup-matt-pocock-skills

    Configure this repo for the engineering skills: set up its issue tracker, triage label vocabulary, and domain doc layout. Run once before first use of the other engineering skills.

    Also in 3 projects that use this

  • AWSSkill

    to-spec

    Turn the current conversation into a spec and publish it to the project issue tracker: no interview, just synthesis of what you've already discussed.

    Also in 3 projects that use this

  • GoogleSkill

    code-review

    Adversarial systems, concurrency, memory-model, and architecture code review protocol. Use this skill whenever asked to review code, PRs, diffs, or branches in Filament.

    Also in 9 projects that use this

  • NVIDIASkill

    deep-research

    Queue deep, multi-step research and analysis tasks to the DeepAgents worker. Supports execution depth presets, request-specific rubrics, SubAgent delegation, and RubricMiddleware cross-validation.

    Also in 3 projects that use this

  • +2 more from aws

The file

We split this skill into the rules it gives an agent

4 rules. 0 are common, 4 are distinctive, and 0 are very specific to this project.

  • 0

    Common

    Most of the 40 edited versions we read keep these.

  • 4

    Distinctive

    This author's own choices. Worth a look.

  • 0

    Very specific

    Tied to their project's names, files or tools. Probably skip.

  • Common
  • Distinctive
  • Very specific
  1. Distinctive:

    Before checking for code style issues, FIRST check for structural overengineering:

    line 87
  2. Distinctive:

    If any answer is unfavorable → SIMPLIFY.

    line 113
  3. Distinctive:

    Verify: all functionality remains unchanged

    line 219
  4. Distinctive:

    Document: only significant changes

    line 221

“Common” is measured: kept by at least 6 in 10 of the 40 edited versions of this file we could read. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
SKILL.md

Code Simplifier

Core Philosophy: "Readable, explicit code over overly compact solutions. Clarity over brevity."

Frontend (React / TypeScript / Tailwind v4)? This skill is language-agnostic. For the React/Tailwind-specific slop patterns — giant components, reinvented hooks/primitives, JS breakpoints, imperative style={{animation}}, dead @keyframes — also apply dedicated frontend clean-code guidance.

Why This Skill Exists

Even working code can be unnecessarily complex. This skill ensures code is:

  • Clear and maintainable
  • Consistent with project standards
  • Free of unnecessary complexity
  • Readable by future maintainers

The Iron Laws

1. PRESERVE FUNCTIONALITY - Never change what code does, only how
2. CLARITY OVER BREVITY - Explicit is better than compact
3. NO NESTED TERNARIES - Use if/else or switch instead
4. FOLLOW PROJECT PATTERNS - Consistency with existing code

Refinement Checklist

1. Functionality Preservation (CRITICAL)

□ All original features remain intact
□ All outputs are identical
□ All behaviors preserved
□ No side effects changed

2. Project Standards Application

□ ES modules with proper import sorting and extensions
□ Prefer `function` keyword over arrow functions
□ Explicit return type annotations for top-level functions
□ React components with explicit Props types
□ Proper error handling patterns (avoid try/catch when possible)
□ Consistent naming conventions

3. Clarity Enhancement

□ Reduced unnecessary complexity and nesting
□ Eliminated redundant code and abstractions
□ Clear variable and function names
□ Consolidated related logic
□ Removed unnecessary comments (code should be self-documenting)
□ NO nested ternary operators
□ Explicit code over dense one-liners

4. Balance Check (Avoid Over-Simplification)

□ Did not reduce code clarity
□ Did not create "clever" solutions that are hard to understand
□ Did not combine too many concerns
□ Did not remove helpful abstractions
□ Did not prioritize "fewer lines" over readability
□ Code remains easy to debug and extend

Overengineering Detection (PRIORITY CHECK)

Before checking for code style issues, FIRST check for structural overengineering:

Structural Red Flags (Fix These FIRST)

□ Class with only 1 method → Convert to function
□ Base class with only 1 subclass → Remove hierarchy, use concrete class
□ Factory that creates only 1 type → Replace with direct instantiation
□ Interface/ABC with only 1 implementation → Use concrete type
□ Registry/Plugin system for < 5 items → Use dict literal or if/else
□ Strategy pattern for 2 strategies → Use if/else or function parameter
□ Builder pattern for simple objects → Use constructor with defaults
□ Event system with 1 publisher + 1 subscriber → Direct function call
□ Config class for < 5 values → Use module-level constants
□ Generic<T> used with only 1 type → Use the concrete type
□ Service layer that just proxies to repository → Remove service, call repo directly
□ Middleware chain with 1 middleware → Direct function call
□ 3+ files created for something that fits in 1 → Merge files

The Simplicity Audit

For each abstraction found, ask:

  1. How many concrete consumers exist RIGHT NOW? (not "might exist")
  2. Is the abstraction simpler than the concrete code it replaced?
  3. Could a junior dev understand this without explanation?

If any answer is unfavorable → SIMPLIFY. Remove the abstraction.

Overengineering Fix Examples

# OVERENGINEERED: Registry pattern for 2 formatters
class FormatterRegistry:
    _formatters: dict[str, type[BaseFormatter]] = {}
    @classmethod
    def register(cls, name: str, formatter: type[BaseFormatter]):
        cls._formatters[name] = formatter
    @classmethod
    def get(cls, name: str) -> BaseFormatter:
        return cls._formatters[name]()

# SIMPLIFIED: Direct dict
FORMATTERS = {
    "json": format_as_json,
    "text": format_as_text,
}
def get_formatter(name: str):
    return FORMATTERS[name]
# OVERENGINEERED: Abstract validator hierarchy
class BaseValidator(ABC):
    @abstractmethod
    def validate(self, data: dict) -> bool: ...

class LengthValidator(BaseValidator):
    def __init__(self, max_length: int):
        self.max_length = max_length
    def validate(self, data: dict) -> bool:
        return len(data.get("text", "")) <= self.max_length

# SIMPLIFIED: Plain function
def validate_length(text: str, max_length: int) -> bool:
    """Check if text is within max length."""
    return len(text) <= max_length

Anti-Patterns to Fix

Nested Ternaries

// BAD
const result = a ? b ? 'x' : 'y' : c ? 'z' : 'w';

// GOOD
if (a) {
  return b ? 'x' : 'y';
}
return c ? 'z' : 'w';

// OR use switch for multiple conditions

Over-Compact One-Liners

// BAD - Dense and hard to read
const data = items.filter(x => x.active).map(x => ({ ...x, processed: true })).reduce((a, b) => ({ ...a, [b.id]: b }), {});

// GOOD - Clear steps
const activeItems = items.filter(item => item.active);
const processedItems = activeItems.map(item => ({ ...item, processed: true }));
const dataById = processedItems.reduce((acc, item) => {
  acc[item.id] = item;
  return acc;
}, {});

Unnecessary Abstraction

// BAD - Over-abstracted for single use
const createHandler = (fn) => (e) => fn(e.target.value);
const handleChange = createHandler(setValue);

// GOOD - Direct and clear
function handleChange(e) {
  setValue(e.target.value);
}

Arrow Functions Where Named Functions Are Clearer

// BAD - Anonymous and harder to debug
const processData = async (data) => {
  // ...
};

// GOOD - Named, clearer in stack traces
async function processData(data) {
  // ...
}

Process

  1. Identify recently modified code sections
  2. Analyze for clarity and consistency opportunities
  3. Apply project-specific best practices
  4. Verify all functionality remains unchanged
  5. Confirm refined code is simpler and more maintainable
  6. Document only significant changes

Output Format

## Code Simplification Review

### Files Analyzed
- [file1.ts]: [brief description]
- [file2.py]: [brief description]

### Simplifications Applied

**1. [Location: file:line]**
- Before: [brief description of complex code]
- After: [brief description of simplified code]
- Reason: [why this improves clarity]

**2. [Location: file:line]**
...

### Functionality Verification
- [X] All original behaviors preserved
- [X] No side effects changed
- [X] Tests still pass (if applicable)

### Summary
[Brief summary of improvements made]

Integration with Workflow

This skill runs AFTER writing code, BEFORE other reviews:

Order:

  1. Write/refactor code
  2. code-simplifier ← YOU ARE HERE (is code CLEAR?)
  3. meticulous-code-review (is code GOOD?)
  4. meticulous-code-review (does code have BUGS?)
  5. verification-before-completion (does code WORK?)

The Bottom Line

Simplify without sacrificing clarity.

  • Complex code that "works" → Simplify
  • Dense one-liners → Expand for readability
  • Nested ternaries → Convert to if/else or switch
  • Unnecessary abstractions → Remove
  • Inconsistent patterns → Align with project standards

The goal is code that future maintainers will thank you for.

Example Flow

User: "Implement the access-level resolver"
→ Claude writes implementation with nested ternary: `const level = user ? user.role === 'admin' ? 'full' : 'limited' : 'none'`
→ code-simplifier activates in post-implementation chain
→ Identifies nested ternary → converts to if/else
→ Identifies dense chained `.filter().map().reduce()` → separates into named steps
→ Verifies: all original behaviors preserved, outputs identical
→ Passes simplified code to next review step

Troubleshooting

ProblemCauseSolution
Simplification changed behaviorDidn't verify outputs matchAlways test with same inputs before and after; preserve ALL side effects
Code became harder to read after "simplifying"Over-combined logic or removed helpful abstractionBalance Check: did simplification reduce clarity? If yes, revert
Removed necessary commentAssumed code was self-documentingOnly remove comments that state WHAT; keep comments that explain WHY
Project patterns not followedDidn't check neighboring filesRead 2-3 similar files first to match conventions

Download now (ZIP)

Does it work?

Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.

No reviews yet

People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.

  • It worked
  • Partly
  • It didn't
What did you use it for? e.g. Reviewing pull requests in a Rails app

Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.

Your trail

Files you open will collect here, so you can find them again.

Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.

Now do this for your own.

Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.