Source profileQuality 94/100

event4u-app/agent-config/src/skills/code-refactoring/SKILL.md

code-refactoring

When the user says 'refactor this', 'rename class', or 'move method'. Safely refactors code in any language — finds all callers, updates downstream dependencies, verifies via quality tools.

Source repository stars
9
Declared platforms
0
Static risk flags
1
Last source update
2026-08-28
Source checked
2026-08-28

Decision brief

What it does: where it fits

When the user says 'refactor this', 'rename class', or 'move method'. Safely refactors code in any language — finds all callers, updates downstream dependencies, verifies via quality tools.

Best for

  • New feature development (use feature-planning skill)
  • Bug fixes that don't involve restructuring (use bug-analyzer skill)

Not for

  • Tasks that require unconfirmed production actions or broad system permissions.
  • Environments where the pinned source and install steps cannot be inspected.

Compatibility matrix

Platform support, with evidence labels

PlatformStatusEvidenceWhat to check
CodexNot declaredNo explicit evidencePortability before use
Claude CodeNot declaredNo explicit evidencePortability before use
CursorNot declaredNo explicit evidencePortability before use
Gemini CLINot declaredNo explicit evidencePortability before use
Open the compatibility checker

Installation

Inspect first. Install second.

The source command is displayed only when detected. A safe inspection prompt is always available so your agent can explain every action before execution.

Source-detected install commandSource
npx skills add https://github.com/event4u-app/agent-config --skill "src/skills/code-refactoring"
Safe inspection promptEditorial

Inspect the Agent Skill "code-refactoring" from https://github.com/event4u-app/agent-config/blob/6a5670b7881a676c0da90d2afb950298087c4ccb/src/skills/code-refactoring/SKILL.md at commit 6a5670b7881a676c0da90d2afb950298087c4ccb. List every install step, command, network request, credential, file read/write, external action, and rollback step. Explain whether it fits my task. Do not install or execute anything until I approve.

Workflow

What the source asks the agent to do

  1. 01

    Procedure: Refactor code

    For each affected file (from the impact analysis):

    Rename, extract, move, or restructure the target code.Keep the change minimal and focused.Callers: Update method calls, constructor arguments, imports.
  2. 02

    Step 1: Make the core change

    Rename, extract, move, or restructure the target code.

    Rename, extract, move, or restructure the target code.Keep the change minimal and focused.- Rename, extract, move, or restructure the target code. - Keep the change minimal and focused.
  3. 03

    Step 2: Update all downstream dependencies

    For each affected file (from the impact analysis):

    Callers: Update method calls, constructor arguments, imports.Interfaces / abstract methods: Update all implementations to match new signatures.Subclasses: Update overridden methods.
  4. 04

    Step 3: Update API layer (if request handlers / endpoints are affected)

    When refactoring touches handlers, route registrations, request validators, or response shapers, walk the stack-appropriate boundary. Use the carve-out skill for the project's framework if one exists; otherwise consult the table below for what to check on each stack.

    Laravel: laravel-api-endpointNext.js: nextjs-patternsSymfony: symfony-workflow
  5. 05

    Step 4: Update tests — with user approval

    Before changing any test, present a summary to the user:

    List all affected tests — which test files and which test cases need changes.Describe what changes — for each test, explain what assertion/setup changes and why.Classify the change:

Permission review

Static risk signals and limitations

Reads files

low · line 17

The documentation asks the agent to read local files, directories, or repositories.

For modules, also read the project's module-docs directory (path varies by stack — Laravel: `app/Modules/{Module}/agents/`; Nx: `apps/{app}/docs/`; mono-repo: per-package `docs/`). See the `project-docs` skill for the mapping.

Evidence record

Why each signal appears

EvidenceSourceComputedTestedEditorial
SignalValueEvidence typeMeaning
Quality score94/100ComputedDocumentation, specificity, maintenance, and trust rules
Repository stars9SourceRepository attention, not individual Skill quality
Compatibility0 platformsSourceDeclared in the catalog source record
Usage guideautomated source guideEditorialGenerated or reviewed according to the visible evidence level

Pinned source

Provenance and original SKILL.md

