Claude-skill-registry code-simplifier
Code simplification skill for improving clarity, consistency, and maintainability while preserving exact behavior. Use when simplifying code, reducing complexity, cleaning up recent changes, applying refactoring patterns, or improving readability. Triggers on tasks involving code cleanup, simplification, refactoring, or readability improvements.
git clone https://github.com/majiayu000/claude-skill-registry
T=$(mktemp -d) && git clone --depth=1 https://github.com/majiayu000/claude-skill-registry "$T" && mkdir -p ~/.claude/skills && cp -r "$T/skills/data/code-simplifier-pproenca-dot-skills" ~/.claude/skills/majiayu000-claude-skill-registry-code-simplifier && rm -rf "$T"
skills/data/code-simplifier-pproenca-dot-skills/SKILL.mdCommunity Code Simplification Best Practices
Comprehensive code simplification guide for AI agents and LLMs. Contains 45 rules across 8 categories, prioritized by impact from critical (context discovery, behavior preservation) to incremental (language idioms). Each rule includes detailed explanations, real-world examples comparing incorrect vs. correct implementations, and specific impact metrics.
Core Principles
- Context First: Understand project conventions before making any changes
- Behavior Preservation: Change how code is written, never what it does
- Scope Discipline: Focus on recently modified code, keep diffs small
- Clarity Over Brevity: Explicit, readable code beats clever one-liners
When to Apply
Reference these guidelines when:
- Simplifying or cleaning up recently modified code
- Reducing nesting, complexity, or duplication
- Improving naming and readability
- Applying language-specific idiomatic patterns
- Reviewing code for maintainability issues
Rule Categories by Priority
| Priority | Category | Impact | Prefix | Rules |
|---|---|---|---|---|
| 1 | Context Discovery | CRITICAL | | 5 |
| 2 | Behavior Preservation | CRITICAL | | 6 |
| 3 | Scope Management | HIGH | | 5 |
| 4 | Control Flow Simplification | HIGH | | 7 |
| 5 | Naming and Clarity | MEDIUM-HIGH | | 5 |
| 6 | Duplication Reduction | MEDIUM | | 5 |
| 7 | Dead Code Elimination | MEDIUM | | 5 |
| 8 | Language Idioms | LOW-MEDIUM | | 7 |
Quick Reference
1. Context Discovery (CRITICAL)
- Always read CLAUDE.md before simplifyingctx-read-claude-md
- Check for linting and formatting configsctx-detect-lint-config
- Match existing code style in file and projectctx-follow-existing-patterns
- Project conventions override generic best practicesctx-project-over-generic
- Identify recently modified code as default scopectx-identify-scope
2. Behavior Preservation (CRITICAL)
- Preserve all return values and outputsbehave-preserve-outputs
- Preserve error messages, types, and handlingbehave-preserve-errors
- Preserve public function signatures and typesbehave-preserve-api
- Preserve side effects (logging, I/O, state changes)behave-preserve-side-effects
- Forbid subtle semantic changesbehave-no-semantics-change
- Verify behavior preservation before finalizingbehave-verify-before-commit
3. Scope Management (HIGH)
- Focus on recently modified code onlyscope-recent-code-only
- Keep changes small and reviewablescope-minimal-diff
- No unrelated refactorsscope-no-unrelated-refactors
- Avoid global rewrites and architectural changesscope-no-global-rewrites
- Respect module and component boundariesscope-respect-boundaries
4. Control Flow Simplification (HIGH)
- Use early returns to reduce nestingflow-early-return
- Use guard clauses for preconditionsflow-guard-clauses
- Never use nested ternary operatorsflow-no-nested-ternaries
- Prefer explicit control flow over dense expressionsflow-explicit-over-dense
- Flatten deep nesting to maximum 2-3 levelsflow-flatten-nesting
- Each code block should do one thingflow-single-responsibility
- Prefer positive conditions over double negativesflow-positive-conditions
5. Naming and Clarity (MEDIUM-HIGH)
- Use intention-revealing namesname-intention-revealing
- Use nouns for data, verbs for actionsname-nouns-for-data
- Avoid cryptic abbreviationsname-avoid-abbreviations
- Use consistent vocabulary throughoutname-consistent-vocabulary
- Avoid generic namesname-avoid-generic
6. Duplication Reduction (MEDIUM)
- Apply the rule of threedup-rule-of-three
- Avoid single-use helper functionsdup-no-single-use-helpers
- Extract only when it improves claritydup-extract-for-clarity
- Prefer duplication over premature abstractiondup-avoid-over-abstraction
- Use data-driven patterns over repetitive conditionalsdup-data-driven
7. Dead Code Elimination (MEDIUM)
- Delete unused code artifactsdead-remove-unused
- Delete code, never comment it outdead-delete-not-comment
- Remove comments that state the obviousdead-remove-obvious-comments
- Keep comments that explain why, not whatdead-keep-why-comments
- Remove stale TODO/FIXME commentsdead-remove-todo-fixme
8. Language Idioms (LOW-MEDIUM)
- Use strict types over any (TypeScript)idiom-ts-strict-types
- Use const assertions and readonly (TypeScript)idiom-ts-const-assertions
- Use ? for error propagation (Rust)idiom-rust-question-mark
- Use iterator chains when clearer (Rust)idiom-rust-iterator-chains
- Use comprehensions for simple transforms (Python)idiom-python-comprehensions
- Handle errors immediately (Go)idiom-go-error-handling
- Prefer language and stdlib builtinsidiom-prefer-language-builtins
Workflow
- Discover context: Read CLAUDE.md, lint configs, examine existing patterns
- Identify scope: Focus on recently modified code unless asked to expand
- Apply transformations: Use rules in priority order (CRITICAL first)
- Verify behavior: Ensure outputs, errors, and side effects remain identical
- Keep diffs minimal: Small, focused changes that are easy to review
How to Use
Read individual reference files for detailed explanations and code examples:
- Section definitions - Category structure and impact levels
- Rule template - Template for adding new rules
Reference Files
| File | Description |
|---|---|
| references/_sections.md | Category definitions and ordering |
| assets/templates/_template.md | Template for new rules |
| metadata.json | Version and reference information |