Extract a Module
Workflow for splitting a large file into focused modules
CLAUDE.md
When splitting a large file into modules:
- Identify groups of related functions, types, and constants that serve a single purpose.
- Verify the existing code has tests. If not, add characterization tests before refactoring.
- Create a new file for each logical group. Name it after its responsibility.
- Move the related code to the new file. Update imports in the original file to reference the new module.
- Update all other files that imported the moved code to use the new paths.
- Run the tests after each move to catch broken imports immediately.
- Verify the original file is smaller and more focused. Each file should have a clear, single responsibility.
Copy this workflow into your CLAUDE.md or agent config file so your agent follows this process automatically.