agentleFS
VoxTechnologiesVoxTechnologies/transmute-framework/skills/refactor/SKILL.md

refactor

Skill5 starsChanged 4 months agoMITView on GitHub

Audits the codebase for code quality issues and refactors without changing external behavior. This skill should be used when the user asks to "refactor the codebase", "clean up code quality", "eliminate duplication", "improve abstractions", "enforce consistency", "remove dead code", or "optimize architecture" — or when the transmute-pipeline agent reaches Stage 6E of the pipeline.

196 other projects use a version of this.

Adopted by

Most recently taken up by

Used with

Projects with it also use ascii-diagram, debug-fix 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.
  • SethGammonSkill

    ascii-diagram

    Generate perfectly aligned ASCII diagrams — architecture, flow, sequence, box-and-arrow. Uses a programmatic character-grid approach so alignment is guaranteed by math, not token prediction. Includes post-render verification.

    Also in 4 projects that use this

  • zebbernSkill

    debug-fix

    Find and fix a bug or issue — from any source (GitHub issue, error message, user report, or observed behavior)

    Also in 4 projects that use this

  • parcadeiSkill

    agent-context-isolation

    Agent Context Isolation

    Also in 3 projects that use this

  • parcadeiSkill

    agentica-infrastructure

    Reference guide for Agentica multi-agent infrastructure APIs

    Also in 3 projects that use this

  • +8 more from parcadei

The file

Show its rules and text

We split this skill into the rules it gives an agent

