claude-code - 💡(How to fix) Fix [Feature Request] Cross-file consistency: auto-grep repo after fixing a pattern [1 comments, 1 participants]

Official PRs (…)
ON THIS PAGE

Recommended Tools

×6

Utilities matched from this issue’s tags and category — try them while you read without losing context.

GitHub issue graph ai analysis

Paste a GitHub issue URL. We fetch that issue, discover linked issues from bodies/comments/timeline, collect linked pull requests, and produce a structured English report.

The report is written in English Markdown for sharing and archival.

Helpful · Quick feedback

Loading…
GitHub stats
anthropics/claude-code#46234Fetched 2026-04-11 06:25:36
View on GitHub
Comments
1
Participants
1
Timeline
5
Reactions
0
Participants
Timeline (top)
labeled ×3closed ×1commented ×1

Follow-up to #45731 (cross-file consistency) and #45738 (Pattern 3).

When Claude fixes a bug in one file, it does not check the rest of the repository for the same pattern. This happened 3 times in a single session for 3 different bug classes:

  • Fixed path traversal in file A, same vulnerability existed in file B
  • Removed unused import in file A, same unused import existed in file B
  • Fixed error handling in layer 3, same broken handling in layer 2

Each time Claude wrote a reflection saying 'next time I will check both layers.' Each time it did not.

Error Message

  • Fixed error handling in layer 3, same broken handling in layer 2 This could be a PostToolUse hook on file writes: extract the changed pattern, grep the repo, warn if found elsewhere.

Root Cause

150+ review threads in #45731 — many were the exact same bug class appearing in parallel files. Cross-file grep before commit would have caught these in round 1 instead of round 5.

Code Example

grep -rn "FIXED_PATTERN" --include="*.ext" .
RAW_BUFFERClick to expand / collapse

Preflight Checklist

  • I have searched existing issues and this hasn't been reported yet
  • This is a single report
  • I am using the latest version of Claude Code

Summary

Follow-up to #45731 (cross-file consistency) and #45738 (Pattern 3).

When Claude fixes a bug in one file, it does not check the rest of the repository for the same pattern. This happened 3 times in a single session for 3 different bug classes:

  • Fixed path traversal in file A, same vulnerability existed in file B
  • Removed unused import in file A, same unused import existed in file B
  • Fixed error handling in layer 3, same broken handling in layer 2

Each time Claude wrote a reflection saying 'next time I will check both layers.' Each time it did not.

Proposed Solution

After every bug fix, automatically run:

grep -rn "FIXED_PATTERN" --include="*.ext" .

If the same pattern exists in other files → fix all occurrences in the same commit. One-file fix when the pattern is multi-file = half-work.

This could be a PostToolUse hook on file writes: extract the changed pattern, grep the repo, warn if found elsewhere.

Why This Matters

150+ review threads in #45731 — many were the exact same bug class appearing in parallel files. Cross-file grep before commit would have caught these in round 1 instead of round 5.

Environment

  • Claude Code CLI (latest)
  • Model: Claude Opus (Max plan)
  • macOS

extent analysis

TL;DR

Implement a post-commit hook to run a grep command that checks for the fixed pattern in other files and fixes all occurrences in the same commit.

Guidance

  • Identify the fixed pattern in each bug fix and extract it for use in the grep command.
  • Configure a PostToolUse hook on file writes to run the grep command and warn if the pattern is found elsewhere in the repository.
  • Consider integrating this hook into the Claude Code CLI to automate the process.
  • Test the hook with various bug fixes to ensure it correctly identifies and fixes multi-file patterns.

Example

# Example grep command to search for the fixed pattern
grep -rn "FIXED_PATTERN" --include="*.ext" .

Notes

This solution assumes that the fixed pattern can be reliably extracted from the bug fix and used in the grep command. Additionally, the effectiveness of this solution depends on the accuracy of the grep command in identifying the pattern in other files.

Recommendation

Apply workaround: Implement the proposed PostToolUse hook to automate the process of checking for and fixing multi-file patterns. This will help reduce the number of review threads and ensure that bug fixes are comprehensive.

Vote matrix · Quick signals

Works
Did the solution work? Tap to confirm.
Easy Fix
Was it a quick fix?
Time Saver
Did it save you time?
Blocking
Was it severely blocking?
Common Issue
Are others likely hitting this too?
Flaky / Intermittent
Is it intermittent?
Verified / Reproducible
Can you reproduce it reliably?
Loading…

Still need to ship something?

×6

Another batch ranked right after the header list — different links, same matching logic.

Back to top recommendations

TRENDING