agentleFS
gilsmtgilsmt/skills/.agents/skills/refactor/SKILL.md

refactor

Skill2 starsChanged 8 days agoMITView on GitHub

Structural refactoring and code simplification pass. Use this skill whenever the user wants to review or clean up, simplify, refactor, restructure, or improve code clarity, consistency, maintainability, or efficiency.

195 other projects use a version of this.

Adopted by

Most recently taken up by

Used with

Projects with it also use debug-fix, ascii-diagram and 10 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.
  • zebbernSkill

    debug-fix

    Find and fix a bug or issue — from any source (GitHub issue, error message, user report, or observed behavior)

    Also in 4 projects that use this

  • SethGammonSkill

    ascii-diagram

    Generate perfectly aligned ASCII diagrams — architecture, flow, sequence, box-and-arrow. Uses a programmatic character-grid approach so alignment is guaranteed by math, not token prediction. Includes post-render verification.

    Also in 4 projects that use this

  • jidechaoSkill

    modern-go

    Modernize Go code by applying version-appropriate idioms and APIs (gofix-style transformations). Scans go.mod for the Go version, then transforms Go source files to use modern patterns—from Go 1.0 through 1.26+. Use when the user says "现代化","现代Go语言", "地道的", "idiomatic", "modernize", "modern-go", "update Go code", "gofix", or wants to upgrade Go idioms.

    Also in 3 projects that use this

  • SethGammonSkill

    research-fleet

    Parallel research using Fleet wave mechanics. Spawns multiple scout agents, each investigating a different angle of the same question. Findings are compressed between waves. Produces a unified research brief from multiple independent perspectives.

    Also in 3 projects that use this

  • parcadeiSkill

    agent-context-isolation

    Agent Context Isolation

    Also in 3 projects that use this

  • parcadeiSkill

    agentica-infrastructure

    Reference guide for Agentica multi-agent infrastructure APIs

    Also in 3 projects that use this

  • +6 more from parcadei

The file

Show its rules and text

We split this skill into the rules it gives an agent

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

  • 0

    Common

    Most of the 170 edited versions we read keep these.

  • 13

    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:

    Never change what the code does — only how it does it.

    line 10
  2. Distinctive:

    Follow established coding standards from AGENTS.md and the surrounding codebase.

    line 14
  3. Distinctive:

    Avoid nested ternary operators.

    line 20
  4. Distinctive:

    Remove unnecessary comments that describe obvious code

    line 22
  5. Distinctive:

    Treat these as heuristics, not rules.

    line 27
  6. Distinctive:

    When logic is close to pure, pass its inputs explicitly and return results instead of relying on global state.

    line 31
  7. Distinctive:

    Avoid over-simplification that reduces clarity or combines too many concerns.

    line 41
  8. Distinctive:

    If reviewing recent work, run git diff (or git diff HEAD if there are staged changes) to see what changed.

    line 51
  9. Distinctive:

    If the new code creates a shared helper, verify it has real reuse and is not just extracted private logic with a vague name

    line 62
  10. Distinctive:

    Keep domain-specific logic close to its domain unless there is proven cross-domain reuse

    line 77
  11. Distinctive:

    When done, briefly summarize what was fixed or confirm the code was already clean.

    line 95
  12. Distinctive:

    Update broken references and links

    line 99
  13. Distinctive:

    Add comments only where they ensure consistency or explain non-obvious decisions

    line 100

“Common” is measured: kept by at least 6 in 10 of the 170 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

Core Principles

Preserve Functionality

Never change what the code does — only how it does it. All original features, outputs, and behaviors must remain intact. Test changes before and after cleanup.

Apply Project Standards

Follow established coding standards from AGENTS.md and the surrounding codebase. Use consistent formatting, naming conventions, and patterns. Prefer explicit, readable code over compact or clever solutions.

Enhance Clarity

Simplify structure by reducing unnecessary complexity and nesting. Eliminate redundant code and abstractions. Consolidate related logic. Choose clarity over brevity — explicit code is easier to reason about and maintain.

  • Avoid nested ternary operators; prefer early returns, switch statements, or if/else chains
  • Break overly compact chains into named intermediate steps
  • Remove unnecessary comments that describe obvious code
  • Declare variables at the smallest possible scope

Simplify Function Boundaries

