Claude should grep all references before renaming, removing, or refactoring code

Status Fixed / completed
Maintainer reply None cached
Activity 4 comments · opened Mar 24, 2026 · closed Mar 24, 2026

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:

  1. Before renaming: grep the old name project-wide, update all references
  2. Before removing: grep to find all callers/importers, confirm nothing depends on it
  3. Before refactoring: grep to 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

View original on GitHub ↗

4 Comments

github-actions[bot] · 6 months ago

Found 3 possible duplicate issues:

  1. https://github.com/anthropics/claude-code/issues/35439
  2. https://github.com/anthropics/claude-code/issues/37695
  3. https://github.com/anthropics/claude-code/issues/33471

This issue will be automatically closed as a duplicate in 3 days.

  • If your issue is a duplicate, please close it and 👍 the existing issue instead
  • To prevent auto-closure, add a comment or 👎 this comment

🤖 Generated with Claude Code

nedlern · 6 months ago

Closing as duplicate of #35439 (same author, same request). Upvoting that one instead.

raye-deng · 6 months ago

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:

  1. Direct reference breakage (what this issue describes) — rename or remove a symbol, miss callers in other files. The fix is straightforward: grep before edit.
  1. Semantic reference drift — the symbol name stays the same, but its contract changes. An AI refactors a function to return a different shape or accept different params, and callers still compile but behave incorrectly. Grep won't catch this because the name still matches.
  1. Implicit dependency breakage — shared state, event handlers, config keys, environment variables. These don't show up in import graphs. An AI removes a Redux action creator without checking which reducers listen for that action type.

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 L1

github-actions[bot] · 6 months ago

This 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.