Skip to content
Back to skills

Code Refactor

ASecurity

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

  • 60 stars
  • 0 votes
  • 0 copies
  • 8 views
  • Added February 8, 2026
developmentrefactoringapi

Works with

  • api

Security analysis

A100/100

Scanned November 9, 2026

npx -y skills add laurigates/claude-plugins --skill code-refactor --agent claude-code

Installs into .claude/skills of the current project.

Are you the author of Code Refactor?

Add the live security badge to your README. It updates with every re-scan.

Security grade badge for Code Refactor
[![Security: A — Skills Directory](https://www.skillsdirectory.com/api/skills/laurigates-code-refactor/badge)](https://www.skillsdirectory.com/skills/laurigates-code-refactor)

More formats (shields.io, HTML) on the badges page. Keep it an A: scan every change in CI with Pro.

Download with Pro
SKILL.md
---
created: 2025-12-16
modified: 2026-05-09
reviewed: 2026-03-09
allowed-tools: Task, TodoWrite
args: <file-path|directory>
argument-hint: <file-path|directory>
description: Refactor toward pure functions, immutability, composition. Use when extracting pure functions, removing side effects, replacing loops with map/filter/reduce, or separating I/O.
name: code-refactor
---

## When to Use This Skill

| Use this skill when... | Use something else when... |
|------------------------|---------------------------|
| A file or directory has mixed side effects and business logic | Deduplicating code across files → `/code:dry-consolidation` |
| Functions mutate state or parameters | Detecting code smells without fixing → `/code:antipatterns` |
| Business logic is tangled with I/O or logging | Reviewing overall quality and architecture → `/code:review` |
| Imperative loops can be replaced with map/filter/reduce | Large 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](#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`

Attribution

Is this your skill, or is something wrong with this listing? Request removal or report an issue. Author removals are honored within 72 hours.

View all in development →

Comments

Loading comments…

Newsletter

Get the weekly list of safe new skills, and the ones we pulled.