Repository
event4u-app/agent-config
Skill path
src/skills/code-refactoring/SKILL.md
Commit
6a5670b7881a676c0da90d2afb950298087c4ccb
License
MIT
Collected
2026-08-28
Default branch
main
View the original SKILL.md

refactorer

When to use

Use this skill when renaming, moving, extracting, or restructuring code — any change that may have downstream effects on callers, interfaces, tests, documentation, or API contracts.

Do NOT use when:

  • New feature development (use feature-planning skill)
  • Bug fixes that don't involve restructuring (use bug-analyzer skill)

Before refactoring

  1. Read the agent docs — check agents/reference/docs/ and agents/settings/contexts/ for the area you're refactoring. For modules, also read the project's module-docs directory (path varies by stack — Laravel: app/Modules/{Module}/agents/; Nx: apps/{app}/docs/; mono-repo: per-package docs/). See the project-docs skill for the mapping.
  2. Understand the scope — what exactly needs to change and why?
  3. Find ALL references — use codebase-retrieval and view with search_query_regex to find every caller, implementation, test, and configuration that references the code being changed. If the change is to a closed set — an enum, union, literal type, state machine, role or permission set — identifier search is not enough: the consumers that break are the ones that never name the type. Search by shape as well (switch / match / if-chains over it, lookup tables keyed by it, validators, serializers, schemas, fixtures, translation keys) and classify each as exhaustive, deliberate fallback, or missing case. Procedure: downstream-changes-mechanics.
  4. Map the impact — create a list of all files that will need changes.
  5. Decide the verdict, if the refactor is a de-duplication — see the safe-abstraction gate below. An extraction with no recorded verdict is a guess about whether two things are the same thing.
  6. Present the plan — show the user what will be affected before starting.

Safe-abstraction gate — before merging two things into one

This skill performs extractions; it is therefore the place that decides whether one should happen. A wrong abstraction costs more than the duplication it replaced, because the duplication is visible and the wrong abstraction grows caller flags until nobody can remove it. Ask, before moving any code:

  1. Is this the same knowledge, or two facts that currently look alike?
  2. Would both copies change for the same reason?
  3. Is there one honest domain name that fits every call site?
  4. Can the common core stay free of caller-specific flags and modes?
  5. Are public contracts preserved, and do tests prove behavioural equivalence?
  6. If the two copies diverged tomorrow, would that be a defect or legitimate evolution?

A "legitimate evolution" answer to the last question is decisive: stop, and record the verdict keep-duplicated. That closes the refactor successfully — so does de-abstract, splitting a shared unit that has grown modes back apart. Neither is a failure to act, and neither needs an apology in the output. Textual similarity is not evidence of shared knowledge: copies that read identically can encode different assumptions, and merging them changes behaviour silently.

The class names and the full verdict list are in redundancy-taxonomy.

When the refactor goes the other way and creates a new unit, the reuse question comes first: does an existing class or component already cover this, and what does composing or extending it cost against a new one? Thresholds per artifact class: component-oriented-and-oop-development.

Procedure: Refactor code

Step 1: Make the core change

  • Rename, extract, move, or restructure the target code.
  • Keep the change minimal and focused.

Step 2: Update all downstream dependencies

For each affected file (from the impact analysis):

  • Callers: Update method calls, constructor arguments, imports.
  • Interfaces / abstract methods: Update all implementations to match new signatures.
  • Subclasses: Update overridden methods.
  • Type hints / annotations: Update type references (PHPDoc, TypeScript types, Python type hints, Go generics, Rust generics).
  • Config / bindings: Update service container bindings, route references, etc.
  • Imports: Add or update import statements (use for PHP, import for JS/TS/Python, import blocks for Go, use for Rust).

Step 3: Update API layer (if request handlers / endpoints are affected)

When refactoring touches handlers, route registrations, request validators, or response shapers, walk the stack-appropriate boundary. Use the carve-out skill for the project's framework if one exists; otherwise consult the table below for what to check on each stack.

