agentleFS
rafidonerafidone/agent-skills/skills/code-simplification/SKILL.md

code-simplification

Skill1 starsChanged 21 days agoMITView on GitHub

Reduces complexity without changing observable behavior. Use when code is hard to read, duplicated, over-abstracted, or when a review asks for simplification and the existing tests must stay green.

101 other projects use a version of this.

Adopted by

Most recently taken up by

Used with

Projects with it also use performance-optimization, security-ownership-map and 8 more.

Other files people use alongside this one.

Files found in the same public projects as a version of this one, more often than they turn up anywhere else. Each project counts once, large collections count for less, and this file's own repository is left out.
  • barisariburnuSkill

    performance-optimization

    Complete performance optimization guide for Next.js applications including frontend, backend, database, caching, and general optimization strategies. Use when improving performance, reducing bundle size, optimizing queries, or implementing caching.

    Also in 51 projects that use this

  • OpenAISkill

    security-ownership-map

    Analyze git repositories to build a security ownership topology (people-to-file), compute bus factor and sensitive-code ownership, and export CSV/JSON for graph databases and visualization. Trigger only when the user explicitly wants a security-oriented ownership or bus-factor analysis grounded in git history (for example: orphaned sensitive code, security maintainers, CODEOWNERS reality checks for risk, sensitive hotspots, or ownership clusters). Do not trigger for general maintainer lists or non-security ownership questions.

    Also in 3 projects that use this

  • arkanSkill

    break-ui

    Try to break a piece of UI by feeding it worst-case data — long names, unbreakable emails, one-letter names, missing fields, huge counts, zero items, long labels, non-Latin text, emoji, extreme numbers — then render it behind a "Demo data / Worst case" toggle and report everything that broke, with the fix for each. Use when the user asks to stress-test, break, or find edge cases in a component or screen, or to "try the worst case". For visual design critique use emil-design-eng; for motion use review-animations.

    Also in 4 projects that use this

  • AJBcodingSkill

    sql-optimization-patterns

    Master SQL query optimization, indexing strategies, and EXPLAIN analysis to dramatically improve database performance and eliminate slow queries. Use when debugging slow queries, designing database schemas, or optimizing application performance.

    Also in 3 projects that use this

  • JohnJBorenSkill

    ci-cd

    CI/CD pipeline design, GitHub Actions, testing automation, and deployment strategies

    Also in 4 projects that use this

  • OpenAISkill

    security-best-practices

    Perform language and framework specific security best-practice reviews and suggest improvements. Trigger only when the user explicitly requests security best practices guidance, a security review/report, or secure-by-default coding help. Trigger only for supported languages (python, javascript/typescript, go). Do not trigger for general code review, debugging, or non-security tasks.

    Also in 4 projects that use this

The file

We split this skill into the rules it gives an agent

9 rules. 0 are common, 9 are distinctive, and 0 are very specific to this project.

  • 0

    Common

    Most of the 95 edited versions we read keep these.

  • 9

    Distinctive

    This author's own choices. Worth a look.

  • 0

    Very specific

    Tied to their project's names, files or tools. Probably skip.

  • Common
  • Distinctive
  • Very specific
  1. Distinctive:

    Use this skill when:

    line 30
  2. Distinctive:

    Do not use it for:

    line 40
  3. Distinctive:

    Run the relevant suite and record the result.

    line 54
  4. Distinctive:

    Run the tests after every step, not at the end.

    line 81
  5. Distinctive:

    When the behavior is not covered, add a characterization test first.

    line 84
  6. Distinctive:

    Prefer removing a layer to adding one.

    line 90
  7. Distinctive:

    Ask of every new abstraction: what would make this worth its indirection?

    line 93
  8. Distinctive:

    Run the full relevant suite, lint, types, and build.

    line 104
  9. Distinctive:

    No before-and-after evidence is recorded.

    line 134

“Common” is measured: kept by at least 6 in 10 of the 95 edited versions of this file we could read. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
SKILL.md

Code Simplification

Overview

Complexity is a cost paid on every future change. Simplification is the disciplined removal of that cost without changing what the code does. It is not a rewrite, and it is not an opportunity to add the feature you noticed was missing.

The test suite is the boundary. If behavior changes, even in a way that seems like an improvement, this is no longer simplification. It is a behavior change and needs its own spec and red test.

The best simplification usually deletes code. Extraction, renaming, and deduplication are tools, not goals. A new abstraction that is used once has made the code harder, not simpler.

When to Use

