Skip to content

Fan Out Across Files

For large migrations, split the work into many small Claude runs instead of one huge session.

In a git repository, the bundled /batch skill does this for you:

Terminal window
/batch migrate src/ from JavaScript to TypeScript

It 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.

  1. Generate a list of files.
  2. Test the prompt on two or three files.
  3. Refine the prompt.
  4. Loop over the full list.
  5. Verify with tests, lint, or a build.
Terminal window
for file in $(cat files.txt); do
claude -p "Migrate $file to the new API. Return OK or FAIL." \
--allowedTools "Edit,Bash(npm test *)"
done
  • Each file gets a smaller context.
  • Failures are isolated.
  • You can retry individual files.
  • Permission scope can be limited with --allowedTools.

Keep destructive commands out of unattended fan-out workflows. Start with a tiny sample and review the diff before scaling up.