- Home
- Skills
- Code Quality & Review
- Code Simplification: Clarity Refactors
More screenshots
Works with the AI Agents you already use
Code Simplification: Clarity Refactors
Shrink working code into its clearest form without changing behavior: name the four kinds of mess, remove them one proven move at a time, and lock outputs, errors, and side effects.
$5
Code Simplification: Clarity Refactors
Example session with this skill installed
Simplify this pricing function. It works and its tests pass, but every change takes an hour because nobody can follow the nesting. Keep behavior exactly the same: def price(user, items, code) — items are (unit_price, quantity) pairs, members get 10% off, code "SAVE5" takes 5 off, the total never goes below zero, and empty items return 0.
- Read your context and instructions
- Compiled the code simplification
Diagnosis: knotted logic (the happy path sits three levels deep), lost meaning (t, i, and tuple indexes i[0] / i[1]), dead weight (the code != None check adds nothing the equality check does not already do). No premature machinery.
Before
def price(user, items, code):
if items:
t = 0
for i in items:
t = t + i[0] * i[1]
if user:
if user["member"] == True:
t = t * 0.9
if code != None:
if code == "SAVE5":
t = t - 5
if t < 0:
t = 0
return round(t, 2)
else:
return 0
After
def price(user, items, code):
if not items:
return 0
total = sum(unit_price * qty for unit_price, qty in items)
if user and user["member"] == True:
total *= 0.9
if code == "SAVE5":
total -= 5
return round(max(total, 0), 2)
Moves: guard clause for empty items; tuple unpacking and total for the lost meaning; the redundant None check dropped. Deliberately not changed: == True stays, because replacing it with a plain truthiness check would give the discount to members stored as a non-boolean truthy value — a behavior change, not a simplification.
Proof, before against after: empty cart → 0; plain cart [(10, 2)] → 20; member → 18.0; member with SAVE5 → 4.0 on [(10, 1)]; SAVE5 larger than the total → 0; code None → no discount. Every case matched, existing tests untouched.
Connects securely to your tools. The creator never sees your data.
About this skill
Working code gets hard to change long before it stops working. Nesting buries the main path, names stop matching what the code does, dead branches promise readers they matter, and abstractions built for a future that never arrived charge rent on every edit. This skill simplifies that code without changing its behavior. It starts by naming the mess — knotted logic, lost meaning, dead weight, or premature machinery — because each kind has a different safe move: guard clauses and shared predicates for knots, honest renames for lost meaning, caller-checked removal for dead weight, and collapsing single-use machinery back to the direct version. The protocol runs study, shrink, prove: understand what the code does, who calls it, and why it might be shaped that way before touching it; make one move at a time and run the tests after each; then prove the behavior lock held — same inputs, outputs, side effects, ordering, and errors, with existing tests passing unmodified. A move that needs a test change is reclassified as a behavior change and leaves the diff. Includes a complete worked example (nested registration validation flattened into guard clauses with every original error preserved), a plan and move-log template, a before-each-move checklist, a five-row scoring rubric with a ship threshold, edge cases such as contract names and flag-hidden code, and a pre-delivery quality gate that stops drive-by cleanups and giant rewrite commits.
Find more skills like this on the Claude Skills Marketplace, the Codex Skills Marketplace and the Gemini Skills Marketplace, or browse Claude Skills for Code Quality & Review.
- It preserves behavior, including behavior that is wrong. Bugs found while studying the code are logged as follow-ups, not fixed inside the simplification diff.
- Proof is only as strong as the tests and checks available. Code with no tests gets characterization checks first, and the skill states the remaining uncertainty instead of claiming a guarantee.
- It deliberately refuses some work: measured hot paths, generated or vendored code, code about to be rewritten, and renames of contract names such as serialized fields, which are migrations rather than simplifications.
How to use
- 1
Connect your agent to the Agensi MCP
Copy the prompt and paste it into Claude, ChatGPT, Cursor or any agent that supports MCP. It sets up the connection for you. Manual setup
- 2
Sign in to Agensi
Your agent shows a sign-in link. Sign in and click Allow.
- 3
Ask for what you need
Your agent loads this skill and uses it on your task. It always asks before buying a skill.
Reviews
No reviews yet
Be one of the first to try it. Every listed skill goes through the trust checks below.
Security scanned
Checked by our 8-point scan before listing
Fresh listing
Recently published to Agensi
Money-back guarantee
Doesn't do what its page promises? You get your money back.
Trust & safety
Security scan
Security scan passed 24 days ago
Permissions
No special permissions declared or detected