Use this skill when:

  • A reviewer says the change is hard to follow.
  • The same logic appears in three or more places.
  • A function is long, deeply nested, or does several unrelated things.
  • An abstraction has one caller, or its interface is harder than the code it hides.
  • Dead code, commented-out blocks, or feature flags have accumulated.
  • You are about to extend code that is already difficult to change.

Do not use it for:

  • Code you do not understand yet. Read it and add a characterization test first.
  • A module with no tests that you cannot test cheaply. Build the safety net before the refactor.
  • A rewrite of the architecture disguised as cleanup.

Related: use the test-driven-development skill to build the safety net, and the code-review-and-quality skill to review the result.

Core Process

1. Establish a green baseline

Run the relevant suite and record the result. If it is already red, stop: you cannot distinguish your regressions from the baseline. Fix or scope the baseline first.

2. Name the complexity

Be specific. "It is messy" is not actionable. Identify the move:

SmellCandidate move
Long function with mixed levels of detailExtract one behavior per function
Deep nestingEarly returns or guard clauses
Repeated conditionalsA lookup table or a named predicate
Duplicated logicExtract once, then call it
One-use abstractionInline it
Misleading nameRename it
Dead or commented-out codeDelete it
Boolean parameter that changes behaviorSplit into two functions
Mutable shared statePass the value or return a new one

3. Choose the smallest transformation

One move at a time. Do not rename, extract, and change the algorithm in the same step. Each step should be easy to review and easy to revert.

4. Refactor under green

Run the tests after every step, not at the end. If a test fails, you changed behavior; revert the step and split it.

When the behavior is not covered, add a characterization test first. It does not need to assert that the current behavior is correct, only that it is the behavior you are preserving.

5. Delete rather than add

Prefer removing a layer to adding one. A helper used once is usually noise. A config option with one value is a decision waiting to be wrong.

Ask of every new abstraction: what would make this worth its indirection? If the answer is speculative, do not add it.

6. Stop when clarity improves

Simplification has diminishing returns and a real risk of churn. When a reviewer can follow the code without explanation and the diff is small, stop. Do not reformat unrelated files.

7. Verify and report

Run the full relevant suite, lint, types, and build. Report what was removed, what was renamed, and confirm that observable behavior is unchanged.

Exit condition: the code is measurably simpler, the suite is green, and the diff contains no behavior change.

Common Rationalizations

RationalizationWhy it is wrongRequired action
"I will rewrite it properly."A rewrite changes behavior and destroys reviewability.Refactor in small, tested steps.
"It works; do not touch it."Working code can still be too expensive to change safely.Simplify only where it reduces a named cost.
"More abstraction is cleaner."Abstraction has a cost and is only worth it when it removes duplication or hides a real detail.Add an abstraction when there is a second caller or a genuine boundary.
"The tests will catch any change."Tests catch covered behavior, not everything.Add characterization tests at the boundary first.
"I will simplify and fix the bug at once."Two changes in one diff make both unverifiable.Land the behavior change first, then simplify.
"I will reformat the file while I am here."Formatting noise hides the real change.Keep formatting in a separate commit.
"Fewer lines always means simpler."Dense one-liners can be harder to read.Optimize for comprehension, not line count.
"I understand it well enough."Understanding without a test is a guess about preserved behavior.Prove it with the suite before and after.

Red Flags

  • The diff changes behavior as well as structure.
  • Tests were added after the refactor, not before.
  • The change touches files unrelated to the named complexity.
  • A new abstraction has one caller.
  • A public interface changed without a compatibility plan.
  • The baseline suite was red before the work started.
  • Formatting or renames dominate the diff.
  • The refactor is large enough that it cannot be reviewed in one sitting.
  • The code is shorter but harder to follow.
  • No before-and-after evidence is recorded.

Verification

  • The complexity being removed is named and specific.
  • The baseline suite was green and its result recorded.
  • Characterization tests cover behavior that was untested.
  • Each step changed one thing.
  • The suite stayed green after every step.
  • No observable behavior changed.
  • No new abstraction has a single caller.
  • Dead code, debug output, and commented-out blocks were removed.
  • The full relevant suite, lint, types, and build pass.
  • The diff contains no unrelated formatting or renames.

Download now (ZIP)

Does it work?

Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.

No reviews yet

People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.

  • It worked
  • Partly
  • It didn't
What did you use it for? e.g. Reviewing pull requests in a Rails app

Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.

Your trail

Files you open will collect here, so you can find them again.

Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.

Now do this for your own.

Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.