/ceh-coding-conduct:refactor-repo [module-or-path]from ceh-coding-conduct
Audit a whole codebase or one module for accumulated complexity and shrink it: a read-only inventory, a ranked proposal, then, only after approval, refactor/ branches under a behavior-preservation gate. Not for one branch's diff (use shrink-diff).
Ships in ceh-coding-conduct. Installing the plugin adds it to Claude Code.
What the skill costs in Claude's context, stage by stage
Name and description, though model invocation is off: only you can start it.
SKILL.md joins the conversation and stays.
Read when SKILL.md points to them; scripts run unread.
The whole-codebase counterpart of shrink-diff: the same standard, but with no diff to scope
it, so scope discipline comes from process instead. This is the high-risk mode — a repo-wide
refactor applied in one pass produces an unreviewable diff and regressions in code that had no
motivating change. Never apply anything in the same breath as finding it: inventory → propose
→ approval → apply.
Scope is the whole repo, or the module/directory the user names. No edits in this phase.
Hunt the same categories as shrink-diff, plus the ones only time produces:
For each area, also record its test coverage status — it decides in Phase 3 what may be applied there.
Walk each piece of code in scope down the write-less-code ladder, in hindsight:
Deliver a ranked candidate table:
| # | What / where | Payoff (est. lines removed, readability) | Risk | Est. diff size | Coverage |
|---|
Group candidates into clusters sized so each cluster makes one reviewable PR (the size limits in
ceh-git-workflow:pull-request). Then stop and wait for the user to select clusters. Invoking
this skill approved the campaign, not any specific candidate — never proceed past this point
unprompted. With no human to select (a headless run), the ranked table is the deliverable: end the
run there and apply nothing, because no cluster was approved.
A deepening candidate carries its proposed interface in the table: the signatures callers would use after, beside the calls they make today, so the user judges the design rather than a label. When the user selects one, settle its open design questions before any code: ask them a round at a time, each with a recommended answer, starting with what the new interface hides and what it must still expose. The answers become the cluster's scope, and a question left open keeps the cluster unapplied.
refactor/<cluster> branch per approved cluster, branched from main, because many
small PRs beat one big one.A refactor changes shape, never behavior:
ceh-testing:verify-behavior-preserved (characterization tests, golden files, differential run)
and commit those pins on their own before touching the code. A green existing suite is the weaker
check: it only proves what it already covered.refactor: type, separate from any other change.Per cluster: candidates applied with before/after git diff --stat totals, candidates skipped
with reasons (coverage, size, risk), and any bug found while refactoring — reported, not fixed.
Save the report to .agents_workspace/product/refactor/<YYYYMMDD-HHMMSS>-<session-id>-refactor.yaml, filling
assets/refactor-report.template.yaml per the refactor-report/v2 section of
references/refactor-report-schema.md, one cluster entry per cluster, and name the path in the
reply, because the skipped candidates and the unfixed bugs have no other record.
Take <YYYYMMDD-HHMMSS> from one date +%Y%m%d-%H%M%S call and <session-id> from ${CLAUDE_SESSION_ID}.
After the last edit, run uv run --script ${CLAUDE_SKILL_DIR}/scripts/artifact.py render <file>.yaml,
which writes the .md beside it in the layout of assets/refactor-report.template.md, and fix
the YAML for each error it lists. Never edit the generated .md. On exit 2 or 3, or without uv,
say in the reply that the report went unchecked and unrendered.
What SKILL.md sets; muted values are Claude Code's defaults
Other plugins' skills for the same job
5 skills in this plugin
/agent-coding-contractCore behavioral contract for coding sessions./find-root-causeLoad this skill when something is broken and no command has yet shown why, before any fix: reproduce it, kill hypotheses with evidence, name the cause. Trigger on "debug this", "find and fix these bugs", "why is this failing", an unexplained stack trace, or a second fix that did not hold./shrink-diffLoad this skill when a feature branch works and its diff against main should shrink before review: duplication it added, single-caller wrappers, code it made dead. Trigger on "shrink the diff", "consolidate the branch". Not for whole-codebase cleanup (use refactor-repo).npx claudepluginhub cheneeheng/ceh-claude-code-library --plugin ceh-coding-conduct