Best for
- New feature development (use feature-planning skill)
- Bug fixes that don't involve restructuring (use bug-analyzer skill)
event4u-app/agent-config/src/skills/code-refactoring/SKILL.md
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.
Decision brief
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.
Compatibility matrix
| Platform | Status | Evidence | What to check |
|---|---|---|---|
| Codex | Not declared | No explicit evidence | Portability before use |
| Claude Code | Not declared | No explicit evidence | Portability before use |
| Cursor | Not declared | No explicit evidence | Portability before use |
| Gemini CLI | Not declared | No explicit evidence | Portability before use |
Installation
The source command is displayed only when detected. A safe inspection prompt is always available so your agent can explain every action before execution.
npx skills add https://github.com/event4u-app/agent-config --skill "src/skills/code-refactoring"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
For each affected file (from the impact analysis):
Rename, extract, move, or restructure the target code.
For each affected file (from the impact analysis):
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.
Before changing any test, present a summary to the user:
Permission review
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
| Signal | Value | Evidence type | Meaning |
|---|---|---|---|
| Quality score | 94/100 | Computed | Documentation, specificity, maintenance, and trust rules |
| Repository stars | 9 | Source | Repository attention, not individual Skill quality |
| Compatibility | 0 platforms | Source | Declared in the catalog source record |
| Usage guide | automated source guide | Editorial | Generated or reviewed according to the visible evidence level |
Pinned source
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:
feature-planning skill)bug-analyzer skill)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.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.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:
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.
For each affected file (from the impact analysis):
use for PHP, import for JS/TS/Python, import blocks for Go, use for Rust).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.
| Layer | What to check and update |
|---|---|
| Route registration | Route file / decorator / file-based-router entry — name, URL, HTTP method, parameter binding |
| Handler / Controller | Entry signature, injected dependencies, return type |
| Request validator | Validation rule definitions, allowlisted fields (FormRequest, Zod schema, class-validator DTO, Pydantic model, struct tags) |
| Response shaper | Field mapping in the transformer (API Resource, serializer, DTO mapper, response model) |
| API contract | OpenAPI annotations, generated spec, typed client (regenerate if generated) |
| Authorization rule | Policy / voter / guard / middleware / route dependency that protects the route |
| Module routes | Module-local routing surface (Laravel app/Modules/*/Routes/, Nx apps/*/src/routes, mono-repo per-package routes) |
Carve-out routing:
laravel-api-endpointnextjs-patternssymfony-workflowBefore changing any test, present a summary to the user:
> 1. Yes — apply test changes
> 2. No — I'll adjust the tests myself
Rules for test changes:
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.
| Stack | Typical pipeline |
|---|---|
| Laravel / PHP | vendor/bin/phpstan analyse → vendor/bin/rector process → vendor/bin/ecs check --fix → re-run the static analyser |
| TypeScript | tsc --noEmit → eslint --fix → prettier --write |
| Python | mypy (or pyright) → ruff check --fix → ruff format |
| Go | go vet ./... → golangci-lint run --fix → gofmt -w |
| Rust | cargo check → cargo clippy --fix → cargo 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.
php artisan test --filter=..., pnpm test -- <pattern>, pytest -k <pattern>, go test ./{path}/..., cargo test {pattern}).php artisan test, pnpm test, pytest, go test ./..., cargo test).After the code changes are verified, update all affected documentation:
| Documentation layer | When to update | Location |
|---|---|---|
| Project docs | When conventions, patterns, or key files change | agents/reference/docs/*.md |
| Project contexts | When architecture or high-level flow changes | agents/settings/contexts/*.md |
| Module agent docs | When 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.md | When project-wide conventions change | AGENTS.md |
| Roadmaps | When a roadmap step is completed | agents/roadmaps/*.md |
Rules for doc updates:
keep-duplicated verdict ends it here.use statements → update imports → update docs → run the static analyser.agents/reference/docs/controller.md, agents/reference/docs/api-resources.md) → run the static analyser → run tests.ModuleServiceProvider if needed → update module routes →
update module agent docs → update project contexts → run the static analyser → run tests.tsc --noEmit, mypy — whichever the project runs), not just at the end.| Skill | Relationship |
|---|---|
project-docs | Which docs to read before refactoring a specific area |
agent-docs-writing | When to create/update agent documentation |
api-endpoint | Full API endpoint structure (controller + request + resource + schema) |
php-coder | PHP coding conventions to follow in refactored code |
pest-testing | Test conventions when adapting tests |
openapi | OpenAPI schema attribute patterns |
Frequently asked questions
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.
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.
Static rules flagged read-files in the source; the page lists the matching lines and excerpts.
Alternatives
oaustegard/claude-skills
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
dancingteeth/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.
enuno/unifi-mcp-server
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.
PaulRBerg/agent-skills
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.