Skip to content
Back to skills

Fan Out Migration

ASecurity

Use when a repetitive, mechanical change must be applied across many files — a bulk migration, codemod, rename, or API/import update spanning a whole codebase. Covers generating a task list to a file and looping a scoped headless `claude -p` per file, testing on a few files before running at scale.

  • 2 stars
  • 0 votes
  • 0 copies
  • 1 view
  • Added October 1, 2026
ai-agentsshellbashtestinggitapi

Works with

  • api

Security analysis

A100/100

Pro scans all 2 files and shows the line behind each finding

Scanned October 1, 2026

npx -y skills add matthews-wong/claude-code-plugins --skill fan-out-migration --agent claude-code

Installs into .claude/skills of the current project.

Are you the author of Fan Out Migration?

Add the live security badge to your README. It updates with every re-scan.

Security grade badge for Fan Out Migration
[![Security: A — Skills Directory](https://www.skillsdirectory.com/api/skills/matthews-wong-fan-out-migration/badge)](https://www.skillsdirectory.com/skills/matthews-wong-fan-out-migration)

More formats (shields.io, HTML) on the badges page. Keep it an A: scan every change in CI with Pro.

Download with Pro
SKILL.md
---
name: fan-out-migration
description: Use when a repetitive, mechanical change must be applied across many files — a bulk migration, codemod, rename, or API/import update spanning a whole codebase. Covers generating a task list to a file and looping a scoped headless `claude -p` per file, testing on a few files before running at scale.
---

# Fan out across files

Some changes are the same edit repeated over dozens or hundreds of files. Doing that in one conversation blows the context and degrades partway through. Instead, fan out: drive one small, scoped, headless Claude run per file, coordinated by a shell loop.

## The workflow

1. **Generate a task list to a file.** Find every target (Glob/Grep) and write the paths to `files.txt`, one per line. The worklist lives on disk, not in context — that's what lets it scale to hundreds of files.

2. **Write a precise per-file prompt.** A single, self-contained instruction for transforming one file, runnable with no conversation history. Ambiguity is multiplied across every file, so state exactly what to change and what to leave alone.

3. **Scope `--allowedTools` tightly.** Give each run only what it needs, e.g. `--allowedTools "Edit,Bash(git commit *)"`. Least privilege per iteration limits the blast radius if the prompt misbehaves.

4. **Test on 2–3 files first.** Point the loop at a tiny `files.txt` of representative files, run it, and inspect the diffs. Iterate on the prompt until it's reliably correct on the sample.

5. **Run at scale, then verify the aggregate.** Expand to the full list and run. Then verify the whole batch — build, tests, `git diff` — because per-file success doesn't prove the whole migration is correct.

## The loop (see `scripts/fan-out.sh`)

The bundled `scripts/fan-out.sh` is a commented POSIX-sh template:

```sh
while IFS= read -r file; do
  claude -p "APPLY <the change> to $file. Do X. Do NOT do Y." \
    --allowedTools "Edit,Bash(git commit *)"
done < files.txt
```

It ships **non-destructive by default**: it prints (dry-runs) each command instead of executing it, so you can eyeball the exact invocations first. You edit the prompt and tool scope, prove it on a sample `files.txt`, then uncomment the live line to run for real.

## Principles

- **Small, uniform, mechanical** changes fan out well; judgment-heavy or interdependent edits don't — do those interactively.
- **Prompt precision matters more here** than anywhere, because errors replicate across every file.
- **Commit per file** (via the scoped `git commit`) so each change is isolated and easy to revert.
- **Always sample before scale.** Never point an unproven prompt at the full list.

See `reference/harness-guide.md` for prompt-design detail, resuming a partial run, parallelism, and post-run verification.

Files in this skill

  • SKILL.md2.7 KB
  • reference/harness-guide.md2.5 KB

Attribution

Is this your skill, or is something wrong with this listing? Request removal or report an issue. Author removals are honored within 72 hours.

Comments

Loading comments…