code-simplification

Refactors code to reduce complexity while preserving exact behavior and passing existing tests.

1|Updated Sep 4, 2026
One-click install
npx skills add https://github.com/SanHsien/agent-skills --skill code-simplification-sanhsien
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: code-simplification
Source: https://github.com/SanHsien/agent-skills/tree/main/skills/code-simplification
Command: npx skills add https://github.com/SanHsien/agent-skills --skill code-simplification-sanhsien

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve? Working code often accumulates unnecessary complexity—deep nesting, long functions, unclear names, and duplicated logic—that slows down every future change. This Skill provides a disciplined, behavior-preserving process for simplifying code so it is easier to read, maintain, and extend. ## Core Features & Use Cases - Behavior-Preserving Refactoring: Every simplification must keep inputs, outputs, side effects, and error behavior identical, verified by running the existing test suite after each change. - Concrete Pattern Detection: Identifies specific complexity signals such as 3+ levels of nesting, 50+ line functions, nested ternaries, boolean parameter flags, generic names, dead code, and over-engineered abstractions. - Language-Specific Guidance: Includes before/after examples for TypeScript, JavaScript, Python, and React/JSX, plus rules for following project conventions and avoiding over-simplification. - Use Case: After finishing a feature whose tests pass but whose implementation feels heavy, run this Skill to incrementally simplify the changed code—one reviewable commit at a time—without touching unrelated modules. ## Quick Start Ask the agent to simplify the recently modified code in this module while keeping all tests passing and behavior unchanged.

Frequently Asked Questions about code-simplification

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I refactor code without changing its behavior?

Make one simplification at a time and run the full test suite after each change. If tests fail, revert that change. Keep refactoring commits separate from feature or bug-fix commits so regressions are easy to isolate.

How to simplify deeply nested code and long functions?

Replace deep nesting with guard clauses and early returns, and split functions over 50 lines into smaller functions with descriptive names. Convert nested ternaries into if/else chains, switch statements, or lookup objects.

When should I not simplify or refactor code?

Avoid simplifying code you do not yet understand, performance-critical code where the simpler version is measurably slower, code about to be rewritten entirely, and code that is already clean and readable.

Does simplifying code mean fewer lines of code?

No. The goal is faster comprehension, not line count. A one-line nested ternary is harder to parse than a five-line if/else. Over-inlining and merging unrelated logic are over-simplification traps to avoid.

Should refactoring and feature changes be in the same commit?

No. Submit refactoring separately from feature or bug-fix changes. Mixed changes are harder to review, revert, and understand in history, and a PR that does both should be split into two.