Skip to content

commandCode quality

Rename Symbol

Renames a function, class or variable everywhere, including strings, docs and tests, then verifies the build still passes.

npx workspacetemplates add rename-symbol --tool claude-code

Writes 1 file to .claude/commands/

.claude/commands/rename-symbol.md15 lines · 1.2 KBFile
---
description: Renames a function, class or variable everywhere, including strings, docs and tests, then verifies the build still passes.
argument-hint: "[old name] to [new name]"
---

Rename a symbol: $ARGUMENTS (format: old to new).

1. Confirm the old name's definition and kind (function, class, field, column, env var, route). If the new name already exists in scope, stop and report the clash.
2. Find all uses with the language server or `grep -rnw` across code, tests, config, docs, scripts, templates, CI files and SQL. Search also for case variants (camelCase, snake_case, kebab-case, UPPER_CASE) and for the name inside strings.
3. Sort hits into: real references to rename; same word with another meaning (leave); public or persisted names such as an API field, database column, event name or env var, where renaming breaks clients or stored data.
4. If a public or persisted name is involved, stop and ask first, since it needs a migration or a deprecation alias.
5. Apply the rename to the real references only. Do not reformat other lines.
6. Run the type check, build and tests. Grep once more for the old name and explain each remaining hit.

Report the count of changed files and the leftover hits. Ask before committing.

What it does

A rename that misses one reference becomes a runtime error on a rarely used path. This command finds every use, including those a compiler cannot see: string keys, config files, docs, SQL and templates.

It separates the matches that are really the symbol from lookalikes, applies the change, and finishes by building and testing the project.

Example

you › /rename-symbol getUsr to getUser

agent › 31 references in 14 files renamed (code 22, tests 7, docs 2). Left alone: "getUsr" inside a vendored file and a changelog entry.
tsc and 212 tests pass. No public API names involved.
Commit?

Questions

What about names stored in a database?
It stops before changing anything persisted or public and asks, because those renames need a migration or an alias.
Does it catch uses in strings and docs?
Yes. It searches text, config, templates and docs along with code, then separates real references from lookalike words.
  • Add Error Handling

    CommandCode quality

    Free
  • Add Logging

    CommandCode quality

    Free
  • Add Types

    CommandCode quality

    Free
  • Extract Function

    CommandCode quality

    Free