/kenji:workflow-refactorfrom kenji skills
Scoped, behavior-preserving refactoring: maps dependencies, changes structure, runs affected tests. Use when asked to refactor, reduce duplication, or improve readability.
Ships in kenji skills. 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.
Degree of freedom: MIXED. Structure target [HIGH freedom];
behavior-preserving checks and affected tests [LOW freedom — run exactly].
| Skill | Owns |
|---|---|
| workflow-refactor (this) | Scoped, behavior-preserving structure change with affected tests run |
audit-code-quality | Repo-wide anti-patterns and consistency drift, detected and fixed |
plan-dead-code | Plan-only dead-code audit with Knip; deletes nothing |
Everything here preserves behavior. Removing code is a different
contract: plan-dead-code proves it unreachable and housekeep-dead-code
deletes it against an approved list. Duplication findings arrive here from
those skills; deletions do not leave from here.
Observe: three copy-pasted date formatters; tests only cover one. Interpret: same behavior, three implementations. Classify: extract
formatDate; add the missing two call-site tests first (red), then extract (green). Verify: same output; no new features.
audit-code-quality; mechanical rename → burndown-fullImprove code quality without changing external behavior. Research-aware.
Before refactoring any code:
README.md (project overview)
src/[domain]/@_[domain]-README.md (domain architecture)
CONTRIBUTING.md (code standards)
Use Grep and SemanticSearch to find:
Before changing any function, class, or component:
rg "functionName" --type ts # find all callers
rg "import.*from.*module" --type ts # find all importers
List every file that will be affected by the change.
If the refactoring introduces a new pattern, verify it's current best practice:
firecrawl:firecrawl_search
{
"query": "<framework> <pattern> best practice <current year>",
"limit": 5,
"sources": [{ "type": "web" }]
}
Scrape the most authoritative result:
firecrawl:firecrawl_scrape
{
"url": "<best-result-url>",
"formats": ["markdown"],
"onlyMainContent": true
}
This prevents refactoring FROM one outdated pattern TO another outdated pattern.
Before refactoring, state:
"Pre-refactoring check:
- README/docs read: [list]
- Dependent files identified: [list files that import this code]
- Blast radius: [N files affected]
- Tests exist: [YES/NO — if NO, write tests first]
- Pattern verified: [YES via research / YES matches codebase / SKIP — trivial refactor]"
| Smell | Symptom | Solution |
|---|---|---|
| Long Function | >20 lines, does multiple things | Extract functions |
| Duplicate Code | Same logic in 2+ places | Extract shared function/hook |
| Magic Numbers | Unexplained literals | Named constants or config |
| Deep Nesting | 3+ levels of if/loops | Early returns, extract functions |
| Long Parameter List | >3 parameters | Object parameter with interface |
| Feature Envy | Function uses another module's data heavily | Move function to that module |
| God Object | One class/component does everything | Split by responsibility |
| Primitive Obsession | Using strings/numbers where a type would be safer | Create domain types |
| Shotgun Surgery | One change requires editing many files | Consolidate related logic |
| Dead Code | Unreachable or unused code | Not this skill — proving it dead is plan-dead-code, deleting it is housekeep-dead-code. Note it and move on |
Before:
function processOrder(order: Order) {
if (!order.items.length) throw new Error('Empty order');
if (!order.customer) throw new Error('No customer');
if (order.total < 0) throw new Error('Invalid total');
const subtotal = order.items.reduce((sum, i) => sum + i.price, 0);
const tax = subtotal * 0.1;
const total = subtotal + tax;
db.orders.insert({ ...order, total });
}
After:
function processOrder(order: Order) {
validateOrder(order);
const total = calculateTotal(order);
saveOrder({ ...order, total });
}
Before:
function getDiscount(user: User, order: Order) {
if (user) {
if (user.isPremium) {
if (order.total > 100) {
return 0.2;
} else {
return 0.1;
}
}
}
return 0;
}
After:
function getDiscount(user: User | null, order: Order) {
if (!user) return 0;
if (user.isPremium && order.total > 100) return 0.2;
if (user.isPremium) return 0.1;
return 0;
}
// Before
if (password.length < 8) { ... }
if (retries > 3) { ... }
const tax = amount * 0.1;
// After
const MIN_PASSWORD_LENGTH = 8;
const MAX_RETRIES = 3;
const TAX_RATE = 0.1;
// Before — positional args are error-prone
function createUser(name: string, email: string, age: number, role: string) { ... }
// After — named, self-documenting, extensible
interface CreateUserParams {
name: string;
email: string;
age: number;
role: string;
}
function createUser(params: CreateUserParams) { ... }
1. Verify tests pass → 2. Make one small change → 3. Verify tests pass → 4. Commit → 5. Repeat
refactor(scope): description of structural change
- What was changed and why
- No behavior change
any or casts)What SKILL.md sets; muted values are Claude Code's defaults
162 skills in this plugin
/audit-accessibilityWCAG 2.2 AA audit via playwright-cli: axe-core, keyboard, contrast, target size, focus, ARIA. Use when "audit accessibility", "check a11y", "WCAG audit", "check keyboard nav", or "test screen reader".
/audit-agent-speedMeasure and fix a slow coding-agent setup: status line, hooks, instruction bloat, effort, worktree pile-up, antivirus and indexer scans. Use when "Claude is slow" or "CPU is pinned". App speed → audit-performance.
/audit-analyticsRead-only audit of product-analytics events (PostHog, Amplitude, Mixpanel, GA4): taxonomy, funnels, consent-gated firing, dead or duplicate events. Use when "audit our analytics", "are we tracking the right events", or "funnel instrumentation".
/audit-auth-flowsRead-only audit of app-layer auth: route×gate matrix, session lifecycle, OAuth, provider traps (getSession vs getUser, middleware-only gates, CVE-2025-29927). Use when "audit our auth" or "check middleware protection". RLS → plan-rls-audit.
/audit-backend-architectureRead-only backend-architecture audit and pattern advisor, gated by stack. Use when "audit backend architecture", "which pattern should I use", "am I over-engineering", or "sync vs event-driven". Enforced boundaries → enhance-arch-boundaries.
/audit-bundle-sizeAnalyse and shrink a web app's JavaScript bundle. Use when "reduce bundle size", "code splitting", "slow initial load", or "why is the bundle so big". Runtime → audit-performance.
npx claudepluginhub kensaurus/skills --plugin kenjiOther plugins' skills for the same job