Fan Out Across Files
For large migrations, split the work into many small Claude runs instead of one huge session.
Try /batch first
Section titled “Try /batch first”In a git repository, the bundled /batch skill does this for you:
/batch migrate src/ from JavaScript to TypeScriptIt researches the codebase, splits the change into 5 to 30 independent units, and presents a plan. Once you approve, it runs one background subagent per unit in its own git worktree. Each one implements its unit, runs tests, and opens a pull request.
Use the claude -p loop below when you want to drive the fan-out from your own script.
Basic pattern
Section titled “Basic pattern”- Generate a list of files.
- Test the prompt on two or three files.
- Refine the prompt.
- Loop over the full list.
- Verify with tests, lint, or a build.
Example
Section titled “Example”for file in $(cat files.txt); do claude -p "Migrate $file to the new API. Return OK or FAIL." \ --allowedTools "Edit,Bash(npm test *)"doneWhy this helps
Section titled “Why this helps”- Each file gets a smaller context.
- Failures are isolated.
- You can retry individual files.
- Permission scope can be limited with
--allowedTools.
Guardrails
Section titled “Guardrails”Keep destructive commands out of unattended fan-out workflows. Start with a tiny sample and review the diff before scaling up.