refactor-decompose-function

refactor-decompose-function is a skill for Claude Code, Codex 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 CodeCodex

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

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.

agentmods
npx agentmods add skills/jimmc414/claude-code-plugin-marketplace/refactor-decompose-function
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, Codex.

Or install norvig-patterns, the plugin that ships this one along with the rest of its 33 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.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.svg" alt="Measured on agentmods" 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. Scan, not verified.
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 $0.00028 $0.00802
Opus 5 $0.00014 $0.00401
Sonnet 5 $0.00006 $0.00160
Haiku 4.5 $0.00003 $0.00080

Measured 4d ago against content hash 2727b365e575, method: parsed. Prices are Anthropic first-party input rates as of 2026-08-30, 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 4d 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. 4d 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. 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

Other skills, from other repositories

phpunit-migration-test-reviewing

Internal sub-skill. Do not auto-activate. Use only when explicitly invoked by name by another skill or agent.

shopwareLabs/ai-coding-tools · 32 tokens

phpunit-unit-test-reviewing

Internal sub-skill. Do not auto-activate. Use only when explicitly invoked by name by another skill or agent.

shopwareLabs/ai-coding-tools · 31 tokens

structuring-documentation

Use when writing, editing, auditing, splitting, or measuring Markdown documentation surfaces — README.md, AGENTS.md, CLAUDE.md, and docs/ siblings. Triggers include "is this doc too long", "split this README", "measure the docs", "where does this documentation belong", "audit the documentation", and any request to…

shopwareLabs/ai-coding-tools · 89 tokens

phpunit-integration-test-generation

Use this skill when the user asks to generate, write, or create integration tests for a Shopware 6 source class whose contract requires wired-up code — phrases like "generate integration tests for X", "write an integration test for this controller", "test this indexer", "create an integration test for the message…

shopwareLabs/ai-coding-tools · 184 tokens

phpunit-unit-test-generation

Internal sub-skill. Do not auto-activate. Use only when explicitly invoked by name by another skill or agent.

shopwareLabs/ai-coding-tools · 30 tokens

phpunit-unit-test-writing

Use this skill when the user asks to write, generate, create, or add PHPUnit unit tests for a Shopware 6 source class — phrases like "write unit tests for X", "generate tests for ClassName", "create PHPUnit tests", "add test coverage", "test this class", "cover this with tests", "I need tests for", "unit test this"…

shopwareLabs/ai-coding-tools · 187 tokens