LayerWhat to check and update
Route registrationRoute file / decorator / file-based-router entry — name, URL, HTTP method, parameter binding
Handler / ControllerEntry signature, injected dependencies, return type
Request validatorValidation rule definitions, allowlisted fields (FormRequest, Zod schema, class-validator DTO, Pydantic model, struct tags)
Response shaperField mapping in the transformer (API Resource, serializer, DTO mapper, response model)
API contractOpenAPI annotations, generated spec, typed client (regenerate if generated)
Authorization rulePolicy / voter / guard / middleware / route dependency that protects the route
Module routesModule-local routing surface (Laravel app/Modules/*/Routes/, Nx apps/*/src/routes, mono-repo per-package routes)

Carve-out routing:

Step 4: Update tests — with user approval

Before changing any test, present a summary to the user:

  1. List all affected tests — which test files and which test cases need changes.
  2. Describe what changes — for each test, explain what assertion/setup changes and why.
  3. Classify the change:
    • Non-breaking: Test adapts to internal refactoring (renamed class, moved method) — same behavior, different code path. No API contract change.
    • ⚠️ Potentially breaking: Test expectations change (new field in response, changed validation rule, different error code) — this MAY affect API consumers.
    • 🔴 Breaking: Test removes or changes existing API behavior (removed field, changed endpoint URL, different response structure) — this WILL affect API consumers.
  4. Ask for confirmation (numbered options):
    > 1. Yes — apply test changes
    > 2. No — I'll adjust the tests myself
    
  5. Only proceed after the user confirms.

Rules for test changes:

  • Do NOT change test expectations to make failing tests pass unless the refactoring intentionally changes behavior. A failing test after refactoring usually means the refactoring has a bug.
  • Do NOT delete tests — adapt them to the new code structure.
  • Do NOT reduce test coverage — if you split a class, split the test too.

Step 5: Verify with the project's quality tools

Run the project's type-checker and linter after each significant step — do NOT batch everything to the end. The exact command set depends on the stack; resolve via quality-tools skill or the project's Taskfile.yml / package.json scripts / composer.json scripts / Makefile.

StackTypical pipeline
Laravel / PHPvendor/bin/phpstan analysevendor/bin/rector processvendor/bin/ecs check --fix → re-run the static analyser
TypeScripttsc --noEmiteslint --fixprettier --write
Pythonmypy (or pyright) → ruff check --fixruff format
Gogo vet ./...golangci-lint run --fixgofmt -w
Rustcargo checkcargo clippy --fixcargo fmt

If auto-fixers can rewrite types (Rector for PHP, eslint --fix for TS), re-run the type-checker after them — auto-fixers can introduce new errors.

Step 6: Run tests

  • Run tests related to the changed code first (php artisan test --filter=..., pnpm test -- <pattern>, pytest -k <pattern>, go test ./{path}/..., cargo test {pattern}).
  • Then run the full test suite (php artisan test, pnpm test, pytest, go test ./..., cargo test).
  • All tests must pass before the refactoring is considered complete.

Step 7: Update documentation

After the code changes are verified, update all affected documentation:

