Process Hundreds of Files in Batch with a Shell Loop and --print
When you need to apply the same transformation to many files — adding headers, converting formats, extracting data — combine a shell loop with claude --print for batch processing.
# Add licence headers to every TypeScript file missing one
for file in $(grep -rL "MIT License" src/**/*.ts); do
claude --print "Read $file. If it doesn't have a licence header, add an MIT licence comment block at the top. Output only the complete file contents." > "$file.tmp" && mv "$file.tmp" "$file"
done
For parallel processing, use xargs to run multiple Claude instances at once:
# Convert all Markdown files to have consistent heading styles
find docs/ -name "*.md" | xargs -P 4 -I {} sh -c '
claude --print "Read {} and convert all headings to ATX style (# instead of underlines). Fix any broken links. Output only the file contents." > {}.tmp && mv {}.tmp {}
'
You can also process structured data in bulk:
# Generate TypeScript interfaces from JSON fixture files
for json in tests/fixtures/*.json; do
name=$(basename "$json" .json)
claude --print "Read $json and generate a TypeScript interface named ${name^} that matches the shape. Export it." > "src/types/${name}.ts"
done
Keep the prompts short and specific for batch work — long prompts multiply your token costs across every file.
Shell loops plus --print turn Claude into a batch processing engine for any text transformation you can describe.
Log in to leave a comment.
The /security-review command scans your uncommitted changes for injection vectors, auth gaps, hardcoded secrets, and other common vulnerabilities.
The SessionStart hook fires when any session begins or resumes, making it ideal for loading environment variables and running one-time setup scripts.
Ask Claude to write property-based tests for your functions using fast-check — it identifies the mathematical invariants in your code and generates tests that cover inputs you'd never enumerate by hand.