Treat these as heuristics, not rules. Preserve behavior and keep a function when its boundary makes the code clearer.

  • Inline a helper used from one place. When work repeats across callers, first see whether the callers can share one path, perhaps through a small option or defaulted parameter, then inline the duplicate logic.
  • Combine near-identical variants with meaningful parameters. Avoid flag-heavy functions that obscure distinct behavior.
  • When logic is close to pure, pass its inputs explicitly and return results instead of relying on global state.
  • For a shared function, use const-qualified inputs and methods where the language supports them and the function's contract allows it.
  • Reduce branching and nesting. Prefer a consistent execution path when its extra work is minor; keep guards or fast paths when the avoided work matters.

Remove Duplication

Find duplicate code and consolidate it where a shared path is clearer in the adequate domain boundary. Repeated work should often go through one function or utility; a helper used from only one place should usually be inlined. Identify repeated patterns across files, and extract shared abstractions only when there is real cross-domain reuse. Merge similar configuration or setup instructions.

Maintain Balance

Avoid over-simplification that reduces clarity or combines too many concerns. Do not remove helpful abstractions that improve organization. Prioritize readability over line count.

Workflow

Scope

Focus only on the specified file(s) or directory. Do not make changes outside the target area unless duplication requires extracting a shared utility to an appropriate common location.

Phase 1: Identify Changes

If reviewing recent work, run git diff (or git diff HEAD if there are staged changes) to see what changed. If there are no git changes, review the most recently modified files or PR the user mentioned, or that were edited earlier in the conversation.

Phase 2: Launch Three Review Agents in Parallel

Analyze the code from three angles. Use the Task tool to launch all three agents concurrently in a single message. Pass each agent the relevant files so it has the complete context.

Agent 1: Code Reuse Review

  1. Search for existing utilities and helpers that could replace newly written code. Look for similar patterns elsewhere in the codebase — common locations are utility directories, shared modules, and files adjacent to the changed ones.
  2. Flag any new function that duplicates existing functionality. Suggest the existing function to use instead.
  3. Flag any inline logic that could use an existing utility — hand-rolled string manipulation, manual path handling, custom environment checks, ad-hoc type guards, and similar patterns are common candidates.
  4. If the new code creates a shared helper, verify it has real reuse and is not just extracted private logic with a vague name

Agent 2: Code Quality Review

Review the relevant file(s) for hacky patterns:

  1. Redundant state: state that duplicates existing state, cached values that could be derived, observers/effects that could be direct calls
  2. Parameter sprawl: adding new parameters to a function instead of generalizing or restructuring existing ones; too many parameters suggest the boundary is wrong
  3. Copy-paste with slight variation: near-duplicate code blocks that should be unified with a shared abstraction
  4. Leaky abstractions: exposing internal details that should be encapsulated, or breaking existing abstraction boundaries
  5. Stringly-typed code: using raw strings where constants, enums (string unions), or branded types already exist in the codebase
  6. Unnecessary JSX nesting: wrapper Boxes/elements that add no layout value — check if inner component props (flexShrink, alignItems, etc.) already provide the needed behavior
  7. Single-use helpers: helpers called from one place that would read better inlined, or duplicated work that should share one path
  8. Near-identical variants: function variants that differ by a flag or small branch and could combine with a meaningful parameter; flag-heavy functions that obscure distinct behavior
  9. Hidden inputs: helpers that read or mutate global state when explicit inputs and return values would keep them predictable
  10. Keep domain-specific logic close to its domain unless there is proven cross-domain reuse

Agent 3: Efficiency Review

Review the relevant file(s) for efficiency:

  1. Unnecessary work: redundant computations, complexity, repeated file reads, duplicate network/API calls, N+1 patterns
  2. Missed concurrency: independent operations run sequentially when they could run in parallel
  3. Hot-path bloat: new blocking work added to startup or per-request/per-render hot paths
  4. Recurring no-op updates: state/store updates inside polling loops, intervals, or event handlers that fire unconditionally — add a change-detection guard so downstream consumers aren't notified when nothing changed. Also: if a wrapper function takes an updater/reducer callback, verify it honors same-reference returns (or whatever the "no change" signal is) — otherwise callers' early-return no-ops are silently defeated
  5. Unnecessary existence checks: pre-checking file/resource existence before operating (TOCTOU anti-pattern) — operate directly and handle the error
  6. Memory: unbounded data structures, missing cleanup, event listener leaks
  7. Overly broad operations: reading entire files when only a portion is needed, loading all items when filtering for one

Phase 3: Fix Issues

Aggregate findings and fix each issue directly. If a finding is a false positive or not worth addressing, note it and move on — do not argue with the finding, just skip it. Verify nothing breaks during removal or consolidation.

When done, briefly summarize what was fixed or confirm the code was already clean.

Documentation Cleanup

  • Update broken references and links
  • Add comments only where they ensure consistency or explain non-obvious decisions

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.