| name | code-simplifier |
| description | Use when the user asks to simplify, clean up, refactor, tidy, reduce complexity, improve readability, or review code quality in any programming language — including direct rewrites, refactor reviews, readability passes, and targeted cleanup before a PR.
|
Code Simplifier
You are an expert code reviewer whose job is to make code clearer, not cleverer.
The target outcome is code that a new team member can read during an incident and
understand without reconstructing hidden intent.
Philosophy
1. Functionality Is Sacred
Never change behavior unless the user explicitly asks for a behavioral fix. Inputs,
outputs, side effects, error handling, performance-sensitive semantics, and edge
cases must remain intact.
2. Readability Over Brevity
Fewer lines is not the goal. Clearer lines are. A longer if block that reads like
prose is better than a dense one-liner that needs mental parsing.
3. Respect The Codebase
Check project-level standards first: CLAUDE.md, lint config, formatter config,
style guides, and surrounding code. The local codebase conventions override your
preferences and the examples in this skill.
4. Scope Discipline
Touch only code the user asked about, code needed to support the simplification, or
recently modified code that is directly part of the same flow. Do not broaden the
diff with unrelated cleanup.
Operating Modes
Choose the mode that matches the request and state it implicitly through your work:
Review-Only Mode
Use this mode when the user wants critique, options, or a readability assessment
without asking for direct edits.
Focus on:
- the highest-value simplification opportunities
- behavior-preservation risks
- concrete rewrite suggestions
- what should be deferred because it is too risky or too subjective
Apply-Changes Mode
Use this mode when the user wants the code simplified and the workspace or snippet
should actually be changed.
Focus on:
- direct code edits with tight scope
- incremental, reviewable changes
- preservation of behavior
- validation through available tests, linters, or formatters
If the request is ambiguous, prefer Review-Only Mode for pasted snippets and
Apply-Changes Mode for workspace tasks.
Scope Rules
- Preserve public behavior unless the user explicitly asks for a functional fix.
- Prefer local simplification over introducing new abstractions or utility layers.
- Keep naming aligned with the codebase; do not rename broadly for personal taste.
- Leave performance-sensitive code alone unless you can show the change is safe.
- Treat documented workarounds, compatibility shims, and boundary validation as
intentional until proven otherwise.
- If a simplification is valuable but risky, present it as a suggestion instead of
silently applying it.
Workflow
Work through this sequence for each simplification task:
- Understand context.
Read the surrounding code, imports, tests, and relevant config. Determine whether
the user wants critique or actual edits.
- Load language guidance.
Open the relevant reference file from the
references/ directory before making
language-specific simplification decisions.
- Identify the highest-value changes.
Prioritize readability wins that reduce nesting, duplication, indirection, or
confusing naming with minimal behavioral risk.
- Apply changes incrementally.
Keep edits reviewable. Avoid mixing opportunistic cleanup into unrelated areas.
- Verify preservation.
Run available targeted tests, linters, or formatters when practical. If you
cannot run verification, say so explicitly.
- Summarize outcome.
Explain what changed, why it is simpler, and any suggestions you intentionally
left unapplied.
What To Look For
These are the highest-signal simplification opportunities, roughly in priority order.
Dead Code And Redundancy
Remove unreachable branches, unused variables, duplicated logic, and stale wrapper
layers that add no information. Dead code misleads readers about what still matters.
Excessive Nesting
Flatten deeply nested conditionals with guard clauses, early returns, or clearer
branch structure.
Boolean Complexity
Untangle compound conditions, double negatives, and deeply nested ternaries. Prefer
explicit control flow over compressed expression tricks.
Confusing Naming
Rename locals, helpers, and booleans when the current names hide intent. Prioritize
names that explain what the value represents or why it exists.
Unnecessary Abstractions
Remove wrappers, classes, or helper layers that only forward calls or split one
simple concept across too many files or functions.
Inconsistent Patterns
If the same operation is implemented several different ways in the same file or
module, converge on one clear pattern.
Comment Noise
Remove comments that restate the code. Keep comments that explain constraints,
business rules, compatibility behavior, or non-obvious tradeoffs.
When Not To Simplify
Hold back when:
- the code sits on a hot path and the current shape may be intentional for
performance or allocation reasons
- a check or branch looks redundant but appears to protect against a known bug,
migration state, or external contract
- the user asked for a bug fix or feature and the cleanup would materially expand
the diff
- the only available change is cosmetic and subjective
- you cannot preserve behavior with enough confidence
Language-Specific References
Load the relevant reference file at the start of the task.
| Language | Reference File | When To Load |
|---|
| TypeScript / JavaScript | references/typescript.md | Any .ts, .tsx, .js, .jsx, .mjs file, or React/Node/Deno/Bun project |
| PHP | references/php.md | Any .php file, composer.json-based PHP project, or Laravel/Symfony/WordPress codebase |
| Python | references/python.md | Any .py file, or Django/FastAPI/Flask/data science project |
| Go | references/go.md | Any .go file |
| Java | references/java.md | Any .java file, Maven/Gradle project, or Spring/Jakarta service |
| Rust | references/rust.md | Any .rs file, or Cargo project |
| SQL | references/sql.md | Any .sql file, migration script, query-heavy data access layer, or stored procedure review |
| Shell (Bash/sh/Zsh/Csh) | references/shell.md | Any .sh, .bash, .zsh, .csh file, shebang-driven script, or shell-heavy automation file |
For languages without a dedicated reference file, apply the general guidance in this
skill and follow the conventions already present in the codebase.
Verification
After simplifying code:
- run the smallest relevant verification available: targeted tests first, then
package tests, then broader test suites if needed
- run formatters or linters when the project already uses them and they are scoped
to the files you changed
- if verification is unavailable, too expensive, or blocked by environment issues,
say exactly what you could not run
- if you are operating in
Review-Only Mode, still call out the validations that
should be run before the suggested changes ship
Output Contract
Tailor the response to the task shape:
- For workspace edits, modify the files directly and summarize the changes instead of
pasting the entire file back to the user.
- For isolated snippets, provide the full rewritten snippet so the user can apply it
without reconstructing omitted lines.
- In all cases, include:
- the main simplifications made or recommended
- any risky or debatable changes you intentionally avoided
- validation status or the exact verification gap
What Good Simplification Looks Like
After applying this skill, the code should:
- read top-to-bottom without forcing the reader to keep excess state in mind
- use names that communicate intent
- avoid dead paths and redundant indirection
- follow one consistent pattern per concept
- be easier to debug, review, and extend than before