Skip to main content

Claude Code Prompt for a Safe Large-Scale Rename Across a Repo

Rename a symbol, file, or concept across an entire codebase with Claude Code. Grep every usage, review a risk-ranked diff plan, apply it safely, then verify.

Fill in the placeholders

Edit the values, then copy your finished prompt.

Your Prompt
prompt.txt

                                

What this prompt does

A find-and-replace rename breaks the moment a name shows up somewhere it doesn't look like a name: a route alias, a serialized cache key, a string in a config file, a heading in your docs. This prompt forces Claude Code through a discovery-first workflow instead. Step one greps every occurrence across code, tests, docs, and config — so the rename is scoped from real matches, not guesses — before a single line changes.

It works because the order is deliberate. The diff plan is grouped by file with a risk rating per group, so you see the dangerous edits (public exports, shared interfaces, route names) separately from the trivial ones. Only then does it apply the change while explicitly preserving imports, route names, and public API shape, update the tests and docs that referenced the old name, and run the type check and test suite as proof. Anything it can't safely automate comes back as a manual follow-up list.

The hard stop before shared interfaces is the safety valve: a rename that's local to one module is cheap, but one that touches a contract other code depends on gets a confirmation gate instead of a silent edit.

When to use it

  • Renaming a class, function, or variable whose name leaked into route names, event names, or cache keys.
  • Moving or renaming a file and needing every import path, autoload reference, and test fixture updated with it.
  • Retiring confusing domain language (e.g. MemberCustomer) consistently across code, tests, and docs in one pass.
  • Cleaning up an inconsistent name that exists in several casings — userId, user_id, UserID — where blind replace is unsafe.
  • Renaming something exposed in a public API or package export, where you need the risk flagged before you touch the contract.
  • Any rename big enough that you want a reviewable plan and a green test run, not a hopeful commit.

Example output

Renaming `fetchUser` → `loadUser` (type: function)

Occurrences found: 23 across 11 files

PLAN (grouped, risk-ranked)
  src/api/users.ts        2  [HIGH]  exported — public API, callers external
  src/services/auth.ts    5  [MED]   internal callers, one DI binding
  tests/users.test.ts     9  [LOW]   test names + assertions
  docs/api.md             4  [LOW]   code samples, no logic
  CHANGELOG.md            3  [SKIP]  historical entries — leave as-is

⚠ src/api/users.ts re-exports fetchUser as a public symbol.
  Confirm before I touch this shared interface?

After confirm → apply, then:
  ✔ tsc --noEmit  passed
  ✔ vitest        48 passed
  Manual follow-up: add `export { loadUser as fetchUser }` shim if
  downstream packages still import the old name.

Pro tips

  • Be precise with [rename_type]function, class, file, route name, env var. The type tells Claude which references are real (a file rename means import paths and autoload entries; a route name means templates and redirects), which sharpens the grep and cuts false matches.
  • For a public symbol, decide your compatibility story up front: rename clean and break callers, or keep a deprecated alias/shim. State it in the prompt so the "manual follow-ups" step plans for it instead of surprising you.
  • Trust the risk ranking as your review map. Skim the LOW groups, read every line of the HIGH ones — that's where a rename quietly changes a contract.
  • Pair it with a clean working tree and a branch. The test-and-type-check step is your proof the rename held; a clean diff makes the review (and the revert, if needed) trivial.
  • Watch the casing trap: OrderId rarely lives in one form. Ask it to surface every casing variant in the grep step so you choose which to rename, rather than letting one slip through.

Frequently Asked Questions

Will it rename things inside strings and comments, or only real code references?
It greps everything first — including strings, comments, config, and docs — then groups the matches by file with a risk rating so you can decide. A name in a route alias or cache key is a real reference you want changed; one in a historical changelog entry usually isn't. You review the plan and confirm before it applies, so string matches are surfaced rather than blindly rewritten.
What does "stop and confirm before touching shared interfaces" actually do?
When the rename reaches a public export, a shared contract, or anything other code depends on, Claude pauses and asks instead of editing silently. That gives you the chance to keep a backward-compatible alias, plan a deprecation, or coordinate with callers. Local-only renames proceed without the gate; only the edits that can break consumers trigger the confirmation.
It says tests passed — does that mean the rename is fully safe to merge?
A green type check and test run is strong evidence, not a guarantee. It catches broken imports, signatures, and anything your tests exercise. It won't catch references outside the repo (other services, dynamic string lookups, external API consumers) — which is exactly why the prompt ends with a manual follow-up list. Read that list before you merge.
Engr Mejba Ahmed

Need this built for real?

Engr Mejba Ahmed

AI Developer · Software Engineer

I'm Mejba — I design and ship production AI systems, automations, and full-stack apps. If you want this turned into a working solution for your team, let's talk.

More in Claude Code Prompts

Engr Mejba Ahmed

Engr Mejba Ahmed

Claude Code Expert · Online

👋

Hey there!

Quick Actions

WhatsApp Instant reply

Chat on WhatsApp

+880 1723 741224 · Instant reply

Popular Questions

Engr Mejba Ahmed is connected
Engr Mejba Ahmed is typing...
Engr Mejba Ahmed avatar

✉ Want me to follow up? Drop your email

Engr Mejba Ahmed avatar

📞 Connect Directly

Choose how you'd like to reach me

WhatsApp

+880 1723 741224

Email

[email protected]

✓ Details sent! I'll get back to you shortly.

Powered by OpenAI

335+

Blog Posts

25

AI Courses

63

Projects

Services & Expertise

Pricing & Process

Learning & Resources

Connect & Support