From dx-core
Code simplification — reduce complexity while maintaining exact behavioral equivalence. Applies Chesterton's Fence (understand before changing) and Rule of 500 (replace when simpler). Use when code works but is harder to maintain than necessary.
npx claudepluginhub easingthemes/dx-aem-flow --plugin dx-coreThis skill is limited to using the following tools:
You reduce code complexity while maintaining exact behavioral equivalence. Every simplification must be proven safe by existing tests.
Simplifies code for clarity by reducing complexity while preserving exact behavior. Use when refactoring functional but hard-to-read code, during reviews, or for maintenance.
Simplifies code by removing dead code, extracting duplicates (3+ repeats), and reducing nesting (>3 levels). Runs tests before/after to preserve behavior. Ideal wrap-up refactor.
Simplifies complex/AI-generated code by removing duplication, dead code, over-engineering, and bloat patterns like verbose error handling. Use after features, on long functions (>40 lines), deep nesting (>3), or repeated patterns.
Share bugs, ideas, or general feedback.
You reduce code complexity while maintaining exact behavioral equivalence. Every simplification must be proven safe by existing tests.
Core principle: Simplification is not refactoring. Refactoring changes structure for future benefit. Simplification removes unnecessary complexity that exists right now.
BASE=$(git merge-base $(git symbolic-ref refs/remotes/origin/HEAD --short 2>/dev/null || echo origin/main) HEAD)
git diff --name-only $BASE..HEAD
Before changing ANY code, answer: Why does this complexity exist?
For each complex section:
git log --oneline -10 -- <file>If you can't explain why it's complex, don't simplify it. The complexity may be intentional — guarding against an edge case you haven't seen yet.
| Smell | Indicator | Simplification |
|---|---|---|
| Dead code | Unreachable branches, unused functions, commented-out blocks | Remove entirely |
| Unnecessary abstraction | Interface with 1 implementation, wrapper that just delegates | Inline the abstraction |
| Premature generalization | Config for values that never change, factory for 1 type | Replace with direct code |
| Over-engineering | Strategy pattern for 2 options, builder for 3 fields | Replace with simple conditional or constructor |
| Nested complexity | 4+ levels of nesting, chained ternaries | Extract to early returns or named functions |
| Flag arguments | Boolean params that change function behavior | Split into 2 clear functions |
| Zombie code | No commits in 12+ months, no clear owner, failing tests | Deprecate or remove |
Check for high-complexity areas:
# Find deeply nested code
Grep: \{.*\{.*\{.*\{ — 4+ levels of nesting
# Find long functions (>50 lines between function declaration and closing brace)
# Check manually by reading suspicious files
# Find god objects (files with >500 lines)
find . -name '*.js' -o -name '*.ts' -o -name '*.java' | xargs wc -l 2>/dev/null | sort -n -r | head -20
When evaluating whether to simplify:
This is a heuristic, not a law. Use judgment.
For each simplification:
| Pattern | Before | After |
|---|---|---|
| Early return | Deep nesting with else branches | Guard clauses at top |
| Inline trivial wrapper | function getX() { return this.x; } then obj.getX() | obj.x directly |
| Remove dead code | Commented-out blocks, unused imports | Delete entirely |
| Flatten conditionals | if (a) { if (b) { if (c) { ... }}} | if (a && b && c) { ... } |
| Replace flag with functions | process(data, true, false) | processWithValidation(data) |
| Simplify boolean | if (condition) { return true; } else { return false; } | return condition; |
## Simplification Report
**Files analyzed:** <N>
**Simplifications applied:** <N>
**Lines removed:** <N>
**Tests:** all passing (behavioral equivalence verified)
### Changes Applied
| # | File | What | Lines Removed | Risk |
|---|------|------|---------------|------|
| 1 | `file.js:42` | Removed dead code block (unreachable after L30 guard) | 15 | Low |
| 2 | `utils.js:10` | Inlined trivial wrapper (only 1 call site) | 8 | Low |
### Skipped (Chesterton's Fence)
| # | File | Complexity | Why Kept |
|---|------|------------|----------|
| 1 | `auth.js:55` | Nested try-catch with retry | Commit msg explains: "handles flaky SSO provider" |
### Opportunities for Later
- <items that need broader discussion before simplifying>
| False Logic | Reality Check |
|---|---|
| "But we might need this flexibility later" | YAGNI. You Aren't Gonna Need It. Remove it now; add it when you actually need it. |
| "The abstraction makes it testable" | If the test requires the abstraction, the abstraction is justified. If not, it's overhead. |
| "It's not hurting anything" | Dead code misleads readers, increases cognitive load, and slows grep/search results. |
| "Removing code is risky" | Keeping unnecessary code is riskier — it gets maintained, tested, and documented forever. |
| "The original author had a reason" | That's Chesterton's Fence — so investigate the reason. If the reason no longer applies, remove. |
| "Three lines is fine, no need for a function" | Correct. Three similar lines is better than a premature abstraction. Don't extract. |
/dx-simplify
Analyzes files changed since base branch, identifies complexity, applies safe simplifications.
/dx-simplify src/components/Hero.js
Deep analysis of one file for simplification opportunities.
/dx-simplify src/utils/
Scan all files in a directory for dead code, unnecessary abstractions, over-engineering.
Cause: The simplification changed behavior, not just structure. Fix: Revert the change. The complexity was protecting a behavior you didn't see.
Cause: Dynamic dispatch, reflection, or string-based references. Fix: Skip it — flag as "possibly dead, needs runtime analysis" in the report.