# Reduce Nesting

> Flatten deeply nested conditionals into readable, early-return code. Use on any function with 3+ levels of indentation.

- Skill: `archive228/reduce-nesting` (Agent Skill)
- Install (CLI): `npx skillmds@latest add archive228/reduce-nesting`
- Raw SKILL.md: https://api.skillmd.com/api/skills/archive228/reduce-nesting/raw
- Safety review: pending
- Works with: Claude Code, Claude.ai, OpenAI Codex
- Category: Coding & Dev Tools
- Author: archive228 (https://skillmd.com/u/archive228)
- Updated: 2026-09-17
- Page: https://skillmd.com/skills/archive228/reduce-nesting

---

# Reduce Nesting
Deep nesting hides bugs in the branches you didn't read.
- **Guard clauses** — handle the invalid/edge cases first and return early. The happy path drops to the left margin.
- **Invert conditions** — `if (!valid) return;` instead of wrapping the whole body in `if (valid) {...}`.
- **Extract** — a nested block doing one thing becomes a named function.
- **Replace flag-then-branch** — return the result directly instead of setting a variable to return later.
Target: no function deeper than 2-3 levels. If you still need more, the function is doing too much — split it.

