Next.js error tracking your coding agent can read

Updated 2026-11-22

In production, Next.js hides server component errors behind a digest ("The specific message is omitted in production builds"). Runheed records the real error on the server through the onRequestError hook in instrumentation.ts, with the route and request, and your coding agent reads it over MCP.

Set it up

  1. 1.Install the SDK.

    terminalbash
    npm install https://runheed.com/dl/runheed-0.1.7.tgz
  2. 2.Create instrumentation.ts in the project root (or src/). register() runs once per server start; onRequestError runs for every uncaught server error in the Node.js runtime. The SDK batches events for up to 5 seconds, so the hook awaits flush() to send right away: on Vercel the function can be frozen as soon as the response goes out.

    instrumentation.tstypescript
    export async function register() {
      if (process.env.NEXT_RUNTIME === 'nodejs') {
        const runheed = (await import('runheed')).default;
        runheed.init({ dsn: process.env.RUNHEED_DSN!, environment: process.env.NODE_ENV });
      }
    }
    
    export async function onRequestError(
      err: unknown,
      request: { path: string; method: string },
      context: { routePath: string; routeType: string },
    ) {
      // Keep this as a wrapping if: Next also compiles this file for the Edge runtime, and only this form lets the
      // bundler drop the import there. An early return fails with "Can't resolve 'os'".
      if (process.env.NEXT_RUNTIME === 'nodejs') {
        const runheed = (await import('runheed')).default;
        runheed.captureException(err as Error, {
          path: request.path,
          method: request.method,
          routePath: context.routePath,
          routeType: context.routeType,
        });
        // Send now: on Vercel and other serverless hosts the function can freeze right after the response.
        await runheed.flush();
      }
    }
  3. 3.Set RUNHEED_DSN in your deploy platform's environment, then connect your agent (one command for Claude Code).

    terminalbash
    claude mcp add --transport http runheed https://runheed.com/api/mcp

The npm and PyPI releases are not out yet, so these commands install the same package files straight from runheed.com. Nothing else changes when the registry versions ship.

What it catches

  • Server component and route handler errors, including the real message behind the production digest
  • Server action failures
  • Errors in API routes and proxy code running on the Node.js runtime

What it does not do

  • Edge runtime routes are skipped in this setup (the SDK uses Node.js APIs)
  • Browser errors are captured when the frontend reports through @sentry/react or @sentry/browser with the project's Sentry SDK DSN (see /for/react)

Then ask your agent

> which server errors came in since the last deploy? read the real message behind the digest, fix the top one and resolve it with the commit hash

Connect Runheed first: Claude Code, Cursor or another client. Then see how the agent fixes and resolves an error.

Common Next.js errors

Read next for Next.js

7-day trial, then $29/moOther agents and editorsCancel any time from the billing portal