Documentation layerWhen to updateLocation
Project docsWhen conventions, patterns, or key files changeagents/reference/docs/*.md
Project contextsWhen architecture or high-level flow changesagents/settings/contexts/*.md
Module agent docsWhen module-specific behavior changes{module_root}/*/{agent_folder}/ (per modules.root_paths + modules.agent_folder)
Module Docs/When module internals change{module_root}/*/Docs/
AGENTS.mdWhen project-wide conventions changeAGENTS.md
RoadmapsWhen a roadmap step is completedagents/roadmaps/*.md

Rules for doc updates:

  • If you rename a class/method referenced in docs → update the reference.
  • If you move files → update all path references.
  • If you change a pattern → update the pattern description.
  • If you add a new convention → document it.
  • Do NOT create new docs unless the refactoring introduces a genuinely new concept.

Common refactoring patterns

Rename (method, class, property)

  1. Find all usages → update all usages → update docs → run the static analyser → run tests.

Extract method / class

  1. Run the safe-abstraction gate above — a keep-duplicated verdict ends it here.
  2. Create the new method/class → move logic → update caller → update docs → run the static analyser → run tests.

Move class to different namespace

  1. Move file → update namespace → find all use statements → update imports → update docs → run the static analyser.

Change method signature

  1. Update the method → find all callers → update each caller → present test changes → update docs → run the static analyser.

Change API endpoint

  1. Update controller + request + resource + OpenAPI schemas + route → present test changes → update docs (agents/reference/docs/controller.md, agents/reference/docs/api-resources.md) → run the static analyser → run tests.

Replace implementation (e.g. switch service)

  1. Create new implementation → update binding → find all direct references → update → present test changes → update docs → run the static analyser → run tests → remove old implementation.

Move/restructure module

  1. Move files → update namespaces → update ModuleServiceProvider if needed → update module routes → update module agent docs → update project contexts → run the static analyser → run tests.

Safety rules

  • Never skip the caller search — missing a caller is the #1 cause of broken refactorings.
  • Never remove old code before verifying the new code works everywhere.
  • Never change test expectations without user approval — explain what changes and why first.
  • Run the static analyser after every step (PHPStan, tsc --noEmit, mypy — whichever the project runs), not just at the end.
  • Run tests after every step, not just at the end.
  • Update docs after code changes — stale docs are worse than no docs.
  • Do NOT commit or push — only apply local changes.
  • Do NOT refactor code outside the requested scope — no drive-by cleanups.
  • If the refactoring reveals more work than expected, stop and discuss with the user.

Cross-References

SkillRelationship
project-docsWhich docs to read before refactoring a specific area
agent-docs-writingWhen to create/update agent documentation
api-endpointFull API endpoint structure (controller + request + resource + schema)
php-coderPHP coding conventions to follow in refactored code
pest-testingTest conventions when adapting tests
openapiOpenAPI schema attribute patterns

Output format

  1. Refactored code with clear separation of changes
  2. Before/after comparison for key changes
  3. Test verification confirming no behavior change

Gotcha

  • Always find ALL callers before renaming — the model frequently misses usages in tests and config files.
  • Don't refactor and add features in the same commit — separate concerns for reviewability.
  • The model tends to "improve" code it's refactoring — stay scope-focused, refactor means same behavior.
  • Run the full test suite after every refactoring step — don't batch multiple refactors.

Do NOT

  • Do NOT refactor without running tests before and after.
  • Do NOT change test expectations without explicit user approval.
  • Do NOT refactor across module boundaries without checking downstream.

Auto-trigger keywords

  • refactoring
  • rename
  • move class
  • change signature

Frequently asked questions

What to verify before installation and use

What does the code-refactoring source document cover?

When the user says 'refactor this', 'rename class', or 'move method'. Safely refactors code in any language — finds all callers, updates downstream dependencies, verifies via quality tools.

How do I install code-refactoring?

The source record exposes this install command: npx skills add https://github.com/event4u-app/agent-config --skill "src/skills/code-refactoring". Inspect the command and pinned source before running it.

Which permission-related actions were detected?

Static rules flagged read-files in the source; the page lists the matching lines and excerpts.

Alternatives

Compare before choosing

Computed 100147

oaustegard/claude-skills

featuring

Generate hierarchical _FEATURES.md files that describe what a codebase DOES from a user/consumer perspective, anchored to source symbols via tree-sitting. Supports large complex codebases through feature-driven decomposition into sub-feature files. Uses a multi-pass synthesis: orientation → detail → overview rewrite. Use when someone says "what does this do", "document features", "feature inventory", "_FEATURES.md", or needs to understand a codebase's purpose before modifying it. Complements tre

Computed 10017

dancingteeth/unified-code-review

unified-code-review

Risk-first code review for PRs and branch audits: blast-radius triage, agent-authored discipline (tests first, intent evidence), call-graph pincer for integration defects between modules, then structural code-judo bar. Use when reviewing PRs, auditing agent-written diffs, catching rubber-stamp green CI, or wiring bugs single-file review misses. Prefer over structure-only thermo-nuclear review alone. Do not use for unrelated coding tasks or as an always-on rule.

Computed 99241

enuno/unifi-mcp-server

unifi-mcp-tool-builder

Specialized guide for adding new MCP tools to the UniFi MCP Server following project standards, UniFi API patterns, and test-driven development practices. Use when implementing new UniFi Network Controller features as MCP tools.

Computed 9970

PaulRBerg/agent-skills

skill-writing

Create/scaffold/init a project-local agent skill under `.agents/skills` in an ordinary repository; defer to repository instructions that define a source catalog and lifecycle.