# Reduce Nesting

> Reduce Nesting is an Agent Skill for development published in the Archive228/loopkit repository on GitHub: a SKILL.md instruction file an AI agent can load to do this task.

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

- Skill name: `reduce-nesting`
- Category: [Development](https://www.openparable.com/skill/development/1)
- Source: https://github.com/Archive228/loopkit/blob/HEAD/skills/reduce-nesting/SKILL.md
- Repository: Archive228/loopkit (638 GitHub stars when collected)

## SKILL.md

# 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.

---

Source: https://www.openparable.com/skill/development/reduce-nesting (OpenParable). Cite the canonical URL above.
