refactor-decompose-function

refactor-decompose-function is a skill for Claude Code from jimmc414/claude-code-plugin-marketplace. It costs 28 tokens per session (802 once invoked), scanned A, original, MIT.

A code-refactoring guide for splitting long or deeply nested functions into smaller helper functions. Refactoring means changing code structure without changing what it does.

In plain words
What is it for?
Use it to separate validation, transformation, summarising, or other clear stages inside an overgrown function.
Why use it?
It makes complicated functions easier to read and lets each part be tested independently when the function contains several distinct jobs.

Skill for Claude Code

Written for Claude Code: shipped in a Claude Code plugin.

Part of the norvig-patterns plugin — 54 skills shipped together

Good fit Use it to separate validation, transformation, summarising, or other clear stages inside an overgrown function.

Compare 6 skills from other repositories ↓
Install with agentmods
npx agentmods add skills/jimmc414/claude-code-plugin-marketplace/refactor-decompose-function
Install

Getting it into your agent

One page per mod, every tool's command on it. A separate URL per tool would split the same page into five that compete with each other.

Any agent
npx skills add jimmc414/claude-code-plugin-marketplace --skill refactor-decompose-function
Clone the repo
git clone --depth 1 https://github.com/jimmc414/claude-code-plugin-marketplace

Made for: Claude Code.

Or install norvig-patterns, the plugin that ships this one along with the rest of its 54 skills.

Wrote this? Show the measurements

A badge with what this costs and how it scanned, read live from this page, so it follows the numbers instead of freezing them. Markdown for a README, HTML for a documentation site or a project page.

agentmods badge for refactor-decompose-function

