Reduce complexity
Per-line complexity reduction pass over the current branch's diff. Trigger phrases: "simplify code", "clean up", "refactor for clarity", "de-clever this", "review readability", "reduce complexity", or before opening a PR. Flattens dense expressions into boring, statement-shaped code without changing behavior. Differs from generic /simplify by targeting per-line density (ternaries, nested optional chaining, inline casts) rather than just removing lines.From its SKILL.md
npx -y skills add emiliacb/skills --skill reduce-complexityAssembled from the repository path, not quoted from the project. Check it against their README if it does not work.
One thing to look at
- 0 stars0 stars. Stars are a popularity signal and not a quality one, but at this level it is likely that nobody has read this closely except its author, and you would be relying on your own review.
SKILL.md
4.9 KB, as published. Nobody here has run it
Reduce Complexity
Not
/simplify. Claude Code already ships a native/simplifycommand that removes lines and collapses blocks. This skill does the opposite: it adds lines to flatten dense expressions. One idea per line, named intermediates, early returns. When the user says "simplify" they usually mean "make readable" — this skill handles the cases where readable means more lines, not fewer.
Reduce the complexity of each line, NOT the line count. The taste being enforced:
boring, flat, statement-shaped code. One idea per line. Named intermediates over
inline expressions. if/early-return over ternary chains. A dumb 5-line block
beats a clever 1-liner.
Phase 0 — Scope
- Get the diff:
git diff origin/main...HEAD(fall back tomain...HEAD, thenHEAD~1), plus uncommitted changes (git diff HEAD). - Only lines the branch added or changed are in scope. Pre-existing code only if the diff touched that exact statement.
- If an argument was passed (PR number, file path), review that instead.
Phase 1 — Review
Launch ONE review subagent via the Agent tool (read-only; its final message is data for you, not the user). Give it the diff scope and this hunt list:
If the harness does not support subagents (Claude Code /skills.sh without Agent tool, Pi, etc.), run the review inline yourself using the same hunt list below. The output format and rules stay identical.
- Ternaries doing too much: nested ternary chains (rewrite as keyed map, if/return helper, or switch); ternaries whose branches contain function calls, object literals, or JSX beyond a trivial expression.
- Dense expressions: multiple chained calls + optional chaining + nullish
coalescing on one line where a named intermediate would tell the reader what
the value IS; boolean conditions combining 3+ clauses inline (name the halves);
inline
ascasts patching inference instead of restructuring (prefer typed declarations/annotations). - Clever one-liners:
??=map-building,.filter(Boolean) as X[], destructure-and-rename gymnastics, expression-bodied arrows hiding side effects — where a plain loop/if/block reads faster. - Comments that don't match the code, or that explain the obvious while missing the non-obvious.
- Naming: variables in NEW code whose name forces a lookup (
result,data, baremap).
Rules the reviewer must follow (pass verbatim):
- Behavior-preserving rewrites only.
- No new abstractions, no helpers shared across files, no type refactors — statement-level restructuring within each function.
- Respect the codebase's existing idiom.
- Skip anything where the rewrite would be longer AND no clearer.
- Each finding must include: file, line, one sentence on WHAT is complex, and the EXACT paste-ready replacement.
Language-specific hunt list (TypeScript / JavaScript)
This skill was originally written for TS/JS codebases. When working in other
languages, translate the concepts: ternary chains → nested conditional
expressions, as casts → unsafe casts, ??= → default-assignment idioms,
JSX → templating logic. For a language-agnostic core, see
references/generic-hunt-list.md.
Phase 2 — Apply
- Apply each rewrite. Skip any that would change behavior or that you judge a false positive — note skips, don't argue.
- Run the project's own checks: its formatter/lint-fix command, its typechecker, and targeted tests for the touched files (discover them from CLAUDE.md or package scripts; don't guess tool names).
- Finish with a summary of applied vs skipped findings.
Worked example
Before — a repository call inside a ternary branch inside a Promise.all argument:
const [items, childCounts, siblingCounts] = await Promise.all([
repo.findItems(ids),
repo.countChildren(ids),
parentId ? repo.countSiblings(await repo.findChainRootIds(parentId)) : Promise.resolve([]),
]);
After — await the prerequisite first, name it, keep the Promise.all flat:
const chainRootIds = parentId ? await repo.findChainRootIds(parentId) : [];
const [items, childCounts, siblingCounts] = await Promise.all([
repo.findItems(ids),
repo.countChildren(ids),
repo.countSiblings(chainRootIds),
]);
Each line now holds one idea, and the intermediate's name says what the value is.
Check the callee before keeping a guard: here countSiblings already returns
empty for empty input, so no ternary is needed inside the Promise.all at all.