modular-large-file-refactor
Skill11 starsChanged 19 days agoMITView on GitHub
Refactor oversized source files into smaller, coherent modules while reducing complexity and preserving behavior. Use when Claude needs to split a large component, hook, service, command handler, or Rust module; untangle mixed responsibilities; extract helpers or submodules; or reorganize code into a clearer modular design without changing the public contract.
In this repository48 other files it gives its agents.
- agents.mdAGENTS.md
- .agents/skills/react-best-practices/AGENTS.mdAGENTS.md
- .agents/skills/react-native-skills/AGENTS.mdAGENTS.md
- .agents/skills/react-view-transitions/AGENTS.mdAGENTS.md
- CLAUDE.mdCLAUDE.md
- .github/copilot-instructions.mdCopilot instructions
- agent-initSkill
- agy-delegateSkill
- audit-docsSkill
- code-audit-expertSkill
- computer-diagnosisSkill
- create-builtin-toolSkill
- create-prSkill
- critique-builtin-toolSkill
- doc-auditorSkill
- docxSkill
- extract-log-debugSkill
- feature-refactor-proposalSkill
- gatekeeper-loopSkill
- harbor-harness-improvement-loopSkill
- i18n-language-standardsSkill
- jobs-trace-analyzerSkill
- lean-builtin-tool-auditorSkill
- libragent-qualitySkill
- libr-delegateSkill
- libr-tool-e2e-harness-loopSkill
- performance-auditSkill
- pptxSkill
- vercel-react-best-practicesSkill
- vercel-react-native-skillsSkill
- vercel-react-view-transitionsSkill
- readme-showcase-syncSkill
- refactor-builtin-toolSkill
- release-managerSkill
- review-local-changesSkill
- review-pr-commentsSkill
- science-searchSkill
- setup-wizardSkill
- skill-creatorSkill
- soul-awakeningSkill
- sqlite-analyzerSkill
- sync-pending-approvalsSkill
- tool-creatorSkill
- trace-analyzerSkill
- trace-eval-loopSkill
- vitepress-doc-syncSkill
- worker-loopSkill
- x-cliSkill
The file
Show its rules and text
We split this skill into the rules it gives an agent
18 rules. About 0 are common, 16 are distinctive, and 2 are very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈16
Distinctive · estimate
This author's own choices. Worth a look.
2
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Distinctive: line 17
Keep the original entrypoint stable unless the current public surface is the problem.
- Distinctive: line 22
Use the bundled script first:
- Distinctive: line 35
Use the script output to pick the biggest meaningful source file, then start the modular split.
- Very specific: line 48
Do not create utils.ts or helpers.ts dumping grounds.
- Distinctive: line 49
Do not split a file just to reduce line count.
- Distinctive: line 50
Do not move tightly coupled code into distant files if the reader now has to bounce between five places to understand one flow.
- Distinctive: line 58
Prefer internal re-exports over churning imports across the repo.
- Distinctive: line 74
Keep side effects near the orchestration layer.
- Distinctive: line 78
Leave the original file as the facade that coordinates extracted parts.
- Distinctive: line 85
Put shared UI pieces in sibling component files.
- Distinctive: line 86
Put non-visual behavior in hooks.
- Distinctive: line 87
Put backend calls in service modules that match existing project patterns.
- Distinctive: line 88
Put complex text/data transforms in pure helpers with explicit types.
- Distinctive: line 92
Keep the public module or command handler as the facade.
- Distinctive: line 98
Prefer a small directory with 3-6 purposeful files over one huge file or fifteen trivial ones.
- Distinctive: line 106
Keep error handling explicit.
- Distinctive: line 119
When you finish, describe the refactor in this shape:
- Very specific: line 128
Read references/splitting-patterns.md when you need concrete module patterns for React/TypeScript or Rust, or when the right split boundary …
≈ “Common” is an estimate: at least 1 in 5 of the 350,495 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
Modular Large File Refactor
Refactor one large file into a small set of focused modules without creating a mess of tiny shards. Optimize for lower cognitive load, stable public APIs, and obvious ownership boundaries.
Workflow
- Find the real target first. In this repository, start with the bundled
scripts/find_large_files.shhelper instead of ad-hoc shell pipelines. - Inspect the oversized file and list its responsibilities before touching code.
- Classify each block as one of: public API, orchestration, pure logic, state management, side effects, types, constants, or UI rendering.
- Choose the smallest useful module split that isolates responsibilities cleanly.
- Extract in safe order: constants/types first, pure helpers next, stateful logic after that, and orchestration last.
- Keep the original entrypoint stable unless the current public surface is the problem.
- Re-run the relevant validation after the split.
Built-in Large File Finder
Use the bundled script first:
bash scripts/find_large_files.shWhat it does well:
- scans the repo's real source roots
- ignores dependency and build directories
- highlights severe offenders at
1000+and800+lines - gives a quick ranked list before deeper analysis
Use the script output to pick the biggest meaningful source file, then start the modular split.
Split Decision Rules
Extract a new module when the code has one clear responsibility.
- Pure transforms, parsers, validators, formatters, and mappers belong in their own helpers.
- Shared types, schemas, and constants move out early because they reduce noise with low risk.
- Repeated UI subsections become components only if they own a meaningful chunk of markup or behavior.
- Stateful logic with a clean interface becomes a hook, service, or internal module.
Keep code together when separation would hide the story.
- Do not create
utils.tsorhelpers.tsdumping grounds. - Do not split a file just to reduce line count.
- Do not move tightly coupled code into distant files if the reader now has to bounce between five places to understand one flow.
Extraction Order
1. Stabilize boundaries
- Identify exports that other files already depend on.
- Preserve existing names and call shapes unless changing the contract is intentional.
- Prefer internal re-exports over churning imports across the repo.
2. Remove passive noise
- Extract constants, literal maps, small types, and Zod schemas first.
- Replace repeated inline conditions or object shapes with named helpers.
3. Isolate pure logic
- Pull complex branches into named functions with narrow inputs and outputs.
- Replace nested conditionals with guard clauses when it improves readability.
- Convert anonymous inline callbacks into named functions when they carry real logic.
4. Isolate stateful logic
- Move reusable or bulky state transitions into hooks, services, or internal modules.
- Keep side effects near the orchestration layer; do not bury network or filesystem calls in generic helpers.
5. Simplify the entrypoint
- Leave the original file as the facade that coordinates extracted parts.
- Aim for the top-level file to read like a table of contents for the feature.
Structural Targets
React and TypeScript
- Put shared UI pieces in sibling component files.
- Put non-visual behavior in hooks.
- Put backend calls in service modules that match existing project patterns.
- Put complex text/data transforms in pure helpers with explicit types.
Rust
- Keep the public module or command handler as the facade.
- Move focused logic into sibling modules under the same directory.
- Separate parsing, validation, repository access, and response formatting when they are currently interleaved.
Cross-cutting rule
- Prefer a small directory with 3-6 purposeful files over one huge file or fifteen trivial ones.
Complexity Reduction Moves
- Replace long
if/elseladders with lookup tables only when the behavior is data-driven. - Collapse duplicated setup/teardown into one helper with explicit naming.
- Break giant functions by phase: parse -> validate -> execute -> format.
- Narrow parameter lists by passing a well-named object only when the fields naturally belong together.
- Keep error handling explicit; do not add broad fallback behavior just to make extraction easier.
Anti-Patterns
- Splitting by arbitrary line ranges instead of responsibility
- Creating circular imports between extracted modules
- Hiding critical behavior in vaguely named helpers
- Moving repository or network calls into "pure" utility files
- Re-exporting everything from everywhere
- Changing filenames, symbols, and call paths more than the refactor requires
Output Expectation
When you finish, describe the refactor in this shape:
- What responsibilities were identified in the original file
- Which modules were extracted and why
- Which public entrypoints stayed stable
- Which risky areas were checked after the split
Reference
Read references/splitting-patterns.md when you need concrete module patterns for React/TypeScript or Rust, or when the right split boundary is not obvious.
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

