kramme-cc-workflow/skills/kramme:code:refactor-opportunities/SKILL.md
Scan the full codebase, current PR, a named file/folder, or a named feature for refactoring candidates. Use when the user asks to find refactor opportunities, audit code quality, identify tech debt, or wants a codebase health check. Flags themes whose combined blast radius exceeds 500 lines as automation candidates.
npx skillsauth add abildtoft/kramme-cc-workflow kramme:code:refactor-opportunitiesInstall this skill globally with one command. Works with Claude Code, Cursor, and Windsurf.
3 of 9 scanners reported clean
Some scanners were skipped, did not run, or reported a non-clean status. Review each row below.
Systematically scan the codebase for refactoring candidates, categorize findings by severity, and produce a prioritized report.
Arguments: "$ARGUMENTS"
full, pr, path, or feature. Defaults to full.full, full codebase, repo, everything, or all, or pass --scope full. Scan all source directories.pr, current PR, diff, or changes, or pass --scope pr. Scan the files changed by the current branch against the resolved base branch, plus staged, unstaged, and untracked files. Changed files are context; active findings must be caused by the PR changes, not merely pre-existing debt in touched files.path <file-or-folder>, --scope path <file-or-folder>, or a bare path-shaped argument that resolves to an existing file, folder, glob match, or file list. Scan only the matching files.feature <name>, --scope feature <name>, or --feature <name>. A bare argument that is neither a reserved keyword nor path-shaped is also treated as a feature name; use the explicit feature <name> form when the feature name collides with a reserved keyword (full, full codebase, repo, everything, all, pr, current PR, diff, changes). Resolve the feature to its implementation, tests, routes, schemas, docs, and adjacent modules before scanning.--scope <mode>, --feature <name>, path <…>, feature <…>) selects that mode directly.full, full codebase, repo, everything, all) or PR alias (pr, current PR, diff, changes) selects the corresponding mode. To name a feature whose name collides with a reserved keyword, use the explicit feature <name> form./, ., or a glob meta-character (*, ?, [); a path-shaped argument that resolves selects path, and one that does not resolve triggers a clarification ask (do not fall back to feature).--scope pr plus a bare path, or path <…> plus feature <…>), pause and ask which single scope to use. --base <ref> is a PR-mode parameter, not a selector, and does not trigger this rule.A high-signal report rejects more than it reports. Do not flag:
These rejections are pre-filters — apply them before recording a finding, not during Synthesis.
$ARGUMENTS per the Inputs section into a single SCOPE_MODE, applying the multi-selector rule from Inputs before resolving. The per-mode target is computed in Resolve the effective scan scope below.package.json / pyproject.toml / build config to understand the stack and directory layout.AGENTS.md, CLAUDE.md, or equivalents) if present and read the relevant ones to understand project-specific conventions.docs/decisions/ (or other common ADR locations: doc/adr/, docs/adr/, architecture/decisions/). If found, read every ADR whose status reads ACCEPTED (case-insensitive) and store their decisions as KNOWN_ADRS — title, status, and a one-line summary of what was decided and what was rejected. Skip ADRs marked PROPOSED, SUPERSEDED, or DEPRECATED — only accepted decisions are decision-of-record. These bound the design space the scan operates in. If no ADR directory exists, proceed silently with KNOWN_ADRS = [].UBIQUITOUS_LANGUAGE.md (or similar: GLOSSARY.md, docs/glossary.md) exists at the project root, read it and store the canonical domain terms. When naming refactor candidates in Phase 4, prefer these terms over internal helper class names — "the Order intake module" is more useful than "the FooBarHandler". If no glossary file exists, proceed silently — do not flag its absence..out-of-scope/ exists at the project root, list its filenames and store them as KNOWN_OUT_OF_SCOPE. Do not open file bodies yet — that happens in Phase 3 only when a finding plausibly matches a slug. If no directory exists, proceed silently with KNOWN_OUT_OF_SCOPE = []. See /kramme:docs:out-of-scope for the storage skill.node_modules, dist, build artifacts, generated files, lock files, vendored code, and binary assets. Then per mode:
Resolve the base ref in this order:
--base <ref>.gh pr view --json baseRefName,isCrossRepository — if it returns metadata for a same-repo PR, use origin/<baseRefName>. For cross-repo PRs (isCrossRepository == true), ask for --base <ref> instead of guessing. If gh is not installed, not authenticated, or reports no PR open for this branch, skip to the next fallback without erroring.origin/<current-branch>.origin/main, origin/master, main, then master.If no base can be resolved, report the attempted refs and ask for --base <ref> — do not fall back to full.
Build the file set from git diff --name-only <resolved-base>...HEAD, git diff --cached --name-only, git diff --name-only, and git ls-files --others --exclude-standard. Drop deleted files from the set unless a search of the current tree/worktree shows surviving references to the deleted symbols or paths.
Build PR_CHANGE_MAP from git diff --unified=0 <resolved-base>...HEAD, git diff --unified=0 --cached, and git diff --unified=0. Record added/modified/deleted hunk ranges per file. Treat each untracked file's full content as added. Store the merge base as PR_BASE_REF for checking whether a candidate issue existed before the branch.
Use changed files as scan context, but use PR_CHANGE_MAP as the finding boundary. Apply the PR relevance gate — a PR-mode finding must be tied to one of:
"The file was touched" is not enough. References to "the PR relevance gate" elsewhere in this skill mean exactly this list.
feature. For folders, recursively include source files under the folder.SCOPE_DESCRIPTION covering mode, resolved target, file count, and source directories — for example Full codebase (1,247 files across 8 source directories), Current PR against origin/main (14 files), Path src/api (37 files), or Feature "billing exports" (22 files across API, UI, tests, and docs). Report it to the user before proceeding.Read references/checklist.md for the full checklist of categories and recording format. For findings in the Structural & Architectural and Coupling & Dependencies categories — anywhere depth, seams, wrappers, or speculative indirection are at issue — read references/architecture-language.md and use that vocabulary in the finding. Specifically, before flagging a wrapper as shallow, apply the deletion test; before flagging an interface as a speculative seam, apply the adapter-count rule ("one adapter = hypothetical seam, two adapters = real seam"). A finding that does not satisfy these tests is not yet a finding.
Launch parallel Explore agents to cover the codebase efficiently. Split work by category group, not by directory, so each agent builds cross-cutting expertise:
Each agent must:
Read the checklist reference file for its assigned categories.
Scan all files in scope for findings in those categories.
Apply the When-NOT-to-flag pre-filter before recording.
Record each finding with: location, category, severity, description, suggested fix.
When SCOPE_MODE=pr, include PR relevance: <why this is caused by the PR> on every finding, naming which of the five categories from the PR relevance gate (defined in Phase 1) the finding satisfies. "The file was touched" is not enough.
When SCOPE_MODE=pr, do not record repository-wide cleanup themes just because the changed file reveals them. If the fix would primarily modify untouched files or address a problem that existed unchanged in PR_BASE_REF, emit it as NOTICED BUT NOT TOUCHING with Why skipping: pre-existing / outside PR scope.
When the agent spots something outside its assigned categories, emit a NOTICED BUT NOT TOUCHING entry instead of silently re-categorizing into its own bucket:
NOTICED BUT NOT TOUCHING: <file:line — what was seen>
Why skipping: outside assigned category group
These entries are collected in Synthesis and surfaced in the report as uncategorized observations, not folded into the agent's findings.
Return findings as a structured list.
NOTICED BUT NOT TOUCHING entries.SCOPE_MODE=pr. Cross-reference each candidate against PR_CHANGE_MAP and PR_BASE_REF before severity assignment:
NOTICED BUT NOT TOUCHING if the report template has no dedicated section. Do not include filtered PR-scope observations in severity tables, themes, or recommended refactor order.KNOWN_OUT_OF_SCOPE. For each finding, check whether its concept plausibly matches a slug in KNOWN_OUT_OF_SCOPE. If yes, read that file and either drop the finding (clean concept match, no new evidence) or annotate it as _"matches .out-of-scope/<slug>.md (decided <date>) — re-evaluate?"_ when concrete new evidence has accumulated. Default is silent skip; the annotation is the exception. Symmetric to the ADR filter below.KNOWN_ADRS. For each finding, check whether it contradicts an accepted ADR. If the contradiction is theoretical (the ADR rejected this exact refactor and no concrete new evidence has emerged), drop the finding silently — the ADR is decision-of-record. Surface as _"contradicts ADR-NNNN — but worth reopening because <concrete new evidence>"_ only when real friction has accumulated since the ADR was accepted. The default is silent skip; the annotation is the exception.assets/report-template.md for the output format.PR relevance for every active finding using the PR-only table column described in the template, and include the count of filtered PR-scope observations in the summary. In non-PR scopes, omit PR relevance entirely. Filtered observations must not be described as findings.references/architecture-language.md must include a one-line deletion test result (e.g., "inlining at the 1 call site removes 4 lines, no caller becomes harder to read") and an adapter count when claiming a seam is speculative. Findings missing these fields are not yet ready and should be dropped at this point, not paper-clipped together.UBIQUITOUS_LANGUAGE.md was read in Phase 1, use the canonical domain terms in finding titles and descriptions. Default helper-class language is a tell that the scan didn't read the project's own vocabulary.REFACTOR_OPPORTUNITIES_OVERVIEW.md in the project root. Overwrite any prior report — the file represents the latest scan only.processOrder (src/orders.ts:45-120) has 8 branches and 3 levels of nesting — extract validation into a separate function" is.kramme:code:refactor-pass on specific findings.These are how a scan turns from high-signal into noise. Each has a correct response:
If you notice any of these during the scan, stop and tighten the filter:
NOTICED BUT NOT TOUCHING entries were silently folded into findings instead of surfaced separately.Before writing the report, self-check:
NOTICED BUT NOT TOUCHING entries are surfaced as a separate section, not mixed into findings.PR relevance line and passed the PR relevance gate.KNOWN_ADRS entry without an explicit contradicts ADR-NNNN annotation backed by concrete new evidence.If any box is unchecked, fix the gap before writing the report.
development
Runs kramme:pr:code-review as a closeout review loop for local or PR branch changes before commit, ship, or final response. Use when the user asks for autoreview, second-model review, or a final code-review pass after non-trivial edits. Not for UX, visual, accessibility, or product review.
development
Guides topic-level understanding verification for a PR, branch, feature, document, spec, design decision, bug fix, or other concrete subject. Use when the user asks to confirm, quiz, drill, teach-and-check, or verify that they understand a topic. Maintains a topic-specific checklist artifact and requires demonstrated understanding before marking the topic complete. Not for ordinary explanations without verification, end-of-session summaries, or code/test correctness checks.
testing
Design a CI/CD pipeline with quality gates, a <10-minute budget, feature-flag lifecycle, and an exit checklist. Use when adding a new CI pipeline, changing gate configuration, or planning a rollout for a new service. Complementary to kramme:pr:fix-ci (which fixes failures in an existing pipeline). Covers gate ordering, secrets storage, branch protection, rollback mechanism, and staged-rollout guardrails — not a rollout-execution runbook.
tools
--- name: kramme:visual:demo-reel description: Capture local demo evidence for observable product behavior: screenshots, before/after image sets, browser reels, terminal recordings, and short GIF/video proof. Use when shipping UI changes, CLI features, or any change where PR reviewers would benefit from visual or behavioral evidence. argument-hint: "[what to capture] [--url <url>|auto] [--tier static|before-after|browser-reel|terminal-recording]" disable-model-invocation: true user-invocable: tr