code-refactor

code-refactor is a skill for Claude Code from arnabdeypolimi/claude_code_setup. It costs 85 tokens per session (783 once invoked), scanned A, original, MIT.

A code-review and cleanup workflow for Python files that checks them against the repository’s coding rules and conventions.

In plain words
What is it for?
Use it to refactor or clean up a Python module, file, or directory, including code that uses Pydantic or PyTorch Lightning.
Why use it?
It helps find style, typing, documentation, and error-handling problems systematically instead of fixing them one by one without a shared standard.

Skill for Claude Code

Written for Claude Code: installed under .claude/.

Good fit Use it to refactor or clean up a Python module, file, or directory, including code that uses Pydantic or PyTorch Lightning.

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

Made for: Claude Code.

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 code-refactor

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

Your own site · 80×15
<a href="https://agentmods.dev/skills/arnabdeypolimi/claude_code_setup/code-refactor"><img src="https://agentmods.dev/badge/skills/arnabdeypolimi/claude_code_setup/code-refactor.svg" alt="Reviewed on agentmods" width="80" height="20"></a>
Per session 85 Skills are progressive disclosure: only the name and description are preloaded; the body loads when the skill is used.
When invoked 783 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.00085 $0.00783
Opus 5.5 $0.00034 $0.00313
Sonnet 5.5 $0.00017 $0.00157
Haiku 4.5 $0.00009 $0.00078

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

Security

Grade A, and why

code-refactor 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 1mo 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.

.claude/skills/code-refactor/SKILL.md · 83 lines

How it starts

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

Code Refactor Skill

Systematically refactor Python code to match this repo's standards.

Workflow

1. Read Target Code

Read every file in the target module. Never propose changes to code you haven't read.

2. Audit Against Checklist

Run through references/checklist.md and note every violation. Group them by category so the user can see the full picture before any edits are made.

3. Run Static Analysis

uv run ruff check <target>
uv run mypy <target>

Report all errors as part of the audit — these are additional violations on top of the checklist.

4. Apply Fixes

Apply all fixes. Prefer the Edit tool over Write for existing files (smaller diffs, easier review). Make all independent edits in parallel.

Priority order (highest impact first):

  1. Type safety — enums over bare strings, from __future__ import annotations, proper return types
  2. Pydantic — snake_case fields with aliases, model_config, field validators (see references/pydantic-patterns.md)
  3. Error handling — replace assert with if/raise, add context to re-raised exceptions
  4. Python best practices — frozen dataclasses, Protocol types, avoid mutable defaults
  5. PyTorch/Lightning — only apply if the module contains torch or nn.Module code (see references/pytorch-patterns.md)
  6. Docs — public functions must have docstrings (see references/docs-patterns.md)

5. Verify

uv run ruff check <target>
uv run ruff format <target>
uv run mypy <target>
uv run pytest tests/unit/<target-name>/ -v

All checks must pass before declaring done. If tests fail, fix them — don't skip.

6. Summarise

Report a table of every change made, grouped by category. Include file and line references.


Repo-Specific Conventions

  • Python: 3.12 — use StrEnum, match, X | Y unions, from __future__ import annotations in every file
  • Linter/Formatter: Ruff (88 char line length)
  • Type checker: mypy (strict — all errors must be resolved)
  • Package manager: uv (uv run <cmd>)
  • Tests: pytest, mirror source structure under tests/unit/
  • Logging: from logging_utils import get_logger then logger = get_logger(__name__) — never logging.getLogger(__name__) or print()
  • Imports: stdlib → third-party → local, each group separated by blank line
  • Config: TOML or YAML only — never JSON for config files

Read the full file on GitHub · 83 lines

Files

What ships with it

4 files beside SKILL.md in the same directory: the scripts, references and assets a skill reads on demand. Not counted in the per-session cost; read them before you install if any of them is executable.

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. 1mo ago First seen · 83 lines · 85 tokens per session scan A f8943f59b0dd

Subscribe to this mod's changes

code-refactor is a skill published in the GitHub repository arnabdeypolimi/claude_code_setup (4 stars, last pushed 1mo ago), licensed MIT. It adds 85 tokens to every session and 783 once invoked, about $0.0003 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

Other skills, from other repositories

py-reviewer

Review selected Python code for typing, async and exception behavior, resource ownership, data access, framework boundaries, and concrete contract defects in the project's actual runtime.

RaNDoM6913/claude-code-superkit · 35 tokens

ha-dev-workflow-apply

Applies and validates the HA code-style / strict-typing / validation workflow (spec/ha/dev-workflow) against an existing HA Custom Integration — Ruff format, ordered imports, f-strings (logging excepted), file-header docstrings, full type annotations, a local mypy-strict profile as the platinum strict-typing bridge…

nolte/claude-home-assistant · 212 tokens

clean-code-python

Use when writing or reviewing Python — deeper idioms (type hints, dataclasses/pydantic, no mutable defaults, EAFP, pathlib, context managers, comprehensions).

CassetteTapeCrackle/claude-starters · 39 tokens

django-testing

Django testing discipline — TDD workflow for Django/DRF (RED-GREEN-REFACTOR against models, views, serializers, permissions), pytest-django and factory patterns, database and transaction handling in tests, API client testing, AND the verification gates a Django change must pass before it ships (migrations check…

Nmor/the-claude-council · 91 tokens

python-patterns

Pythonic idioms, PEP 8 standards, type hints, and best practices for building robust, efficient, and maintainable Python applications.

Nmor/the-claude-council · 33 tokens

python-anti-patterns

Use this skill when reviewing Python code for common anti-patterns to avoid. Use as a checklist when reviewing code, before finalizing implementations, or when debugging issues that might stem from known bad practices.

FluxonLab/Skillry · 46 tokens