claude-code - 💡(How to fix) Fix Opus 4.6 deleted a live API endpoint after a too-narrow grep convinced it was dead [2 comments, 2 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#49340Fetched 2026-04-17 08:44:00
View on GitHub
Comments
2
Participants
2
Timeline
6
Reactions
0
Timeline (top)
labeled ×3commented ×2closed ×1

Error Message

  • The breakage would only surface during user testing, with a vague console error.

Root Cause

  1. Crossed a high-blast-radius boundary without confirmation. Deleting an HTTP endpoint changes a public contract. Even with strong evidence the agent should have surfaced "I'm about to delete X because I see no callers — confirm?" rather than bundling it into a sweep. The agent's own action policy says hard-to-reverse / shared-state actions warrant confirmation; deleting a live endpoint qualifies on both counts.

Code Example

const response = await fetch(`${this.config.apiBase}/doctors`, ...)
RAW_BUFFERClick to expand / collapse

Model

claude-opus-4-6 (1M context), via Claude Code CLI.

What happened

While doing a code-cleanup sweep, the agent identified an HTTP endpoint (GET /api/forms/doctors) as dead code based on a literal-string grep for the route forms/doctors returning only the endpoint definition itself plus one code comment.

The agent deleted the entire endpoint (~65 lines).

The endpoint was, in fact, live. A frontend script called it via:

const response = await fetch(`${this.config.apiBase}/doctors`, ...)

where apiBase was a string variable resolving to /api/forms. The grep for forms/doctors could not match this dynamically-constructed URL, so the agent's "zero callers" verdict was a false negative.

The user was not told about the deletion before it happened — it was bundled into a "clean up dead code" task. The agent caught the mistake itself one step later when investigating the related doctor-select CSS class, then restored the endpoint.

Why this is a judgment failure

  1. Treated absence-of-evidence as evidence-of-absence. A literal-string grep proves only that no source file contains that exact substring. It does not prove the endpoint isn't called via runtime URL construction (template strings, configured base paths, route helpers, generated clients).

  2. Skipped the standard sanity check for "dead endpoint" verdicts: looking for callers via the entity name (e.g. doctor-select, DoctorSelect, the response shape {value, label}) instead of just the URL.

  3. Crossed a high-blast-radius boundary without confirmation. Deleting an HTTP endpoint changes a public contract. Even with strong evidence the agent should have surfaced "I'm about to delete X because I see no callers — confirm?" rather than bundling it into a sweep. The agent's own action policy says hard-to-reverse / shared-state actions warrant confirmation; deleting a live endpoint qualifies on both counts.

  4. The "dead code" rationalization was eager. The agent was already invested in a cleanup pass and looking for things to delete. A conservative reviewer would have noted "dynamic URL construction is common in JS clients, my grep cannot rule that out" and stopped.

Impact

Low this time — same-session catch, full restoration. In a less-supervised run:

  • The deletion would ship.
  • All dental form templates with a Doctor select field would silently fail to populate options at runtime.
  • Form submissions referencing those fields would have no doctor selectable.
  • The breakage would only surface during user testing, with a vague console error.
  • The git history would show "cleanup: removed dead endpoint" with no link to the dependent JS — the connection would have to be re-discovered by whoever bisected the regression.

Suggested guardrails

  • Before deleting an HTTP endpoint, controller action, or service method, search by every reasonable identifier: route literal, method name, response shape, related CSS class, related TypeScript type. Multiple negative searches > one negative search.
  • Treat string-literal grep as a starting point for "dead code" claims, not a conclusion. Frontend code routinely constructs URLs at runtime.
  • Deletion of public-contract code (endpoints, exported types, public methods) belongs in its own commit with explicit user confirmation, not bundled into a "cleanup" sweep.

Co-authored-by: Claude Opus 4.6 (1M context) [email protected] Filed by the same model that caused the failure.

extent analysis

TL;DR

To prevent similar incidents, implement a more comprehensive search strategy before deleting HTTP endpoints, including searching by multiple identifiers and considering dynamic URL construction.

Guidance

  • Before deleting an HTTP endpoint, perform searches using various identifiers such as route literals, method names, response shapes, related CSS classes, and related TypeScript types to ensure no callers are missed.
  • Treat string-literal grep as a starting point for "dead code" claims, not a conclusion, and consider the possibility of dynamic URL construction in frontend code.
  • Require explicit user confirmation for deletion of public-contract code, such as endpoints, exported types, and public methods, and avoid bundling these changes into "cleanup" sweeps.
  • Consider implementing a pre-deletion review process to catch potential issues before they are introduced.

Example

No specific code snippet is provided, but an example of a more comprehensive search strategy could involve using a combination of grep, code analysis tools, and manual review to identify potential callers of an endpoint.

Notes

The suggested approach may not catch all cases of dynamic URL construction, and additional measures such as code reviews and testing may be necessary to ensure the correctness of changes.

Recommendation

Apply a workaround by implementing the suggested guardrails, including multiple searches and explicit user confirmation for public-contract code changes, to prevent similar incidents in the future. This approach prioritizes caution and thoroughness over automation and speed.

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