MCPInstall

code-refactor

Refactor toward pure functions, immutability, composition. Use when extracting pure functions, removing side effects, replacing loops with map/filter/reduce, or separating I/O.

Installs
72
Last 24h
—
Trending rank
—
Security
Not audited

Install

Works with every agent the skills CLI supports.

npx skills add https://github.com/laurigates/claude-plugins --skill code-refactor
  1. 01

    Install

    Run the command in your project. The CLI asks which agents to install for.

  2. 02

    Describe the task

    Ask your agent for something this skill covers. It loads code-refactor automatically when relevant.

  3. 03

    Review the result

    The agent follows the SKILL.md steps, scripts and references bundled with the skill.

SKILL.md

The instructions your agent reads when the skill is triggered.

When to Use This Skill

Use this skill when...Use something else when...
A file or directory has mixed side effects and business logicDeduplicating code across files → /code:dry-consolidation
Functions mutate state or parametersDetecting code smells without fixing → /code:antipatterns
Business logic is tangled with I/O or loggingReviewing overall quality and architecture → /code:review
Imperative loops can be replaced with map/filter/reduceLarge multi-phase refactor spanning 10+ files → /workflow:checkpoint-refactor
Deep nesting obscures intent

Context

  • Target path: !echo "$1"

Parameters

  • $1: Required file path or directory to refactor

Your task

Delegate this task to the agents-plugin:refactor agent.

Use the Agent tool with subagent_type: agents-plugin:refactor to refactor the specified code. Pass all the context gathered in Context to the agent.

The refactor agent should:

  1. Identify refactoring opportunities — look for these FP code smells:

    • Side effects (mutation, I/O, logging) mixed into computation functions
    • Parameters or external state mutated in place
    • Imperative loops (for, while) that could be map, filter, reduce, or flatMap
    • Shared mutable state accessed across functions
    • Deep nesting where early returns or guard clauses would clarify intent
    • Business logic entangled with I/O at call sites
    • Duplicated transformation logic
  2. Apply functional programming principles:

    • Pure functions: Extract computation into functions with no side effects — same input always produces same output
    • Immutability: Replace in-place mutation with data transformations (spread, map, Object.assign, structural copies)
    • Composition: Build complex behavior from small, focused, single-purpose functions
    • Higher-order functions: Replace imperative loops with map, filter, reduce, flatMap, find
    • Explicit effects: Push I/O, logging, and mutations to the outermost boundary; keep inner functions pure
    • Early returns / guard clauses: Validate preconditions at the top, return early to avoid deep nesting
    • DRY / KISS: Eliminate repetition; prefer the simplest shape that works
  3. Preserve functionality:

    • Ensure all existing tests pass
    • Maintain the external API contract
    • No behavioral changes
  4. Output the refactored code with clear structure

Provide the agent with:

  • The target file or directory path
  • The detected programming language
  • Any style guide examples from the project

The agent has expertise in:

  • Behavior-preserving code transformations
  • Functional refactoring patterns
  • Code smell detection and remediation
  • Semantic code search for similar patterns

Related Skills

  • If complexity metrics needed before refactoring → /code:complexity
  • If duplicated code needs consolidation → /code:dry-consolidation
  • If linting standards not configured → /configure:linting

FAQ

What does the code-refactor skill do?

Refactor toward pure functions, immutability, composition. Use when extracting pure functions, removing side effects, replacing loops with map/filter/reduce, or separating I/O.

How do I install code-refactor?

Run npx skills add https://github.com/laurigates/claude-plugins --skill code-refactor in your project. The skills CLI detects the agents you use and copies the skill into the right folder. For Claude Code you can also place the skill folder at ~/.claude/skills/code-refactor/ (personal) or .claude/skills/code-refactor/ (project).

Which AI agents can use code-refactor?

Any agent that supports the open Agent Skills format (a folder with a SKILL.md file), including Claude Code, Codex, Cursor, GitHub Copilot, Gemini CLI, Windsurf, Cline, OpenCode and more.

Is code-refactor safe to install?

No partner security audit is available yet. Skills can run commands and scripts, so read the SKILL.md and any bundled files before installing.

Who maintains code-refactor?

It is published by laurigates in laurigates/claude-plugins. It has 72 recorded installs.

More from laurigates/claude-plugins

View all →

python-code-quality

laurigates/claude-plugins

Python code quality with ruff and ty. Use when the user mentions ruff, ty, linting, formatting, type checking, or Python code style.

1K installs

ruff-linting

laurigates/claude-plugins

Python linting with ruff. Fast linting, rule selection, auto-fixing, and config. Use when checking Python code quality, enforcing standards, or finding bugs.

466 installs

python-testing

laurigates/claude-plugins

Python testing with pytest, coverage, fixtures, and mocking. Use when the user mentions pytest, unit tests, coverage, fixtures, mocking, or writing Python tests.

Testing & QA428 installs

pytest-advanced

laurigates/claude-plugins

Advanced pytest: fixtures, markers, parametrization, parallel execution. Use when implementing test infrastructure, writing fixtures, or running with coverage.

Testing & QA352 installs

uv-workspaces

laurigates/claude-plugins

Manage multi-package Python projects with uv workspaces. Use when the user mentions uv workspaces, Python monorepo, shared lockfiles, or member dependencies.

321 installs

basedpyright-type-checking

laurigates/claude-plugins

Open the skill to read its SKILL.md instructions.

320 installs

Popular code quality & workflow skills

View category →

grill-me

mattpocock/skills

A relentless interview to sharpen a plan or design.

Scan a codebase for deepening opportunities, present them as a visual HTML report, then grill through whichever one you pick.

handoff

mattpocock/skills

Compact the current conversation into a handoff document for another agent to pick up.

domain-modeling

mattpocock/skills

Build and sharpen a project's domain model. Use when discussing codebase terminology, writing or editing a GLOSSARY.md, or recording or editing an ADR.

codebase-design

mattpocock/skills

Shared vocabulary for designing deep modules. Use when the user wants to design or improve a module's interface, find deepening opportunities, decide where a seam goes, make code more testable or AI-navigable, or when another skill needs the deep-module vocabulary.

diagnosing-bugs

mattpocock/skills

Diagnosis loop for hard bugs and performance regressions. Use when the user says "diagnose"/"debug this", or reports something broken/throwing/failing/slow.