README.md
[![agentmods](https://agentmods.dev/badge/skills/jimmc414/claude-code-plugin-marketplace/refactor-decompose-function/github.svg)](https://agentmods.dev/skills/jimmc414/claude-code-plugin-marketplace/refactor-decompose-function)
Your own site
<a href="https://agentmods.dev/skills/jimmc414/claude-code-plugin-marketplace/refactor-decompose-function"><img src="https://agentmods.dev/badge/skills/jimmc414/claude-code-plugin-marketplace/refactor-decompose-function/github.svg" alt="Measured on agentmods" height="20"></a>

Or the 80×15 button, for a site that already has a row of RSS and ATOM ones. Only the verdict fits; the numbers stay here.

agentmods 80×15 button for refactor-decompose-function

Your own site · 80×15
<a href="https://agentmods.dev/skills/jimmc414/claude-code-plugin-marketplace/refactor-decompose-function"><img src="https://agentmods.dev/badge/skills/jimmc414/claude-code-plugin-marketplace/refactor-decompose-function.svg" alt="Reviewed on agentmods" width="80" height="20"></a>
Per session 28 Skills are progressive disclosure: only the name and description are preloaded; the body loads when the skill is used.
When invoked 802 The whole file, excluding the scripts and references it only reads on demand.
Security scan A 0 findings. A grade says what 26 rules found in the file — not that it is safe.
Origin original No closer match found in the catalogue.
Token cost

What it costs to keep this loaded

Counted locally with the o200k_base tokenizer, which is exact for GPT models; Claude uses its own tokenizer and its counts differ. Treat this as one consistent yardstick across the catalogue rather than a bill. Prices are per million input tokens.

ModelPer sessionOnce invoked
Fable 5.1 $0.00028 $0.00802
Opus 5.5 $0.00011 $0.00321
Sonnet 5.5 $0.00006 $0.00160
Haiku 4.5 $0.00003 $0.00080

Measured 3mo ago against content hash 2727b365e575, method: parsed. Prices are Anthropic first-party input rates as of 2026-10-07, from the pricing page.

Security

Grade A, and why

refactor-decompose-function scanned grade A with 0 findings against 26 rules in 11 categories — prompt injection, anti-refusal, data exfiltration, privilege escalation, supply chain, agent snooping, system-prompt leakage, SSRF and excessive agency — measured 3mo ago.

A static scan of the body, not an audit. Every finding is printed with the line that produced it so you can judge whether it matters here. A mod is markdown that instructs an agent; that is exactly why what it instructs is worth reading.

Nothing flagged

None of the 26 patterns this scan looks for appear in this file: no shell pipes, no recursive deletes, no credential paths, no hidden text, no instruction-override or anti-refusal phrasing, no agent-config snooping. That is not a guarantee, it is the absence of the things that are checkable.

plugins/norvig-patterns/skills/refactor-decompose-function/SKILL.md · 103 lines

How it starts

The opening of the file, as written. The whole thing — 103 lines — stays where its author put it; the contents beside it link to each section on GitHub.

refactor-decompose-function

When to Use

  • Function is longer than 10-15 lines
  • Multiple levels of nesting
  • Hard to understand at a glance
  • Difficult to test parts independently
  • Code has natural "chunks" with different purposes

When NOT to Use

  • Function is already simple and clear
  • Decomposition would obscure the algorithm
  • Helpers would only be used once with no clarity gain

The Pattern

Extract cohesive chunks into named helper functions. Each function should do one thing.

# BEFORE: Long, hard to test
def process_data(data):
    # Validate
    if not data:
        raise ValueError("Empty data")
    if not all(isinstance(x, int) for x in data):
        raise TypeError("Non-integer data")

    # Transform
    result = []
    for x in data:
        if x > 0:
            result.append(x * 2)
        else:
            result.append(0)

    # Summarize
    total = sum(result)
    avg = total / len(result)
    return {'data': result, 'total': total, 'average': avg}

# AFTER: Decomposed, each part testable
def process_data(data):
    validate(data)
    transformed = transform(data)
    return summarize(transformed)

def validate(data):
    if not data:
        raise ValueError("Empty data")
    if not all(isinstance(x, int) for x in data):
        raise TypeError("Non-integer data")

def transform(data):
    return [x * 2 if x > 0 else 0 for x in data]

def summarize(data):
    total = sum(data)
    return {'data': data, 'total': total, 'average': total / len(data)}

Example (from pytudes)

# Spelling correction (spell.py) - beautifully decomposed
def correction(word):
    """Most probable spelling correction for word."""
    return max(candidates(word), key=P)

def candidates(word):
    """Generate possible spelling corrections for word."""
    return known([word]) or known(edits1(word)) or known(edits2(word)) or [word]

def known(words):
    """The subset of words that appear in the dictionary."""
    return set(w for w in words if w in WORDS)

def edits1(word):
    """All edits one edit away from word."""
    letters = 'abcdefghijklmnopqrstuvwxyz'
    splits = [(word[:i], word[i:]) for i in range(len(word) + 1)]
    deletes = [L + R[1:] for L, R in splits if R]
    transposes = [L + R[1] + R[0] + R[2:] for L, R in splits if len(R) > 1]
    replaces = [L + c + R[1:] for L, R in splits if R for c in letters]
    inserts = [L + c + R for L, R in splits for c in letters]
    return set(deletes + transposes + replaces + inserts)

def edits2(word):
    """All edits two edits away from word."""
    return (e2 for e1 in edits1(word) for e2 in edits1(e1))

Read the full file on GitHub · 103 lines

Changes

What this file has done since we first saw it

Hashed on every crawl. A supply-chain change to an agent config is a question of when, not whether, so the history is kept rather than the latest state alone.

  1. 3mo ago First seen · 103 lines · 28 tokens per session scan A 2727b365e575

Subscribe to this mod's changes

refactor-decompose-function is a skill published in the GitHub repository jimmc414/claude-code-plugin-marketplace (4 stars, last pushed today), licensed MIT. It adds 28 tokens to every session and 802 once invoked, about $0.0001 per session on Opus 5.5. A static security scan graded it A with 0 findings. No closer match exists in the catalogue, so it is treated as the original; first seen 2026-08-31.

Related

refactor-decompose-function compared with skills from other repositories

refactor-decompose-function next to 6 skills from other repositories
ModTypeStarsLast pushLicenceScanTokensWorks with
refactor-decompose-functionjimmc414/claude-code-plugin-marketplaceSkill4todayMITA28Claude Code
codexmelodic-software/claude-code-pluginsSkill34todayMITA75Claude Code
code-reviewmelodic-software/claude-code-pluginsSkill34todayMITA63Claude Code
fanoutmelodic-software/claude-code-pluginsSkill34todayMITA24Claude Code
morning-briefmelodic-software/claude-code-pluginsSkill34todayMITA152Claude Code
phpunit-test-reconcilingshopwareLabs/ai-coding-toolsSkill484d agoMITA32Claude Code
usemelodic-software/claude-code-pluginsSkill34todayMITA183Claude Code