/yka-code:refactor-safelyfrom yka-code
[yka-code] Safe refactoring workflow using this system's installed plugins. Use when the user asks to refactor, clean up, simplify, deduplicate, extract, or reorganize existing code WITHOUT changing behavior. Not for bug fixes (use fix-bug) or new features (use ship-feature).
Ships in yka-code. Installing the plugin adds it to Claude Code.
What the skill costs in Claude's context, stage by stage
Name and description: Claude knows it exists.
SKILL.md joins the conversation and stays.
None: SKILL.md is the whole skill.
Refactor = change structure, preserve behavior. This workflow enforces that via the user's installed tooling.
Load and apply the karpathy-guidelines skill alongside this workflow. Short version:
Before anything else: does the refactor touch >2 files, involve rename across multiple modules, require a plan + refactor + review pipeline, or need verify-fix iteration? If ANY yes → stop refactor-safely, route back to /do which will pick team-do. refactor-safely is for local, single-module refactors.
Only continue if scope is genuinely local.
| Condition | Tool | Why |
|---|---|---|
| Always — map the code before changing it | serena (semantic refs) + ast-grep (structural) + /claude-mem:smart-explore (AST) — launch as parallel Task calls in ONE message | Read-only, independent, 3× speedup |
| Check prior refactors in this area | /claude-mem:mem-search "<module name>" | Learn from past attempts |
| Refactor touches external library calls | docfork MCP | Confirm current API shape before rewriting call sites — training cutoff may be stale |
| Refactor hypothesis rests on open-source behavior | deepwiki MCP | Public repo Q&A — verify lib semantics before restructuring around them |
| Refactor targets DB-layer code | psql / mongosh / project ORM's CLI | Run EXPLAIN / EXPLAIN ANALYZE directly; no MCP overhead |
| Need to run tests in isolation (parallel experiments) | container-use CLI | Per-branch sandboxed test runs |
| Refactor is complex (>5 files cross-cutting) | /claude-mem:make-plan + TeamCreate persistent team | Plan + keep reviewers in shared context |
| Refactor a public API / library boundary | pr-review-toolkit:type-design-analyzer + pr-review-toolkit:comment-analyzer | Type invariants + doc accuracy |
Before writing any characterization test (or when one is needed to cover untested code in scope), invoke Skill(skill: "test-driven-development"). Not "consider" — call. The upstream skill owns the RED → GREEN discipline for pinning current behavior before the refactor touches it.
Before touching any code:
serena MCP tools to find all references/types involvedast-grep for structural pattern searches across files/claude-mem:mem-search with the relevant topic — did we refactor this area before? What did we learn?Spawn the code-simplifier subagent (from code-simplifier plugin). Give it the specific files/functions in scope. It is explicitly designed to refine code "while preserving functionality" — constrain it to the targeted region, not the whole file.
Karpathy principles apply: surgical changes only. Do not reformat unrelated code. Do not rename things that aren't in scope.
Invoke /code-review:code-review on the diff. For deeper review, also spawn:
pr-review-toolkit:code-simplifier (duplicate of simplifier but reviewer-mode — catches over-simplification)pr-review-toolkit:type-design-analyzer — catches type-invariant breakageRe-run the same tests from Phase 1. Pass state MUST match. If any test changed, either:
Only proceed if the baseline matches.
Before claiming the refactor is done (or before running git commit), invoke Skill(skill: "verification-before-completion"). Non-negotiable. The baseline-match check in Phase 5 plus full test suite exit code must be re-run and captured as fresh evidence. No "Done!" without this.
/commit-commands:commit with a message like refactor(scope): what changed and why — the "why" is the refactor's purpose (readability, perf, deduplication), NOT just the what.
User: "Clean up the auth middleware — it's gotten tangled."
serena symbol-search for callers of middleware functions; ast-grep for similar patterns elsewhere/claude-mem:mem-search "auth middleware" → find a past note about a tricky session-token edge casecode-simplifier agent on src/middleware/auth.ts only/code-review:code-review + pr-review-toolkit:type-design-analyzer review the diff/commit-commands:commit → "refactor(auth): extract session-token helper, inline single-use guard"test-driven-development — See Phase 1 — invoked there as an explicit tool call, not an optional chain.verification-before-completion — See Phase 5.5 — invoked there as an explicit tool call, not an optional chain.fix-bug — if the refactor exposes a real bug (not just smell), stop refactoring and route there.ship-feature — if the refactor reveals missing feature scope, don't fold it in; queue as separate ship-feature work.doc-hygiene — if public API shape changes (rename, signature), doc updates land under its rules.What SKILL.md sets; muted values are Claude Code's defaults
Generated from the plugin's indexed repository (youssefkadaouiabbassi/yka-code) — no native marketplace selected
npx claudepluginhub p/youssefkadaouiabbassi-code-tools-setup20 skills in this plugin
/audit-rigor[yka-code] Discipline for audit, review, and technology-comparison tasks. Use when the request is "audit X", "review our stack", "is this the best option", "compare alternatives", "what should we swap / add / drop", or any task that produces prioritized recommendations rather than new code. Enforces a ≥70% confidence threshold, delegate-retrieval-to-subagent pattern, inline citations with ISO dates, MCP-first sourcing, and a fixed output format (SWAP / ADD / DROP / KEEP-BUT-UPGRADE / SURPRISE). Pair with research-first (retrieval discipline) and karpathy-guidelines (surgical scope). Chained from security-audit, onboard-codebase, and any /do route that smells like "is this the best we have"./ci-hygiene[yka-code] CI/CD and DevOps hygiene enforcer. Activates when editing GitHub Actions workflows, Dockerfiles, docker-compose, justfile, deploy scripts, or any CI configuration. Enforces pinned versions, proper Claude Code invocation in CI (--bare, API key not Max sub), secret management, and reproducibility. Fills the DevOps gap — no plugin covers this in the wild./coding-style[yka-code] Enforce minimalist, self-documenting, defensively-sane coding style. Use ALWAYS when writing, editing, or reviewing ANY code in ANY language — every function, every edit, every diff, no exceptions. Covers five rules: (1) no comments unless critical (WHY only, never WHAT, never history), (2) clean + optimized (no dead code, no speculative abstractions, no stale imports, delete over deprecate), (3) self-documenting names (full words, verbs for functions, nouns for data), (4) smallest surface (one function one concern, extract only on 3rd reuse, validate only at boundaries), (5) no dead defense (no try/catch for impossible cases, no fallbacks for inputs you control, let errors bubble to the right handler). Pair with karpathy-guidelines for behavioral principles (Think Before Coding, Simplicity First, Surgical Changes, Goal-Driven Execution).Other plugins' skills for the same job