← All Articles 🤖 AI Comparison & Trending High By Nishant Kumar Verma

Why AI Agents Break Your Frontend When They Change an API

AI coding agents rename an API field and the frontend breaks with a green build. Why agents miss HTTP callers, and how to give them the request map.

Quick Answer

AI coding agents such as Claude Code, Cursor or Codex can break the frontend when they change an API route, because nothing in the code connects the two. The frontend calls a URL string, not an imported function, so the agent's search, your editor's "find references" and the type checker do not see the caller. Give the agent the list of requests that reach the route before it edits it, share the response type between both sides, and keep the old field until every caller has moved.

How It Happens

You ask the agent to clean up the orders endpoint. It renames a field, updates the handler, runs the type check, and reports success:

// app/api/orders/[id]/route.ts, after the agent's change
return Response.json({ id: order.id, amount: order.total }); // was: total

Two folders away, a component still reads the old field:

// components/order-total.tsx
'use client';
import useSWR from 'swr';

const fetcher = (url: string) => fetch(url).then((r) => r.json());

export function OrderTotal({ id }: { id: string }) {
  const { data } = useSWR(`/api/orders/${id}`, fetcher);
  return <p>Total: {data?.total}</p>; // now undefined
}

The build passes, because r.json() returns any. The page shows "Total:" and nothing else. Nobody notices until a customer does.

Why the Agent Does Not See the Caller

  • No import joins them. Agents and editors follow imports and symbols. A request is a string, and the route is a file path or a pattern like /orders/:id.
  • The path is built, not written. `/api/orders/${id}` does not contain the text /api/orders/[id], so a search for the route's path finds nothing, and a looser search for orders returns every other use of the word too.
  • Proxies and base URLs hide it. A rewrite or a base URL from an env var changes the path between the two sides.
  • The caller is in another repo. An agent usually searches only the repo it was opened in.
  • The context is limited. An agent reads the files it thinks are relevant. A caller it never opened does not exist for it.

How to Stop It

  1. Share the response type. Put it in one module both sides import, and check the handler against it with satisfies:
    // lib/api-types.ts
    export type OrderResponse = { id: string; total: number };
    
    // app/api/orders/[id]/route.ts
    return Response.json({ id: order.id, total: order.total } satisfies OrderResponse);
    
    // components/order-total.tsx
    const { data } = useSWR<OrderResponse>(`/api/orders/${id}`, fetcher);
    Now the rename fails the type check: renaming the field in the handler breaks the satisfies, and renaming it in the type breaks the component that reads data?.total.
  2. Add a rule for your agent. In CLAUDE.md, AGENTS.md or your editor's rules file: "Before changing an API route, list every request that calls it, with file and line, and update or keep compatible each one."
  3. Expand, then contract. Return the new field next to the old one, move the callers, then remove the old field. The full method is in find every caller before you change an API endpoint.
  4. Test the contract. One test per endpoint that checks the fields the frontend reads catches the rename before deploy.

The rule in step 2 only works if the agent can actually find the callers. That is the part a request map from the code solves.

Give the Agent the Request Map

With the VibeDoctor connector, your agent reads Vibe X-Ray's code map through the vibedoctor_graph tool, and the map links each request in your code to the route that answers it.

  • impact on a route's handler returns what a change to it affects. Its callers include the code whose requests the route answers, each with the method, the path and the file and line on both sides.
  • trace follows a flow from an entry point across the requests it sends, including into your other projects in VibeDoctor.

So before the agent renames total, impact tells it that components/order-total.tsx sends a request the route answers. These HTTP hops are included during the Free Week and on paid plans; after the Free Week, Free answers stay inside the code and say how many hops were left out.

To try VibeDoctor from Claude Code or Codex, paste this into the agent:

connect to vibedoctor using https://vibedoctor.io/mcp/start

Not a developer? Connect your GitHub repository on vibedoctor.io for a free scan, and open the HTTP Requests tab in Vibe X-Ray to see the requests in your code and the routes that answer them.

FAQ

Why does my AI agent break things it did not touch?

Because it changed something they depend on, and nothing in the code told it so. Calls over HTTP are the common case: the frontend depends on the route through a URL, not an import.

Does TypeScript catch a renamed API field?

Only if both sides use the same type and the handler is checked against it, for example with satisfies. fetch().then(r => r.json()) returns any, so without a shared type a renamed field passes the build.

What should I put in CLAUDE.md or AGENTS.md about APIs?

A rule to list every request that calls a route before changing it, to keep changes backward compatible until callers move, and to run the contract tests after.

Can the agent see callers in another repository?

Not from the backend's repo. When the agent works in the frontend project, VibeDoctor's trace follows the frontend's requests into your other projects, matched by their website address or by a link you add in Settings.

Diagnose your codebase - free

VibeDoctor checks for and 148 other issues across 21 diagnostic areas - security, performance, code quality, and more.

SCAN MY APP →