refactoring-python

refactoring-python is a skill for Claude Code, Codex from fgmacedo/agent-skills. It costs 122 tokens per session (2,623 once invoked), scanned A, original, MIT.

A set of rules and checks for restructuring existing Python code without changing what it does. It uses small, separately reviewable commits and tests to verify each structural change.

In plain words
What is it for?
It is for splitting long functions or modules, removing duplication, isolating input and output for testing, replacing Java-style designs with idiomatic Python, and judging whether an interface is unnecessarily complex.
Why use it?
It reduces the risk that cleanup accidentally changes behavior. It also keeps code organization improvements separate from new behavior and makes each step easier to review.

Skill for Claude CodeCodex

Written for no agent in particular: nothing here depends on one.

Good fit It is for splitting long functions or modules, removing duplication, isolating input and output for testing, replacing Java-style designs with idiomatic Python, and judging whether an interface is unnecessarily complex.

Compare 6 skills from other repositories ↓
Install with agentmods
npx agentmods add skills/fgmacedo/agent-skills/refactoring-python
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 fgmacedo/agent-skills --skill refactoring-python
Clone the repo
git clone --depth 1 https://github.com/fgmacedo/agent-skills

Made for: Claude Code, Codex.

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 refactoring-python

README.md
[![agentmods](https://agentmods.dev/badge/skills/fgmacedo/agent-skills/refactoring-python/github.svg)](https://agentmods.dev/skills/fgmacedo/agent-skills/refactoring-python)
Your own site
<a href="https://agentmods.dev/skills/fgmacedo/agent-skills/refactoring-python"><img src="https://agentmods.dev/badge/skills/fgmacedo/agent-skills/refactoring-python/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 refactoring-python

Your own site · 80×15
<a href="https://agentmods.dev/skills/fgmacedo/agent-skills/refactoring-python"><img src="https://agentmods.dev/badge/skills/fgmacedo/agent-skills/refactoring-python.svg" alt="Reviewed on agentmods" width="80" height="20"></a>
Per session 122 Skills are progressive disclosure: only the name and description are preloaded; the body loads when the skill is used.
When invoked 2,623 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.00122 $0.02623
Opus 5.5 $0.00049 $0.01049
Sonnet 5.5 $0.00024 $0.00525
Haiku 4.5 $0.00012 $0.00262

Measured 4d ago against content hash 79acb55461dc, method: parsed. Prices are Anthropic first-party input rates as of 2026-10-07, from the pricing page.

Security

Grade A, and why

refactoring-python 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.

The scan reads SKILL.md. This mod also ships 3 executable files (scripts/check_boundaries.py, scripts/check_commits.py, scripts/smell_census.py), listed below but not scanned — reading those needs a real analyzer, not pattern matching.

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.

skills/refactoring-python/SKILL.md · 193 lines

How it starts

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

Refactoring Python

A refactoring is done when behavior is provably unchanged, the structure is better by a named measure, and each step is a commit a reviewer can verify alone. Tidy first, then change behavior, never both in one commit (Beck). The moves are Fowler's, the patterns Kerievsky's, the idioms Ramalho's.

Do not report done until all five hold:

  1. Every commit is one named transformation and the suite is green at each one: python scripts/check_commits.py --base <sha> --test-cmd "<suite>" passes.
  2. No commit mixes structure and behavior. refactor:/tidy: commits change no assertion and add no test file; test: commits touch only tests; fix:/feat: commits carry a test that fails without them.
  3. Every function you changed was pinned first. A test: commit with a characterization test precedes the first structural commit on an untested module.
  4. Every seam is real. A dependency the domain cannot run without faking (I/O, clock, randomness) is a parameter or a port; the domain imports no I/O module; nothing abstract has fewer than two implementations unless it wraps I/O.
  5. Every idiom the user asked for covers the whole module, verified by grep or AST, and no modernization changed an exception type, an ordering, a rounding, a string format or a mutation callers rely on.

Workflow

0. Map the target

Scope (modules, callers, entry points), the test command, the baseline suite result, and the lint and type checks that must stay green. Then:

python scripts/smell_census.py PATHS            # long functions, params, nesting, god modules, I/O outside adapters, duplicates
git grep -n "patch(\|patch.object(" tests/        # mock targets that break when names move

Name what the census found with references/smells.md. Order by value to the user (the extraction, the testability, the readability they asked for); risk decides where you stop to verify, not what you do first.

1. Pin behavior before the first move

Read the full file on GitHub · 193 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 · 193 lines · 122 tokens per session scan A 79acb55461dc

Subscribe to this mod's changes

refactoring-python is a skill published in the GitHub repository fgmacedo/agent-skills (10 stars, last pushed 5d ago), licensed MIT. It adds 122 tokens to every session and 2,623 once invoked, about $0.0005 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-10-14.

Related

Other skills, from other repositories

cuga-contributor-workflows

Run CUGA contributor workflows: Conventional Commits, create pull requests against origin with gh and PR templates, and ruff check/format via uv. Use when the user says commit, create a commit, create PR, pull request, open a PR, ruff check, ruff format, or conventional commits.

cuga-project/cuga-agent · 71 tokens

marketing-council-pack-conventions

Development conventions and patterns for marketing-council-pack. Python project with conventional commits.

imMamdouhaboammar/marketing-council-pack · 25 tokens

python-modernization-sweep

Plan a Python 3 modernization sweep (f-strings, super(), type hints) as a series of mechanical PRs, not one mega-PR.

chen3feng/agent-skills · 37 tokens

marimo-pair

Work inside the user's live marimo notebook from the code editor: run Python in the same kernel the user does, inspect live notebook state, and commit durable notebook changes through code mode. Use whenever you create, analyze, or improve the user's marimo notebook.

marimo-team/marimo · 57 tokens

safety

Check secret handling, staged changes and push targets, destructive Git operations, Docker image hygiene, and new dependencies before consequential coding actions. Use for commits, pushes, container builds or publishes, dependency additions, and explicit safety reviews.

langchain-ai/deepagents · 48 tokens

python-release

Handle Python SDK release, build, bump, packaging metadata, PyPI client pin, uv.lock, nox/build workflow, and publish verification changes. Use for Python release process work or dependency pin bumps; do not use for ordinary Python feature implementation.

ComposioHQ/composio · 53 tokens