Claude should grep all references before renaming, removing, or refactoring code
Problem
When Claude renames a function, removes a variable, or refactors a component, it often edits only the file it's looking at. It misses callers, listeners, event handlers, and shared state in other files. This causes broken builds and silent bugs that take long debugging sessions to find.
Proposed solution
Before any rename, removal, or refactor, Claude should automatically grep the entire project for all references to the symbol being changed. This should be default behavior, not something users have to ask for.
Specifically:
- Before renaming:
grepthe old name project-wide, update all references - Before removing:
grepto find all callers/importers, confirm nothing depends on it - Before refactoring:
grepto find all usages, understand the full blast radius
Grepping takes ~50ms on most projects. The cost of not doing it is broken builds and multi-hour debugging sessions.
Why this matters
Cross-file interactions are the #1 source of AI-introduced bugs. A single-file view misses callers, listeners, and shared state. This is the single highest-leverage behavioral change for code quality.
🤖 Generated with Claude Code
4 Comments
Found 3 possible duplicate issues:
This issue will be automatically closed as a duplicate in 3 days.
🤖 Generated with Claude Code
Closing as duplicate of #35439 (same author, same request). Upvoting that one instead.
Cross-file reference drift is probably the most underdiagnosed failure mode in AI-assisted development right now. The grep-before-rename approach described here would catch the most obvious cases, but there's a broader pattern worth noting.
We see three variants of this in production:
The tricky part is that all three variants often pass TypeScript compilation, pass unit tests (because tests mock the dependency boundary), and even pass integration tests (because test fixtures don't exercise the changed code path). They surface as production bugs days later.
We've been building deterministic cross-file consistency checks that validate reference integrity at the PR level — not just name matching but structural contract validation. It catches a surprising number of these "silent drift" bugs that no amount of grepping would find.
For anyone wanting to add this as a CI check:
npx @opencodereview/cli scan . --sla L1This issue has been automatically locked since it was closed and has not had any activity for 7 days. If you're experiencing a similar issue, please file a new issue and reference this one if it's relevant.