DEV Community

brian austin
brian austin

Posted on

Claude Code parallel file editing: how to modify 50 files without going insane

Claude Code parallel file editing: how to modify 50 files without going insane

You know that moment when you rename a function and realize it's used in 47 different files?

Most devs do this:

  1. Ask Claude to fix file 1
  2. Ask Claude to fix file 2
  3. ... 45 more times
  4. Lose the will to live

There's a better way.

The batch edit pattern

Claude Code can handle multi-file refactors in a single instruction — but only if you frame it correctly.

Bad prompt:

Rename getUserData to fetchUser
Enter fullscreen mode Exit fullscreen mode

Good prompt:

Rename getUserData to fetchUser across the entire codebase.
Search every .js and .ts file.
Update all imports, all call sites, all type definitions.
Show me a list of every file you changed.
Enter fullscreen mode Exit fullscreen mode

The second prompt activates Claude's multi-file awareness. The first one only fixes the current file.

Use CLAUDE.md to define scope

If you're doing a large refactor, add this to your CLAUDE.md temporarily:

## Current refactor scope
- Renaming: getUserData → fetchUser
- Files in scope: src/**/*.ts, tests/**/*.ts
- Files OUT of scope: node_modules, dist, build
- After each file change, verify imports compile
Enter fullscreen mode Exit fullscreen mode

This gives Claude persistent context so it doesn't forget what it's doing mid-refactor.

Remove this section when the refactor is done.

The parallel subagent trick

For very large codebases (500+ files), single-threaded editing is too slow. Use subagents:

## Refactor task

Split this work across 4 parallel subagents:

Subagent 1: Rename getUserData → fetchUser in src/api/
Subagent 2: Rename getUserData → fetchUser in src/components/
Subagent 3: Rename getUserData → fetchUser in src/utils/
Subagent 4: Update all test files in tests/

Each subagent should:
1. List files it will touch
2. Make changes
3. Report completion

Wait for all 4 before proceeding.
Enter fullscreen mode Exit fullscreen mode

This cuts refactor time by ~4x on large codebases.

Checkpoint pattern for safety

When doing destructive edits, add explicit checkpoints:

Refactor getUserData → fetchUser

After every 10 files:
- Run: tsc --noEmit
- If TypeScript errors, stop and report them
- Don't proceed until errors are fixed

At completion:
- Run full test suite
- Show me the diff summary
Enter fullscreen mode Exit fullscreen mode

This catches breakage early instead of at the end when you've touched 50 files.

The "explain first" pattern

Before any large refactor, ask Claude to plan it:

Before making any changes, show me:
1. Every file that references getUserData
2. The different ways it's called (direct, destructured, re-exported)
3. Any edge cases that might break
4. Your proposed order of changes

Don't start editing until I approve the plan.
Enter fullscreen mode Exit fullscreen mode

This reveals surprises — like when a function is re-exported from 3 barrel files and you only knew about one.

Real example: renaming across 50 files in 3 minutes

Here's a real CLAUDE.md entry I use for refactors:

## Refactor protocol

When I say "rename X to Y":
1. First: grep -r "X" src/ to find all occurrences
2. Report: N files affected, list them
3. Ask: "Proceed?" and wait for my approval
4. Execute: change all files
5. Run: tsc --noEmit
6. Report: "Done. N files changed. TypeScript: clean"

Never start editing without my approval.
Never stop mid-refactor without reporting why.
Enter fullscreen mode Exit fullscreen mode

With this in CLAUDE.md, every refactor follows the same safe pattern automatically.

The flat-rate advantage

Parallel file editing burns tokens fast. Reading 50 files + writing 50 files = a lot of API calls.

If you're on Anthropic's pay-per-token plan, a big refactor can cost $3-8.

I route my Claude Code through SimplyLouie ($2/month flat rate) specifically for refactor-heavy work. The ANTHROPIC_BASE_URL swap takes 10 seconds:

export ANTHROPIC_BASE_URL=https://api.simplylouie.com
Enter fullscreen mode Exit fullscreen mode

Same model (claude-sonnet-4-5), no token counting anxiety, refactor as much as you want.

Summary

Pattern Use when
Batch instruction < 20 files, simple rename
CLAUDE.md scope Ongoing refactor over multiple sessions
Parallel subagents 100+ files, time-sensitive
Checkpoint pattern Risky changes (DB schema, API contracts)
Explain-first Unknown codebase, complex dependencies

The biggest mistake I see: treating Claude Code like a single-file editor. It's not. It's a codebase-aware agent — use it at that scale.


What's your biggest refactor nightmare? Drop it in the comments.

Top comments (0)