Refactor a specific file by splitting it into smaller action/component files
Refactors large files by extracting code into smaller, focused components following project conventions.
/plugin marketplace add MaxBoiko21/claude-plugins-marketplace/plugin install code-splitter@own-plugins-marketplace<file-path>Analyze a specific file and execute refactoring to split it into smaller, focused components following action pattern conventions.
file-path (required): Full path to the file to refactor.claude/code-splitter.local.md from project rootCreate a detailed plan showing:
For each extraction:
Example Laravel plan:
Refactoring Plan: app/Http/Controllers/UserController.php
═════════════════════════════════════════════════════════
Current Issues:
• File size: 425 lines (125 lines over threshold)
• Methods: 15 (5 methods over threshold)
• Mixed concerns: routing, validation, business logic, email sending
Proposed Extractions:
1. Create User Action
File: app/Actions/Users/CreateUserAction.php
Extracts: store() method business logic
Dependencies: User model, Mail service
Connections: Controller calls this action
2. Update User Action
File: app/Actions/Users/UpdateUserAction.php
Extracts: update() method business logic
Dependencies: User model
Connections: Controller calls this action
3. Delete User Action
File: app/Actions/Users/DeleteUserAction.php
Extracts: destroy() method logic
Dependencies: User model
Connections: Controller calls this action
4. Send User Invitation
File: app/Actions/Users/SendUserInvitationAction.php
Extracts: sendInvitation() method
Dependencies: Mail service
Connections: Controller calls this action
Result:
• Controller reduced to ~50 lines (routing only)
• Each action has single responsibility
• Code is testable and reusable
• Following Laravel action pattern
For React/Vue, show component breakdown:
Refactoring Plan: src/components/UserDashboard.tsx
═════════════════════════════════════════════════
Current Issues:
• Component size: 380 lines (80 over threshold)
• Mixed concerns: data fetching, form state, rendering
• No child components
Proposed Extractions:
1. useUserData Hook
File: src/hooks/useUserData.ts
Extracts: User fetching logic
Dependencies: React Query/SWR
Connections: UserDashboard imports and uses it
2. UserProfile Component
File: src/sections/UserProfile.tsx
Extracts: Profile rendering section
Dependencies: User type
Connections: Receives user prop from UserDashboard
3. UserForm Component
File: src/sections/UserForm.tsx
Extracts: Form rendering and submission
Dependencies: useUserForm hook
Connections: Receives user prop, calls onSuccess
4. UserActivity Component
File: src/sections/UserActivity.tsx
Extracts: Activity list rendering
Dependencies: useUserActivities hook
Connections: Receives userId prop
Result:
• Dashboard component: ~50 lines of layout
• Each section has single responsibility
• Reusable hooks and components
• Better code organization
Format as structured proposal:
Allow user to:
For each extraction the user approved:
Create new file:
Update original file:
Validate syntax:
Show user what was created:
✅ Refactoring Complete!
═════════════════════════════════════════
Files Created:
✓ app/Actions/Users/CreateUserAction.php (45 lines)
✓ app/Actions/Users/UpdateUserAction.php (38 lines)
✓ app/Actions/Users/DeleteUserAction.php (25 lines)
Files Modified:
✓ app/Http/Controllers/UserController.php
Reduced from 425 → 65 lines
Result:
• Original controller now focused on routing only
• Each action has clear single responsibility
• Code is testable and reusable from multiple places
• Following Laravel action pattern
Next Steps:
1. Run tests to verify functionality
2. Check imports if using IDE
3. Consider creating test files for new actions
After refactoring, suggest improvements:
💡 Suggestions for Further Improvement:
1. Create Factory for CreateUserAction tests
Path: database/factories/UserFactory.php
2. Consider extracting validation to Form Request
Path: app/Http/Requests/StoreUserRequest.php
3. Add event dispatching for user creation
Would allow notifications without tight coupling
app/Actions/ (Laravel) or src/Service/ (Symfony)handle() or execute() methodsrc/hooks/src/components/ or src/sections/use prefixsrc/composables/src/components/ or src/views/use prefixsrc/services/Before Creating Files:
Import Updates:
Read .claude/code-splitter.local.md:
laravel_actions_path: Where to create Laravel actionsreact_components_path: Where to create React componentsvue_composables_path: Where to create Vue composablesnode_services_path: Where to create Node services