$ recombobulate _
home / tips / process-hundreds-of-files-in-batch-with-a-shell-loop-and-print
0

Process Hundreds of Files in Batch with a Shell Loop and --print

bagwaa @bagwaa · Mar 26, 2026 · Workflows
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.

~/recombobulate $ tip --comments --count=0

Log in to leave a comment.

~/recombobulate $ tip --related --limit=3
0
Scan Pending Changes for Security Issues with /security-review

The /security-review command scans your uncommitted changes for injection vectors, auth gaps, hardcoded secrets, and other common vulnerabilities.

bagwaa @bagwaa · 1 hour ago
0
Run Setup Scripts on Every Session with the SessionStart Hook

The SessionStart hook fires when any session begins or resumes, making it ideal for loading environment variables and running one-time setup scripts.

bagwaa @bagwaa · 1 hour ago
0
Write Property-Based Tests with fast-check and Claude

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.

bagwaa @bagwaa · 2 hours ago