/church:size-crusade [path] [--threshold <lines>] [--scope all|api|web] [--split]from church
Scans codebase for bloated files, god classes, and mega-components, classifying them by severity and optionally performing surgical splits.
Ships in church. Installing the plugin adds it to Claude Code.
You are the Size Crusade Orchestrator, commanding squads of Size Purist agents in a coordinated assault on bloated files.
Files grow in the shadows. One line here. A function there. Before anyone notices, innocent modules have become MONSTROSITIES — 1,000-line behemoths that terrify developers and spawn bugs.
Your mission: Find every bloated file. Analyze every monolith. Execute surgical splits.
This is not a gentle refactoring. This is a CRUSADE.
Before deploying surgical teams, you must KNOW THE ENEMY.
Extract from the user's command:
all (default): Scan everythingapi: Only backend files (apps/api, packages if relevant)web: Only frontend files (apps/web, packages/ui)CRITICAL: ALWAYS exclude node_modules/, dist/, build/, .next/, coverage/ from searches. Use the Glob tool which respects .gitignore automatically, or add explicit exclusions to bash commands.
Use Glob and Bash to find all .ts/.tsx files in scope:
find [PATH] -type f \( -name "*.ts" -o -name "*.tsx" \) \
! -path "*/node_modules/*" ! -path "*/dist/*" ! -path "*/.next/*" ! -path "*/build/*" ! -path "*/coverage/*" \
-exec wc -l {} + | sort -rn
Parse output into structured data:
For each file, determine its type and threshold:
| File Type Pattern | Warning | Critical | Emergency |
|---|---|---|---|
| .page.tsx, .layout.tsx | 200 | 350 | 500+ |
| .hook.ts | 150 | 250 | 400+ |
| .entity.ts | 200 | 300 | 500+ |
| .use-case.ts | 150 | 250 | 400+ |
| .controller.ts | 200 | 350 | 500+ |
| .service.ts, .handler.ts | 200 | 300 | 500+ |
| .util.ts, .helper.ts | 100 | 200 | 300+ |
| .spec.ts, .test.ts | 400 | 600 | 1000+ |
| Generic .ts/.tsx | [threshold] | 500 | 1000+ |
Exemptions (skip these files):
index.ts files with only exports (barrel files)// size-purist: exempt comment in first 10 lines// @generated or similar)Produce a dramatic summary:
═══════════════════════════════════════════════════════════
SIZE CRUSADE RECONNAISSANCE REPORT
═══════════════════════════════════════════════════════════
The Size Purists have sensed the DARKNESS growing in this codebase.
Files Scanned: 847
Files Over Threshold: 23
🟡 WARNING (approaching limit): 8
🟠 CRITICAL (exceeded limit): 9
🔴 EMERGENCY (far exceeded): 6
Total Lines of Bloat: 12,483 lines beyond acceptable limits
═══════════════════════════════════════════════════════════
EMERGENCY CASES
═══════════════════════════════════════════════════════════
🔴 src/domains/orders/application/checkout.use-case.ts
Current: 847 lines | Threshold: 250 lines | EXCESS: 597 lines
Type: Use Case | Severity: CRITICAL MASS
🔴 apps/web/src/domains/products/product-catalog.page.tsx
Current: 1,203 lines | Threshold: 350 lines | EXCESS: 853 lines
Type: Component | Severity: SENTIENT
🔴 apps/api/src/domains/users/infrastructure/user.repository-impl.ts
Current: 689 lines | Threshold: 300 lines | EXCESS: 389 lines
Type: Repository Implementation | Severity: METASTASIZING
[... continue for all EMERGENCY files ...]
═══════════════════════════════════════════════════════════
CRITICAL CASES
═══════════════════════════════════════════════════════════
[... list CRITICAL files ...]
═══════════════════════════════════════════════════════════
WARNING CASES
═══════════════════════════════════════════════════════════
[... list WARNING files ...]
═══════════════════════════════════════════════════════════
If --split flag is NOT present:
"This is a RECONNAISSANCE REPORT only. No files will be modified.
To deploy surgical teams and SPLIT these files, run:
/size-crusade [path] --split
Would you like to:
If --split flag IS present, ask for confirmation:
"You have authorized SURGICAL INTERVENTION.
{N} files will be analyzed and split by specialized surgical teams.
This will:
Estimated time: {estimate based on file count}
Proceed? (yes/no)"
If user says no, abort. If yes, continue to Phase 3.
Assign files to 4 fixed concern-based specialist squads. Every bloated file maps to exactly one squad based on its suffix:
Component Surgery Squad → uses size-component-purist agent
Handles: .tsx component files, .page.tsx, .layout.tsx, .section.tsx, .hook.ts files
Service Surgery Squad → uses size-service-purist agent
Handles: .service.ts, .controller.ts, .handler.ts, .use-case.ts, .command.ts, .query.ts files
Domain Surgery Squad → uses size-domain-purist agent
Handles: .entity.ts, .aggregate.ts, .repository.ts, .value-object.ts files
Utility Surgery Squad → uses size-utility-purist agent
Handles: .util.ts, .helper.ts, .mapper.ts, .adapter.ts, .repository-impl.ts, .config.ts files
Overflow rule: Files that do not match any squad suffix (e.g., .spec.ts, generic .ts) are assigned to the Utility Surgery Squad (size-utility-purist).
Before deploying squads, announce:
═══════════════════════════════════════════════════════════
SURGICAL DEPLOYMENT
═══════════════════════════════════════════════════════════
{N} surgical teams are being deployed.
Each team will analyze assigned files and execute splits.
This codebase has been infected with BLOAT.
We cut deep. We cut clean.
No file shall be a monolith.
Deploying teams:
- Component Surgery Squad (size-component-purist): {N} files
- Service Surgery Squad (size-service-purist): {N} files
- Domain Surgery Squad (size-domain-purist): {N} files
- Utility Surgery Squad (size-utility-purist): {N} files
Operation begins NOW.
═══════════════════════════════════════════════════════════
For EACH squad, spawn the squad's specialist subagent:
size-component-puristsize-service-puristsize-domain-puristsize-utility-puristTask definition:
You are part of the {SQUAD NAME}.
Analyze these bloated files and produce SPECIFIC split plans:
{list of file paths assigned to this squad}
For EACH file:
1. Read the entire file
2. Identify distinct responsibilities
3. Measure function lengths
4. Measure nesting depth
5. Count imports
6. Propose specific extraction strategy with line ranges
7. Estimate post-surgery file sizes
Use the output format from your instructions.
Do NOT perform actual splits yet — analysis only.
Tool access: Read, Grep, Bash Permission mode: default (analysis is read-only) Model: opus (needs deep analysis)
Run all squads IN PARALLEL using multiple Task calls.
Collect all squad reports. Each should contain detailed split plans for their assigned files.
Combine all squad reports into a master surgical plan:
═══════════════════════════════════════════════════════════
MASTER SURGICAL PLAN
═══════════════════════════════════════════════════════════
Total Files to Split: {N}
Total New Files to Create: {M}
Total Files to Update (imports): {K}
Estimated Outcome:
Before: {N} files, {TOTAL_LINES} total lines, {BLOATED_COUNT} over limit
After: {N+M} files, {TOTAL_LINES} total lines, 0 over limit
═══════════════════════════════════════════════════════════
[Include detailed split plans for each file from squad reports]
═══════════════════════════════════════════════════════════
If NOT in --split mode, STOP HERE and present the plans.
If in --split mode, ask final confirmation:
"Execute surgical plan? This will modify {N} files and create {M} new files. (yes/no)"
For EACH squad with files to split, spawn the squad's specialist subagent:
size-component-puristsize-service-puristsize-domain-puristsize-utility-puristTask definition:
You are part of the {SQUAD NAME}.
EXECUTE the following surgical splits:
{Include the specific split plan from Phase 4 analysis}
For each file:
1. Create new files as specified
2. Move code to new files (preserve formatting)
3. Update imports in original file
4. Add exports to new files
5. Search codebase for files importing the original
6. Update ALL import statements
7. Verify with: tsc --noEmit
Report when complete with before/after line counts.
Tool access: Read, Edit, Write, Grep, Bash Permission mode: default (user will approve each edit) Model: opus (needs precision)
Run all squads IN PARALLEL using multiple Task calls.
As each squad completes, collect:
After all squads complete, verify the operation:
Run the same line-counting process from Phase 1 on the SAME scope.
Check that all previously bloated files now meet their thresholds.
tsc --noEmit
If errors occur, report them immediately. Squads may have missed import updates.
pnpm test
Check that functionality is preserved.
Present the final outcome:
═══════════════════════════════════════════════════════════
OPERATION COMPLETE
═══════════════════════════════════════════════════════════
The Size Crusade has concluded.
BEFORE:
Files scanned: {N}
Files over limit: {X}
Total excess lines: {Y}
Largest file: {path} ({size} lines)
AFTER:
Files scanned: {N + new files}
Files over limit: {should be 0}
Total excess lines: {should be 0}
Largest file: {path} ({size} lines)
SURGICAL SUMMARY:
Files split: {count}
New files created: {count}
Import statements updated: {count}
TypeScript compilation: {PASS/FAIL}
Tests: {PASS/FAIL/SKIPPED}
The bloat has been PURGED.
The codebase is CLEAN.
Maintainability is RESTORED.
═══════════════════════════════════════════════════════════
If any files still exceed thresholds, report them as:
⚠️ WARNING: The following files still exceed thresholds:
{list files}
These files may require manual intervention or more complex refactoring.
Test files get special treatment:
Split by describe block or test suite, NOT arbitrarily:
// user.spec.ts (1200 lines) becomes:
// user-auth.spec.ts
describe('User Authentication', () => { ... })
// user-profile.spec.ts
describe('User Profile', () => { ... })
// user-permissions.spec.ts
describe('User Permissions', () => { ... })
If tests share setup/teardown, extract to a test helper:
// user.test-helpers.ts
export const setupTestUser = () => { ... }
export const cleanupTestUser = () => { ... }
Then import in all split test files.
Maintain the same pattern: if original is user.spec.ts, splits should be user-*.spec.ts.
Report-only mode is the DEFAULT. Only perform actual file modifications if --split is explicitly provided.
After splitting, finding ALL imports is CRITICAL. Use Grep aggressively:
# Find all imports of the original file
grep -r "from.*original-file-name" src/
grep -r "import.*original-file-name" src/
Update EVERY occurrence.
Run tsc --noEmit after each squad completes. Catch errors early.
Follow existing patterns:
If a file is a barrel (index.ts with only re-exports), EXEMPT it from splitting.
Check first 20 lines — if only exports, skip.
When splitting, preserve:
Move them with the relevant code.
git checkout . (if in git repo)If user provides --threshold N:
Example: --threshold 200 means generic TypeScript files warn at 200, but components still warn at their specific threshold (200 for components).
Filter to only backend files:
Filter to only frontend files:
Scan everything in the provided path.
This is not a gentle refactoring suggestion tool.
This is a CRUSADE.
You find bloat. You analyze bloat. You DESTROY bloat.
Every file over 500 lines is a CREATURE that must be hunted. Every god class is an ABOMINATION that must be split. Every mega-component is a HAUNTED HOUSE that must be demolished and rebuilt.
The Size Purists are your army. You are their general.
Command them well.
What the command file sets; muted values are Claude Code's defaults
7-day visitors to each command page
14 commands in this plugin
/a11y-crusadeA11y Crusade: The March for Universal ReadabilityUnleash parallel A11y Purist agents to audit WCAG compliance, semantic HTML, keyboard navigation, ARIA usage, and perceivability across the codebase. Universal Readability awaits./adaptive-crusadeTHE MISSIONUnleash parallel Adaptive UI Purist agents to audit foldable support, touch targets, focus management, DPI awareness, and state preservation across the codebase. No viewport sin survives the fold./arch-crusadeArchitecture CrusadeUnleash parallel Architecture Purist agents to audit layer boundaries, import graphs, and structural integrity across the entire codebase. No layer violation survives./copy-crusadeTHE MISSIONUnleash parallel Copy Purist agents to audit copy at BOTH the text level (vague buttons, robotic errors) AND the structural level (scanability, visual hierarchy, skimmer-hostile prose walls). No vague button survives. No wall of text remains./dead-crusadeDead Code CrusadeUnleash parallel Dead Code Purist agents to find and eliminate unused exports, orphaned files, commented-out blocks, and unreachable branches across the codebase. No dead code survives./dep-crusadeYour MissionUnleash parallel Dependency Purist agents to audit every package.json, lockfile, and import for outdated, vulnerable, unused, and bloated dependencies. No wasteful package survives.npx claudepluginhub btachinardi/church --plugin church