Run the Same Refactor Across Many Repos With One Prompt
A multi-repo refactoring prompt that sequences the same change across separate repositories, handles shared contracts, and plans a safe rollout.
Changing one function signature inside a single repo is a five-minute job. Changing that same signature across nine repos that all call it, when three of them are owned by other teams and deploy on their own cadence, is a week of coordination. That's the job a multi-repo refactoring prompt is built for: not the edit itself, but the sequencing, the contract versioning, and the rollout order that keeps everything green while the change is half-done.
Most published guidance on AI refactoring is monorepo-shaped. It assumes you can change a shared type and fix every caller in one atomic commit. Separate repositories break that assumption hard. The change lands at different times, in different deploy windows, often without you holding the merge button for the downstream repos. So the planning has to account for a system that's inconsistent for hours or days while the migration rolls through.
This post covers the prompt that produces that plan, and the prompt-craft patterns that keep it honest.
Why the same refactor is harder across separate repos
A multi-repo refactor is a single logical change that has to be applied independently to several repositories that share a contract but not a build. The hard part isn't the code. It's the ordering and the overlap window.
Three things make it different from the monorepo case:
- No atomic commit. You can't change a producer and its consumers in one PR. The producer ships, then each consumer catches up on its own timeline. Between those events, both the old and new shapes have to work.
- Shared contracts are live. If repo A publishes an API or a package that repos B and C depend on, you can't just rename the field. You version it, ship both, migrate the consumers, then remove the old one. That's three rollouts, not one.
- Ownership is split. Some of those consumer repos belong to other teams. The plan has to produce a PR description and a deprecation note they'll actually act on, not just a diff.
The pages that currently rank for cross-repo refactoring gloss over this. Augment Code's multi-file refactoring guide mentions changes that "span multiple repositories" and a system that "makes them all at once," but its detailed walkthrough is a single Python rename inside one repo, and it gives no copyable prompt or sequencing mechanics. The Moderne and large-scale-refactoring tooling write-ups lean on platform automation that rewrites code across repos in bulk, which is great if you've bought the platform, but says nothing about how to plan the change with a model you already pay for. The gap is a copyable prompt with a locked output contract that any team can run today.
What you can do with this prompt
- Turn a one-line change ("rename
userIdtoaccountIdeverywhere") into an ordered, repo-by-repo migration plan. - Decide which repo is the producer and must change first, and which are consumers that follow.
- Generate the versioning strategy for a shared API or package so nothing breaks during the overlap.
- Produce per-repo diffs plus the PR description for the teams that own each consumer.
- Get a rollback point for each step, so a failed deploy doesn't strand the system half-migrated.
- Output a verification checklist that proves each repo is consistent before the next one moves.
Anatomy of the prompt
The structure that holds up puts the inventory and the contract first, the change second, and the output contract last. Models weight the most recent tokens, so the format spec belongs at the end where it won't get buried under repo context.
Variables
{{repo_inventory}} → name, role (producer/consumer), language, deploy cadence per repo
{{shared_contract}} → the API/package/type every repo depends on
{{target_change}} → the refactor in one sentence
{{constraints}} → freeze windows, teams you can't block, must-stay-backward-compatible
Prompt
Role: staff engineer planning a cross-repo migration.
Task: order the repos, version the shared contract, and plan rollout.
Context: the variables above.
Output contract (locked)
1. Dependency graph: which repo depends on which
2. Sequence: ordered list, producer-first, with the reason each repo is at that position
3. Per-repo plan: the diff, the PR title/description, the rollback point
4. Contract versioning: how the old + new shapes coexist during overlap
5. Verification: the check that must pass before the next repo moves
1. Gather inputs
List every repo touched by the change. For each, note whether it produces the shared contract or consumes it, what language it's in, and roughly how often it deploys. The deploy cadence matters more than people expect. A consumer that ships once a sprint sets the length of your overlap window.
2. Fill the variables
Paste the inventory into {{repo_inventory}}. Name the exact thing that's shared in {{shared_contract}} (a REST field, a gRPC message, a published npm package, a shared TypeScript type). Write the change in one sentence in {{target_change}}. Be specific in {{constraints}}: "marketing-web deploys Tuesdays only" or "the billing team can't take a breaking change before Q3."
3. Run the prompt and read the sequence first
Before you look at any diff, read the ordering and the reasoning. If the model put a consumer ahead of its producer, the inventory was wrong or the roles were mislabeled. Fix the input, don't argue with the output.
4. Execute one repo at a time
Hand each per-repo plan to a coding agent or do it by hand. The point of the sequence is that you finish and verify one repo, confirm the system is still consistent, then start the next. Never open all nine PRs at once.
5. Iterate on the overlap
The contract-versioning section is where reality bites. If the plan says "ship both userId and accountId for two weeks," that's a real two weeks of dual-write or dual-read code you have to add and later remove. Budget for the cleanup pass. It's a separate, smaller refactor of its own.
Prompt-craft patterns that make it reliable
Pattern 1: producer-first sequencing as a hard rule
Tell the model the rule explicitly instead of hoping it infers ordering from the dependency graph.
Hard rule: a consumer repo NEVER changes before the producer it depends on
has shipped the new contract. If two repos both produce and consume, split
them into two steps and order each half independently.
Without this, models occasionally output an alphabetical or size-based order that looks tidy and breaks production. State the invariant.
Pattern 2: force the backward-compatible overlap into the output
For any shared contract change, the plan MUST include an overlap phase where
both the old and new shape are valid. Name the mechanism (additive field,
versioned endpoint, aliased export) and the exact step that removes the old
shape. A plan that flips the contract in one step is invalid output.
This is the pattern that separates a usable plan from a dangerous one. Claude honors a hard "this output is invalid if X" instruction more reliably than a soft "please consider backward compatibility." GPT-4o tends to need the rule restated near the end of the prompt to keep it from drifting on long repo lists.
Pattern 3: a rollback point per step, not per migration
Each step in the sequence gets its own rollback point: the commit/tag to
revert to and the one check that confirms the revert is clean. Do not output
a single rollback for the whole migration.
A migration that's only reversible as a whole isn't reversible in practice. Per-step rollback is what lets you stop safely when repo five's deploy goes sideways.
Here's the opinionated part. Don't ask one model to refactor all the repos in a single call, even with a huge context window. The plan is the durable artifact; the edits are disposable. A clean sequence with per-repo diffs that a human reviews beats a 50-file mega-diff nobody can audit. Splitting planning from execution is the whole point, and it's the thing the "make them all at once" marketing quietly skips.
Variables you'll set
| Variable | Required | What it is |
|---|---|---|
{{repo_inventory}} | Yes | Each repo: name, producer or consumer, language, deploy cadence |
{{shared_contract}} | Yes | The exact API, package, or type the repos share |
{{target_change}} | Yes | The refactor in one sentence |
{{constraints}} | No | Freeze windows, teams you can't block, compatibility requirements |
Getting started
- List every repo the change touches and tag each as producer or consumer.
- Name the one shared contract precisely. If there are two, run the prompt twice.
- Fill
{{target_change}}in a single sentence. Vague changes produce vague plans. - Run the prompt and read the sequence and reasoning before any diff.
- Execute repo one, verify consistency, then move to repo two.
- Schedule the overlap-cleanup pass as its own task once every consumer has migrated.
- For a recurring cross-repo cadence, reach for the Multi-Repo Orchestration Agent Pack rather than rebuilding the plan each time.
If your change is contained to one repo with internal modules instead, the Monorepo Impact Analysis Agent Pack maps the blast radius inside a single tree, and a cross-language refactor prompt handles the case where the same logic has to move between languages.
The Multi-Repo Orchestration Agent Pack does this end-to-end: a {{repo_inventory}} variable feeds a planner whose locked output contract always emits producer-first sequencing, a contract-overlap phase, and a per-step rollback point, plus a companion prompt that drafts the consumer-team PR descriptions. It's part of The Complete AI Prompts Bundle, a one-time lifetime license to the whole catalog plus every pack added later, worth it if you coordinate changes across repos more than once.
The plan is the artifact that survives the migration. A spreadsheet of "who changes when" goes stale the moment the first deploy slips. A prompt you re-run against the current repo inventory doesn't. For the wider story on scoping change before you touch code, the change blast-radius prompt and the technical-debt triage prompt both feed the same planning muscle.
See the multi-repo orchestration pack →Common questions
What is a multi-repo refactoring prompt?
How is this different from a monorepo refactor?
Can ChatGPT or Claude refactor multiple repos at once?
Get the prompt packs this guide is built on
Ready-to-paste prompts with documented variables and usage guides for ChatGPT, Claude, and Gemini. One-time payment, own it forever.
More prompt guides

Keep Docs in Sync With Code: A Prompt That Catches Drift
The README says the function takes three arguments. Someone added a fourth six months ago. Nobody updated the docs, because nothing forced them to. That's documentation drift, and it's the default sta…

Service Dependency Audit Prompt: Map Coupling Risk
Every architecture diagram lies a little. It shows the dependencies someone remembered to draw, not the ones that grew in over three years of shipping. A service dependency audit prompt reads the actu…

Tabletop Exercise Prompt: Build an IR Scenario in Minutes
Most security teams run the same tabletop exercise twice and then stop. The scenario PDF goes stale, the injects name systems the team retired a year ago, and nobody wants to spend a week writing a fr…