agentleFS
arnabdeypolimiarnabdeypolimi/claude_code_setup/.claude/skills/code-refactor/SKILL.md

code-refactor

Skill4 starsChanged 6 months agoMITView on GitHub

Refactor Python code to match this repo's coding standards and style. Use when the user asks to "refactor", "clean up", "fix coding standards", or "apply best practices" to a module, file, or directory in this repo. Applies python-best-practices, pydantic v2, pytorch-lightning, and python-docs conventions as relevant to the target code.

16 other projects use a version of this.

Adopted by

Most recently taken up by

Used with

Projects with it also use git-doc-updater, git-precommit and 10 more.

Other files people use alongside this one.

Files found in the same public projects as a version of this one, more often than they turn up anywhere else. Each project counts once, large collections count for less, and this file's own repository is left out.
  • u9401066Skill

    git-doc-updater

    Auto-check and update key documentation before Git commits to keep docs in sync with code. Triggers: docs, 文檔, 更新文檔, sync docs, release, 發布.

    Also in 5 projects that use this

  • u9401066Skill

    git-precommit

    Orchestrate pre-commit workflow including Memory Bank sync, README/CHANGELOG/ROADMAP updates. Triggers: GIT, gc, push, commit, 提交, 準備 commit, 要提交了, git commit, pre-commit, 推送.

    Also in 5 projects that use this

  • klauswgSkill

    readme-i18n

    Use when the user wants to translate a repository README, make a repo multilingual, localize docs, add a language switcher, internationalize the README, or update localized README variants in a GitHub-style repository.

    Also in 5 projects that use this

  • GoogleSkill

    code-reviewer

    Also in 5 projects that use this

  • +8 more from u9401066

The file

We split this skill into the rules it gives an agent

3 rules. 0 are common, 2 are distinctive, and 1 is very specific to this project.

  • 0

    Common

    Most of the 9 edited versions we read keep these.

  • 2

    Distinctive

    This author's own choices. Worth a look.

  • 1

    Very specific

    Tied to their project's names, files or tools. Probably skip.

  • Common
  • Distinctive
  • Very specific
  1. Distinctive:

    Read every file in the target module.

    line 19
  2. Very specific:

    Run through references/checklist.md and note every violation.

    line 23
  3. Distinctive:

    All checks must pass before declaring done.

    line 56

“Common” is measured: kept by at least 6 in 10 of the 9 edited versions of this file we could read. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
SKILL.md

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

When to Apply Each Sub-Skill

Code containsApply
BaseModel, Pydantic fieldsreferences/pydantic-patterns.md
torch, nn.Module, LightningModulereferences/pytorch-patterns.md
Public classes / functions without docstringsreferences/docs-patterns.md
All Python filesreferences/checklist.md

Download now (ZIP)

Does it work?

Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.

No reviews yet

People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.

  • It worked
  • Partly
  • It didn't
What did you use it for? e.g. Reviewing pull requests in a Rails app

Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.

Your trail

Files you open will collect here, so you can find them again.

Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.

Now do this for your own.

Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.