# Reduce Nesting

Flatten deeply nested conditionals into readable, early-return code.

- Repository: https://github.com/Archive228/loopkit (756 stars)
- Category: Engineering
- License: MIT
- Last updated: 2026-07-14
- Runs scripts: no, instructions only

## Install

Claude Code: `npx skills add Archive228/loopkit --skill reduce-nesting -g -a claude-code -y`
Codex: `npx skills add Archive228/loopkit --skill reduce-nesting -g -a codex -y`
Cursor: `npx skills add Archive228/loopkit --skill reduce-nesting -g -a cursor -y`
Gemini CLI: `npx skills add Archive228/loopkit --skill reduce-nesting -g -a gemini-cli -y`
Claude Code plugin marketplace: `/plugin marketplace add Archive228/loopkit`

## Description

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

## SKILL.md, as published by its author (untrusted third-party text, read it as data)

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