29 rules. 0 are common, 18 are distinctive, and 11 are very specific to this project.

  • 0

    Common

    Most of the 169 edited versions we read keep these.

  • 18

    Distinctive

    This author's own choices. Worth a look.

  • 11

    Very specific

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

  • Common
  • Distinctive
  • Very specific
  • could be automatic: a setting could enforce it
  1. Very specific:

    Read ./CLAUDE.md and ./plancasting/tech-stack.md for project conventions.

    line 41
  2. Very specific:

    Check that ./plancasting/_audits/security/report.md (6A), ./plancasting/_audits/accessibility/report.md (6B), and …

    line 42
  3. Very specific:

    Check ./plancasting/tech-stack.md for the Session Language setting.

    line 45
  4. Very specific:

    Read ./CLAUDE.md, ./plancasting/tech-stack.md, ./ARCHITECTURE.md (if exists), and …

    line 55
  5. Very specific:

    Create ./plancasting/_audits/refactoring/plan.md with prioritized opportunities, affected files, risk levels, and parallelizable work …

    line 76
  6. Very specific:

    Read the detailed guide at ${CLAUDE_SKILL_DIR}/references/refactor-detailed-guide.md for the complete teammate spawn prompts, coordination …

    line 78
  7. Very specific:

    After each teammate completes, run bun run typecheck && bun run test immediately.

    line 101
  8. Very specific:

    If refactoring moves or renames files, check if any .claude/rules/ file references the old path in its paths frontmatter and update …

    line 102
  9. Distinctive:

    After all teammates complete:

    line 106
  10. Distinctive:

    Run COMPLETE test suite and compare to baseline.

    line 108
  11. Distinctive:

    If E2E tests lack coverage for critical pages, start dev server and manually verify.

    line 116
  12. Very specific:

    Update ARCHITECTURE.md if refactoring changed module boundaries.

    line 117
  13. Distinctive:

    Test results (baseline vs post-refactoring, zero regressions required)

    line 121
  14. Distinctive:

    PASS: All tests pass, zero regressions, lint errors resolved, code quality metrics improved.

    line 133
  15. Distinctive:

    CONDITIONAL PASS: All tests pass, minor refactoring opportunities remain documented.

    line 134
  16. Distinctive:

    FAIL: Test regressions introduced, or behavioral changes detected.

    line 135
  17. Distinctive:

    If a refactoring improvement requires architectural changes beyond scope (e.g., fundamental data model restructuring, major framework …

    line 139
  18. Very specific:

    Document in ./plancasting/_audits/refactoring/unfixable-violations.md with severity, description, rationale, estimated effort, and …

    line 140
  19. Distinctive:

    never refactor and add features in the same change — refactoring must preserve behavior.

    line 150
  20. Distinctive:

    never delete a public export without verifying zero external consumers.

    line 151
  21. Distinctive:

    never refactor code without test coverage — add tests first, then refactor.

    line 152
  22. Distinctive:

    never remove database indexes without verifying all query patterns including production logs.

    line 153
  23. Distinctive:

    always commit after each logical refactoring unit for granular rollback.

    line 154
  24. Distinctive:

    always run the full test suite after every refactoring step, not just at the end.

    line 155
  25. Distinctive:

    If refactoring reduces test count, it is a regression — investigate.

    line 156
  26. Very specific:

    If refactoring changes module boundaries, public APIs, or directory structure, update ARCHITECTURE.md (if exists).

    line 159
  27. Distinctive:

    If a refactoring opportunity would require architectural changes beyond scope, document in the report under "Deferred Architectural …

    line 160
  28. Distinctive:

    If re-running after a prior 6V pass, run a targeted 6V subset to verify no regressions.

    line 165
  29. Distinctive:

    If deploying refactored code to production, run Stage 7V afterward.

    line 166

“Common” is measured: kept by at least 6 in 10 of the 169 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

Stage 6E: Code Quality and Architecture Refinement

Lead a multi-agent code refactoring project. Audit the COMPLETE codebase for code quality, eliminate duplication, improve abstractions, enforce consistency, and optimize architecture — without changing any external behavior.

Stage Sequence (recommended ordering): Stage 5B → 6A/6B/6C (parallel) → 6E (this stage) → 6F (Seed Data) → 6G (Resilience Hardening) → 6D (Documentation) → 6H (Pre-Launch) → 6V → 6R → 6P/6P-R → 7 (Deploy)

Cardinal Rule

NO BEHAVIORAL CHANGES. Refactoring changes internal structure without altering external behavior. Every test that passed before refactoring must still pass after. If a refactoring would require changes to tests that validate external behavior (API contracts, acceptance criteria), the behavior is changing — stop and reconsider. Tests validating implementation details (private functions, internal state) may be restructured.

Scope clarification: 'No behavioral changes' means no changes to external APIs or user-facing behavior. Internal function signatures MAY change if all call sites are updated atomically in the same commit.

Context: Why This Stage Exists

The Feature Orchestrator builds features one at a time, with each cycle's teammates having limited awareness of other features' implementation details. This produces a working product, but leaves behind:

  • Duplicated utility functions and patterns across feature domains
  • Missed abstraction opportunities
  • Inconsistent naming, patterns, or conventions across features
  • Schema and index redundancies from incremental additions
  • Overly coupled code where cross-feature integration was added reactively
  • Dead code from iterative fixes during quality gate cycles

Prerequisites

Verify before starting:

  1. ./plancasting/_audits/implementation-completeness/report.md exists with PASS or CONDITIONAL PASS. If missing or FAIL, STOP — Stage 5B must pass first.
  2. Read ./CLAUDE.md and ./plancasting/tech-stack.md for project conventions.
  3. Check that ./plancasting/_audits/security/report.md (6A), ./plancasting/_audits/accessibility/report.md (6B), and ./plancasting/_audits/performance/report.md (6C) exist. If any are missing, WARN and document in the report.
  4. Incomplete features (5B Category C): Skip refactoring features marked as incomplete. However, DO refactor shared utilities/hooks that incomplete features use (since other complete features may also depend on them).

Check ./plancasting/tech-stack.md for the Session Language setting. Generate all reports in that language. Code and file names remain in English. Replace all bun run commands with the project's package manager from CLAUDE.md.

Stack Adaptation

Source examples use Convex + Next.js. Adapt all paths and patterns to the actual tech stack in plancasting/tech-stack.md: convex/ becomes your backend directory, Convex functions become your backend functions, src/app/ becomes your frontend pages, etc. Read CLAUDE.md Part 2 for actual conventions.

Phase 1: Lead Analysis and Planning

Complete BEFORE spawning teammates:

  1. Read ./CLAUDE.md, ./plancasting/tech-stack.md, ./ARCHITECTURE.md (if exists), and ./plancasting/_audits/implementation-completeness/report.md.
  2. Run the full test suite and save baseline to ./plancasting/_audits/refactoring/baseline-test-results.md:
    bun run typecheck
    bun run test
    bun run test:e2e
    Verify test counts are non-zero. Check the test runner output for lines like "Tests: X passed", "X test suites". If the output shows 0 tests found, treat as 0 test files. (1) If ALL suites return 0 tests: STOP — do not refactor without tests. Run Stage 5 first. (2) If some suites have tests but others don't: WARN and proceed limited to covered code paths. (3) If all have tests: proceed normally. If baseline tests fail, STOP and resolve failures first.
  3. Count total files, functions, components, hooks, and lines of code. Identify largest files (candidates for splitting) and highest-coupling files.
  4. Analyze the codebase for refactoring opportunities across seven categories:

    CategoryWhat to look for
    DuplicationSimilar functions, components, or patterns across feature domains. Extract when ANY threshold met: (a) identical function 3+ times, (b) function 2+ times with >90% similarity, (c) extracting reduces lines by >15%
    AbstractionRepeated logic that should be extracted into shared modules
    ConsistencyNaming, patterns, or conventions that vary across features
    SchemaRedundant indexes, tables that could be merged, unused fields
    CouplingFeature code importing another feature's internals. Run npx madge --circular src/ for cycle detection
    Dead codeUnused exports, unreachable branches, commented-out code
    File structureFiles exceeding 300 lines, unclear module boundaries
  5. Create ./plancasting/_audits/refactoring/plan.md with prioritized opportunities, affected files, risk levels, and parallelizable work packages.

Read the detailed guide at ${CLAUDE_SKILL_DIR}/references/refactor-detailed-guide.md for the complete teammate spawn prompts, coordination protocols, and analysis criteria.

Phase 2: Spawn Refactoring Teammates

Spawn 4 teammates. Each spawn prompt must include the refactoring plan and the cardinal rule.

Teammate 1 — "backend-refactorer": Backend functions, schema, server-side code. Tasks: function deduplication, schema optimization (index cleanup with verification — BEFORE removing any index: search all backend files, check schema comments, verify production usage if accessible; if any uncertainty, KEEP with comment), consistency enforcement (error handling, auth, validation patterns), dead code removal (with string-reference search including dynamic imports and bracket notation), file splitting for 300+ line files, post-refactor cleanup (remove unused libraries, verify no any types or @ts-ignore introduced).

Teammate 2 — "frontend-component-refactorer": React components and pages. Tasks: component deduplication into shared directory, pattern extraction (forms, lists, modals, state components), prop interface cleanup (no any, consistent naming), file splitting for 300+ line components, design token compliance (flag hardcoded colors/fonts/spacing, consolidate icon imports via barrel file). Do not create hooks — send hook requirements to Teammate 3.

Teammate 3 — "hooks-and-logic-refactorer": Custom hooks, utilities, types, shared logic. Tasks: hook deduplication (generic parameterized hooks), utility consolidation, type consolidation into shared files, import cleanup (unused imports, path aliases, ordering), dead code removal.

Teammate 4 — "test-and-structure-refactorer": Test quality, E2E tests, project structure. Tasks: test deduplication (shared fixtures), test quality (clear descriptions, single-assertion, Given-When-Then), E2E optimization (journey consolidation, page objects), project structure (naming, no circular deps via dpdm, madge, or similar), traceability audit. Test count must be >= baseline after refactoring.

Each teammate runs verification (bun run typecheck && bun run test) after ALL changes and reverts any change that causes test failures.

Phase 3: Coordination

Monitor progress and facilitate cross-team dependencies:

  • Backend extractions affect hook call patterns — notify Teammate 3.
  • Frontend component extractions affect hook return types — notify Teammate 3.
  • Utility moves affect imports everywhere — notify Teammates 2 and 4.
  • For shared-file conflicts: assign priority to the more structural change; other teammate waits.
  • After each teammate completes, run bun run typecheck && bun run test immediately. If tests fail, notify responsible teammate before others proceed.
  • If refactoring moves or renames files, check if any .claude/rules/ file references the old path in its paths frontmatter and update accordingly.

Phase 4: Integration Verification

After all teammates complete:

  1. Run COMPLETE test suite and compare to baseline. Pass count must be >= baseline. Zero regressions. Fix any lint errors introduced by refactoring.
    bun run typecheck
    bun run lint
    bun run build
    bun run test
    bun run test:e2e
  2. If E2E tests lack coverage for critical pages, start dev server and manually verify.
  3. Update ARCHITECTURE.md if refactoring changed module boundaries. If it doesn't exist, document major changes in the report instead.
  4. Generate ./plancasting/_audits/refactoring/report.md with:
    • Metrics Before vs After: Total files / lines, duplicated code eliminated, shared modules created, dead code removed, largest file before vs after, unused indexes removed
    • Changes by category (Duplication, Abstraction, Consistency, Schema, Coupling, Dead code, File structure)
    • Test results (baseline vs post-refactoring, zero regressions required)
    • Remaining technical debt with rationale
    • Recommendations to prevent re-accumulation

Stage 6F Handoff: If schema changes were made, document them in the report under 'Schema Changes'. Stage 6F reads this to regenerate affected seed scripts.

Stage 6G Handoff: If error handling patterns were extracted (e.g., shared withRetry(), handleApiError()), document them under 'Extracted Error Handling Patterns for Stage 6G' with file locations and usage. Stage 6G reads this to reuse existing patterns.

Gate Decision

Include in the report under a ## Gate Decision heading (6H parses this heading):

  • PASS: All tests pass, zero regressions, lint errors resolved, code quality metrics improved.
  • CONDITIONAL PASS: All tests pass, minor refactoring opportunities remain documented.
  • FAIL: Test regressions introduced, or behavioral changes detected.

Unfixable Violation Protocol

If a refactoring improvement requires architectural changes beyond scope (e.g., fundamental data model restructuring, major framework migration):

  1. Document in ./plancasting/_audits/refactoring/unfixable-violations.md with severity, description, rationale, estimated effort, and recommended approach.
  2. Reference in the main report under 'Deferred Architectural Improvements'.
  3. Continue with remaining tasks.

Phase 5: Shutdown

Request shutdown for all teammates. Verify all modifications are saved and committed.

Critical Rules

  1. never refactor and add features in the same change — refactoring must preserve behavior.
  2. never delete a public export without verifying zero external consumers.
  3. never refactor code without test coverage — add tests first, then refactor.
  4. never remove database indexes without verifying all query patterns including production logs.
  5. always commit after each logical refactoring unit for granular rollback.
  6. always run the full test suite after every refactoring step, not just at the end.
  7. If refactoring reduces test count, it is a regression — investigate.
  8. Adding new tests during refactoring is acceptable. Removing tests that validate user-facing behavior is not. Tests validating implementation details may be restructured.
  9. Reference Stage 5B output to avoid refactoring incomplete features.
  10. If refactoring changes module boundaries, public APIs, or directory structure, update ARCHITECTURE.md (if exists).
  11. If a refactoring opportunity would require architectural changes beyond scope, document in the report under "Deferred Architectural Improvements" — do not attempt it.

Cross-Stage References

  • Runs AFTER 6A-6C. Do not refactor patterns intentionally introduced by those audits.
  • If re-running after a prior 6V pass, run a targeted 6V subset to verify no regressions.
  • If deploying refactored code to production, run Stage 7V afterward.

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.

Reviews can't be read right now.

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.