Requirements
stacknext init rejects a missing app/ or src/app/ directory and a Next.js
major below 15. A newer major prints a warning because it is outside the tested
range. See compatibility for the recorded matrix.
Install inside the application directory, not in a parent folder. The collector
and dashboard use http://127.0.0.1:4400 by default and try the next 25
loopback ports when it is busy.
Install the packages
npm:@stacknext/cli contains the CLI, collector and dashboard. @stacknext/next
is the instrumentation and OpenTelemetry exporter loaded by your app, so install
it as a production dependency. Keep the CLI as a development dependency. The
collector, dashboard, diagnostics, regression and MCP packages are installed
automatically as dependencies of the CLI.
Add these only when you use the integration:
Initialize the project
init performs these checks and writes only what is missing:
- It finds
package.json, the Next.js version andapp/orsrc/app/. - It creates
stacknext.config.jsonwith private (0600) permissions. - It creates
instrumentation.tsfor a TypeScript project, orinstrumentation.jsfor a JavaScript project. - It detects Drizzle and Prisma and prints the adapter setup.
- It reports whether
@stacknext/nextis declared. Pass--installto let the detected package manager install it. - It can add managed AI-agent instructions with
--agents.
init is idempotent. Running it again leaves valid files unchanged.
Existing instrumentation is never overwritten
If the project already has aninstrumentation file, init leaves it
untouched. Add the hook yourself:
onRequestError already exists, call stackNextOnRequestError(error, request, context) inside it. StackNext yields to an existing OpenTelemetry
tracer provider instead of replacing it.
The generated hook checks NEXT_RUNTIME === 'nodejs' and imports StackNext
dynamically. Edge compilation must not load the Node.js transport.
Start the collector and app
dev starts the loopback collector, writes .stacknext/run.json with mode
0600, and runs your app’s own dev script with the collector URL and token in
its environment. The dashboard URL is printed at startup and is usually
http://127.0.0.1:4400. Use --open to open it in the default browser.
.stacknext/run.json holds a short-lived bearer token and must stay private.
Never commit it, paste it into an issue or copy it into another app.Verify the installation
Withstacknext dev running in another terminal:
doctor is the first stop when the dashboard is empty. coverage describes
only what the current retention window observed; it is not a health score.
Next steps
- Connect a database integration.
- Add custom spans.
- Review the configuration reference.
- Connect an AI coding agent.
Upgrade
- Stop
stacknext devwith SIGINT or SIGTERM. - Install the new versions with the same package manager.
- Run
stacknext initagain. It preserves user-owned files and validates the existing config. - Run
stacknext doctor, thenstacknext dev. - Review the changelog for behavior changes.
.stacknext/runs, .stacknext/baselines or
.stacknext/comparisons. Those records are versioned and kept until you remove
them explicitly.
Workspaces and monorepos
Install StackNext in the Next.js application package, not at the workspace root, so the CLI can find that app’spackage.json, dev script and Next.js version.
In a pnpm workspace:
Remove StackNext
stacknext uninstall removes only files that StackNext generated. It does not
delete user-authored instrumentation, application data or saved records unless
you ask for it.
Stop stacknext dev with SIGINT or SIGTERM first and wait for it to exit.
Uninstall refuses to remove runtime files while the recorded process is alive.
Preview the removals (the default is a dry run):
The command leaves an instrumentation file you edited or wrote yourself,
application code,
node_modules, lockfiles and .stacknext capture data alone
unless --remove-data is passed.
Remove the packages with your package manager. For pnpm:
@stacknext/drizzle, @stacknext/prisma or @stacknext/playwright
only if you installed them. The other @stacknext/* packages are dependencies
of the CLI and disappear with it.
If the CLI is no longer available, delete stacknext.config.json if StackNext
created it, remove the StackNext import and hook from your instrumentation file,
and delete .stacknext/run.json. Keep .stacknext/runs, .stacknext/baselines
and .stacknext/comparisons if you still need the evidence. Also remove the MCP
server entry and the stacknext-debugging skill from your agent configuration.