code-refactor

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 CodeCodex

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/arnabdeypolimi/claude_code_setup/code-refactor
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, Codex.

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. 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.00085 $0.00783
Opus 5 $0.00043 $0.00392
Sonnet 5 $0.00017 $0.00157
Haiku 4.5 $0.00009 $0.00078

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

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. yesterday 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 3mo ago), licensed MIT. It adds 85 tokens to every session and 783 once invoked, about $0.0004 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

learn-mcp

Focused interactive tutor for the Model Context Protocol (MCP) path in AI Engineering from Scratch. Start or resume this route when a learner wants to build, secure, debug, verify, or operate MCP clients, servers, transports, gateways, registries, or conformance gates. Teaches one lesson per invocation and records…

rohitg00/ai-engineering-from-scratch · 77 tokens

find-your-level

Interactive quiz that maps your AI/ML knowledge to a starting point in the 523-lesson, 20-phase AI Engineering from Scratch curriculum. Trigger phrases: "where should I start", "find my level", "what do I know", "which phase", "assess my knowledge", "placement test", "skip ahead".

rohitg00/ai-engineering-from-scratch · 71 tokens

learn-agent-skills

Focused interactive tutor for the Agent Skills Engineering path in AI Engineering from Scratch. Start or resume this route when a learner wants to create, discover, invoke, secure, evaluate, package, or port Agent Skills. Teaches one lesson per invocation and records evidence in AGENT-SKILLS-LEARNING.md.

rohitg00/ai-engineering-from-scratch · 67 tokens

start-learning

One-time onboarding for the AI Engineering from Scratch curriculum (523 lessons, 20 phases). Interviews the learner, runs the placement quiz, and writes LEARNING.md, a persistent study plan the learn skill drives. Trigger phrases: "start learning", "set up the course", "begin the curriculum", "onboard me", "create my…

rohitg00/ai-engineering-from-scratch · 74 tokens

skill-release-gate

Evaluate an Agent Skill bundle for structural integrity, trigger quality, artifact improvement, script correctness, safety, installed-tree integrity, and target-host portability before release.

rohitg00/ai-engineering-from-scratch · 36 tokens

migration-review

Review database migration files when a change adds or modifies paths under migrations/. Use it before merge to collect forward, rollback, locking, and data-safety evidence.

rohitg00/ai-engineering-from-scratch · 35 tokens