# Simplify Code

> Simplify recently changed code for clarity and maintainability while preserving behavior. Use when the user says "simplify", "simplify code", "make this simpler", "clean up", or after implementing a logical chunk.

- Skill: `majiayu000/simplify-code-2` (Agent Skill, multi-file: 2 files)
- Install (CLI): `npx skillmds add majiayu000/simplify-code-2`
- Raw SKILL.md: https://api.skillmd.com/api/skills/majiayu000/simplify-code-2/raw
- Safety review: pending
- Works with: Claude Code, Claude.ai, OpenAI Codex
- Category: Coding & Dev Tools
- Author: majiayu000 (https://skillmd.com/u/majiayu000)
- Updated: 2026-09-09
- Page: https://skillmd.com/skills/majiayu000/simplify-code-2

---


# Simplify Code

Refine code to reduce unnecessary complexity while preserving behavior.

## Scope

- Default scope is **recently modified code** in the current session (prefer `git diff` / staged changes to identify).
- Do not perform broad refactors (renaming across the repo, architecture rewrites) unless the user explicitly requests it.

## Process

1. Identify the target scope:
   - Prefer staged changes: `git diff --staged`
   - Otherwise: `git diff` or user-provided file paths
2. Establish constraints:
   - Preserve public APIs and observable behavior unless the user asks otherwise
   - Preserve performance characteristics unless improvements are explicit and verified
   - Keep changes small and reviewable (multiple small commits/patches > one large rewrite)
3. Simplify with these priorities (highest to lowest):
   - Reduce nesting and control-flow complexity (guard clauses, clearer branching)
   - Remove redundancy and dead code (duplicate logic, unused variables, unreachable branches)
   - Improve names to match intent (avoid renaming beyond the touched surface area)
   - Split overly long functions into cohesive helpers where it reduces cognitive load
   - Replace ad-hoc patterns with existing local conventions (follow `AGENTS.md` / repo style)
4. Avoid “compression” patterns that reduce readability:
   - Nested ternaries
   - Dense one-liners that hide control flow or side effects
   - Over-general abstractions introduced solely to reduce line count
5. Validate:
   - Run the narrowest available checks/tests for the modified area
   - Re-check diffs to confirm only intended files changed
6. Report:
   - Summarize the simplifications as a short list of behavioral-preserving refactors
   - Call out any remaining complexity that was intentionally left in place (and why)

## Avoid

- Nested ternaries — prefer if/else or early returns
- Dense one-liners that hide control flow or side effects
- Abstractions introduced solely to reduce line count
- Renaming beyond the touched surface area
- Changes that require updating unrelated code

## Output Format

Provide:

- **What changed**: 3-8 bullets of the key simplifications
- **Why it is simpler**: 1-2 bullets focused on reduced branching/nesting, clearer invariants, or reduced duplication
- **Verification**: commands run (or “not run”) and the reasoning

