Command Palette

Search for a command to run...

UnylyUnyly
Назад к скиллам

code-simplification

БесплатноБез исполняемых скриптовНе проверен

Makes working code easier to read and change without altering what it does, and proves the behaviour stayed the same. Use when someone says "simplify this"…

TerminalSkillsот TerminalSkills★ 221 звезда на GitHub

Об этом скилле

Code Simplification

Overview

Simplifying means rewriting how code is expressed while every caller, test and user sees the same results: the same return values and types, the same errors, the same side effects in the same order. The work is a loop: pin down what the code does today, find what makes it hard to follow, apply one named refactoring, re-check, repeat.

"Simpler" means a reader has less to keep in their head: fewer branches per function, shallower nesting, fewer parameters, no names that only pass a value along, no code that never runs. Line count is not the measure. The deliverable is a set of small changes plus a report with numbers before and after and a list of everything that looked like a bug and was deliberately left as it was.

Instructions

1. Settle the scope and the safety net

Look these up in the repository first (package scripts, Makefile, pyproject.toml, CI workflow, CLAUDE.md or AGENTS.md):

  • the test, type-check and lint commands, and the lint configuration already in force
  • every caller of the code in question (language server references or a text search), and whether the name is part of a public surface: exports in package.json, __all__, an HTTP route, a CLI flag
  • the files in the current diff, when the request is "tidy what I just wrote"

Ask the user only what the repository cannot answer:

  1. Is the target this function, this file, or the whole module? (Default: the named function, or the lines of the current diff. Do not widen it on your own.)
  2. May exported names and signatures change? (Default: no.)
  3. Is any current behaviour already known to be wrong? Known bugs get reported, not preserved by accident or fixed in passing.

2. Pin the current behaviour

Run tests, type check and lint once and write down the result. If that baseline is red, stop and say so: with failures already present you cannot tell your breakage from the old one.

Then check that the lines you will touch are executed by a test:

python -m pytest tests/test_delivery.py --cov=shop.delivery --cov-report=term-missing   # needs pytest-cov
node --test --experimental-test-coverage "src/*.test.ts"

Where coverage is missing, write characterization tests before changing anything: tests that record what the code does now, right or wrong. Choose inputs on both sides of every boundary in the code, at least one invalid input, and the value types callers really pass (a form field arrives as a string). Assert on the value, its type, and for failures the exception class and message.

For a pure function the strongest net is a differential test: keep the old implementation beside the new one while you work and compare both over a grid of inputs (Example 1). For code with side effects, assert on the sequence of calls made to the existing fakes or mocks. If there is nothing to observe, shrink the scope to the parts that can be checked and say what was left out.

3. Find what makes the code hard to follow

Measure without editing the project's lint configuration:

# Python: cyclomatic complexity over 10, more than 12 branches, 50 statements, 5 arguments (ruff defaults)
ruff check --select C901,PLR0912,PLR0915,PLR0913 shop/
# Python: unused imports and variables, commented-out code, unreferenced functions
ruff check --select F401,F841,ERA001 shop/
vulture shop/ --min-confidence 60
# JavaScript / TypeScript: the same measures (ESLint's own defaults are 20, 4, 3 and 50)
npx eslint src --rule 'complexity: ["warn", 10]' --rule 'max-depth: ["warn", 3]' \
  --rule 'max-params: ["warn", 3]' --rule 'max-lines-per-function: ["warn", 50]'
# JavaScript / TypeScript: unused files, exports and dependencies
npx knip

Numbers point at candidates; reading decides. Match what you see to a refactoring from the standard catalog and check the exception before applying it:

What you see Refactoring Leave it when
Pyramid of if/else that validates input Replace Nested Conditional with Guard Clauses cleanup must run at a single exit and there is no finally, defer or context manager
The same branch shape repeated per category Replace the branches with a lookup table categories differ in logic, not only in values
One function doing several jobs in a row Extract Function, Split Phase the pieces share so much local state that each would take four or more parameters
Boolean or mode argument choosing between two behaviours Remove Flag Argument callers compute the flag at run time
Parameter that has the same value at every call site Inline the constant, drop the parameter the function is public
Class, interface or wrapper with one implementation that only forwards Inline Function, Inline Class, Remove Middle Man tests or a confirmed second implementation use the seam
Shared helper full of if kind == ... Inline it into its callers, then extract only what is truly common
Two copies of the same logic Extr
Полный SKILL.md на GitHub

Установить code-simplification в Claude Code и Claude Desktop

Зарегайся, чтобы установить скилл

Создай бесплатный аккаунт, чтобы открыть команду установки и сохранить скилл в библиотеку.

  • Открой команду установки в одну строку
  • Сохраняй скиллы в синхронизируемую библиотеку
  • Уведомления, когда скиллы обновляются
Зарегаться бесплатноУ меня уже есть аккаунт

Разрешённые инструменты

Инструменты, которые скиллу разрешено вызывать.

Без ограничений — скилл может использовать любой инструмент.

Вложенные файлы

_scores.json

FAQ

Что делает скилл code-simplification?

Makes working code easier to read and change without altering what it does, and proves the behaviour stayed the same. Use when someone says "simplify this", "clean up this function", "this file is a mess", "reduce the complexity", "refactor for readability", "tidy my diff before the PR", or when a linter reports high cyclomatic complexity or deep nesting. Covers pinning current behaviour with characterization tests, measuring complexity, choosing a named refactoring, applying it in small verified steps, and reporting suspected bugs found on the way instead of fixing them silently.

Как установить скилл code-simplification?

Скопируй папку скилла в ~/.claude/skills (вкладка Claude Code выше делает это одной командой), либо поставь как плагин.

Скилл code-simplification запускает скрипты?

Нет, скилл состоит только из инструкций (SKILL.md), без исполняемых скриптов.

Похожие скиллы

Сравнить code-simplification с