Getting started

snapfail Documentation

snapfail is a context capture layer for AI-assisted debugging. When your app crashes in the browser, snapfail captures the full evidence and packages it so your AI agent (Claude Code, Cursor, Copilot) can diagnose the root cause directly.

๐Ÿ’ก
Who is snapfail for? Builders who use AI to code (vibe coding) and receive errors from their app without enough context to explain them to their agent.

How it works

01
Browser error
The SDK detects unhandled exceptions, fetch errors, and 4xx/5xx responses in real time.
โ†’
02
Evidence capture
Stack trace, console, network, click replay, and device context โ€” all in a single package.
โ†’
03
Your AI analyzes it
The agent runs snapfail explain <id> and receives the root cause + fix prompt.
Getting started

Quick start

One command installs and configures everything.

1. Install

bash
# npm
npm install -g @snapfail/cli

# or bun
bun add -g @snapfail/cli

2. Initialize in your project

bash
snapfail init

snapfail init does everything automatically:

  • Detects your framework (Astro, Vite, Next.js)
  • Opens the browser for authentication
  • Injects the browser SDK into your framework config
  • Writes SNAPFAIL_PROJECT_KEY to your .env
  • Generates .agents/skills/snapfail/SKILL.md for your AI agent

3. Ask your AI to investigate

bash
# List unresolved incidents
snapfail incidents

# Full diagnosis for an incident
snapfail explain <id>
โœ“
That's it. When a user hits an error, snapfail captures it automatically. You or your AI agent query it with the CLI.
CLI

snapfail init

Sets up snapfail in your project. You only need to run this once.

bash
snapfail init

What it does

StepDescription
Detect frameworkScans package.json to identify Astro, Vite, or Next.js
AuthenticateOpens the browser for login/register. Token is saved to ~/.snapfail/auth.json
Create projectCreates or selects a project on app.snapfail.com
Inject SDKModifies astro.config.mjs, vite.config.ts, or next.config.js
Write .envAdds SNAPFAIL_PROJECT_KEY to your .env file
Generate SKILL.mdCreates .agents/skills/snapfail/SKILL.md with context for your AI
CLI

snapfail incidents

Lists incident groups for your project.

bash
snapfail incidents [options]

Options

FlagDefaultDescription
--statusunresolvedunresolved ยท resolved ยท ignored ยท all
--jsonโ€”JSON output without ANSI colors (for LLM use)
--pk <key>from .envOverride the project key
๐Ÿค–
When using this command from an AI agent, always pass --json to avoid ANSI characters in the output.

Example output

json
{"groups": [
  {
    "id": "inc_8f2a",
    "title": "TypeError: cannot read 'total' of undefined",
    "severity": "critical",
    "status": "unresolved",
    "count": 1284,
    "affectedUsers": 312,
    "lastSeen": "2025-06-01T18:30:00Z",
    "environments": ["prod"]
  }
]}
CLI

snapfail incident <id>

Detail for a group: summary + representative sample.

bash
snapfail incident <id> [--sample <n>] [--json]

Options

FlagDescription
--sample <n>Sample index (0-based). Useful for comparing different occurrences of the same error.
--jsonStructured output without visual formatting
๐Ÿ’ก
With the exact incident ID you don't need to pass --pk. snapfail resolves the project automatically from your session.
CLI

snapfail explain <id>

The primary command for AI diagnosis. Emits the full structured evidence from up to 3 samples, ready for the LLM to reason about the root cause.

bash
snapfail explain <id>

The output includes:

  • group โ€” normalized title, severity, count, affected users
  • samples[].stackFrames โ€” call stack at error time, frames from your app highlighted
  • samples[].consoleEntries โ€” console logs before the error
  • samples[].networkEntries โ€” network requests with status, duration, and headers (no auth)
  • samples[].timeline โ€” sequence of user interactions
  • samples[].device โ€” user agent, viewport, language
๐Ÿค–
For AI agents: read the output of snapfail explain directly and reason about the root cause. Do not delegate to another model โ€” the evidence is sufficient to diagnose.
CLI

snapfail suppress

Manage suppression rules to filter known noise (browser errors, bots, healthchecks).

bash
# List active rules
snapfail suppress list

# Create a rule
snapfail suppress add --field message --pattern "ResizeObserver loop*"

# Delete a rule
snapfail suppress delete <rule-id>

Available fields

FieldDescription
messageGlob pattern on the error message
useragentPattern on the user agent (useful for filtering bots)
urlExact URL or pattern (e.g. /healthz)
script_originOrigin of the script that threw the error
SDK

Browser SDK

The SDK runs in the end user's browser. It captures errors in real time using four event-driven collectors that write to an in-memory ring buffer.

โš 
Errors
window.onerror, unhandledrejection, and 4xx/5xx network errors
๐Ÿ“‹
Console
Monkeypatch of console.error/warn/log to capture the last N logs before the error
๐ŸŒ
Network
fetch wrapper and XMLHttpRequest patch + PerformanceObserver
๐ŸŽฌ
Replay
MutationObserver + click, input, scroll, and navigation listeners

When an error occurs, the SDK freezes the buffer, assembles the IncidentSample, scrubs sensitive data in the browser before sending, and transmits to the cloud endpoint.

SDK

Framework adapters

snapfail init installs the correct adapter automatically. You can also do it manually:

Astro

astro.config.mjs
import { defineConfig } from 'astro/config';
import snapfail from '@snapfail/astro';

export default defineConfig({
  integrations: [snapfail()]
});

Vite

vite.config.ts
import snapfail from '@snapfail/vite';

export default { plugins: [snapfail()] };

Next.js

next.config.js
const snapfail = require('@snapfail/next');

module.exports = snapfail({ /* next config */ });
SDK

Configuration

The SDK is configured with the project key and environment options.

js
snapfail("proj_xxxxxxxxxxxxxxxxx", {
  endpoint: "https://app.snapfail.com",  // ingest URL
  env: "prod",                            // "dev" | "prod"
  replay: true,                           // DOM replay (default: true)
  storage: false,                         // storage snapshot (default: false)
});
OptionTypeDefaultDescription
endpointstringโ€”Base URL of the ingest server
envstring"prod"Environment tag. Use "dev" during development
replaybooleantrueCapture DOM replay (MutationObserver)
storagebooleanfalseInclude localStorage/sessionStorage inventory
Concepts

Incidents & groups

snapfail groups occurrences of the same error by fingerprint โ€” a deterministic signature derived from the normalized message + stack trace.

IncidentGroup

Aggregates all occurrences of the same error. Has count, affected users, first and last seen, and up to 50 samples.

IncidentSample

A specific occurrence with full evidence: stack, console, network, timeline, device. Samples are chosen with reservoir sampling to maximize diversity.

Fingerprint normalization

PatternReplaced with
UUIDs[uuid]
Hex hashes โ‰ฅ8 chars[hash]
Numbers โ‰ฅ6 digits in paths[id]
JWTs (eyJ...)[token]
Dynamic path segments/users/[id]
Concepts

Sampling

snapfail uses reservoir sampling with diversity to keep a maximum of 50 samples per group. Instead of saving the first N identical occurrences, it prioritizes:

  • Samples from different time periods
  • Different environments (dev vs prod)
  • Different devices and browsers

This ensures that when analyzing samples, the LLM sees variety โ€” not 50 identical occurrences from the same user on the same device.

Concepts

Privacy & scrubbing

Scrubbing happens in the end user's browser, before anything leaves the network. No sensitive data ever reaches the server.

Network headers โ€” full drop

AuthorizationCookieSet-CookieX-Api-KeyX-Auth-Token

Query params โ€” value replaced with [redacted]

tokenkeysecretpasswordapi_keyaccess_token

Console

  • JWTs (eyJ...) โ†’ [token]
  • API keys with prefixes (sk-, pk_live_, Bearer) โ†’ [api-key]

Replay / DOM

  • input[type=password] โ†’ value โ—โ—โ—โ—โ—โ—
  • Inputs with name/id in password|token|secret|card|cvv|ssn โ†’ masked
  • Card number pattern โ†’ [card]
๐Ÿ”’
Storage opt-in is off by default. snapfail never captures localStorage/sessionStorage values unless you explicitly enable storage: true.
AI Integration

SKILL.md

snapfail init automatically generates .agents/skills/snapfail/SKILL.md โ€” a context file your AI agent reads so it can use snapfail without you having to explain anything.

It contains:

  • Project summary (detected framework, routes, endpoints)
  • Incident format and how to interpret it
  • CLI commands and when to use them
  • The project-specific fix prompt pattern

To activate it in Claude Code, import the skill from your CLAUDE.md:

CLAUDE.md
import .agents/skills/snapfail/SKILL.md
AI Integration

Reading evidence

When your AI runs snapfail explain <id>, it receives structured evidence from up to 3 samples. Here's how to interpret each field:

FieldHow to use it
group.titleNormalized error message โ€” the starting point for diagnosis
sample.stackFramesLook for frames with app: true โ€” those are from your code, not libraries
sample.consoleEntriesRead in chronological order โ€” logs before the error reveal the state at the time of failure
sample.networkEntriesLook for requests with status 0, 4xx, or 5xx โ€” these are often the root cause
sample.timelineReplay the user's steps โ€” useful for intermittent reproduction bugs
sample.deviceCritical for mobile- or browser-specific bugs
AI Integration

Fix prompts

After diagnosing, snapfail explain generates a fix prompt ready to paste into Cursor, Claude Code, or your preferred agent.

fix prompt ยท example
In Cart.jsx:42, the component reads `cart.total` assuming `cart`
always exists, but `/api/cart` can respond with an empty body.

Fix:
1. Guard the access with `cart?.total ?? 0`
2. Add empty-state handling before rendering the checkout
3. Verify the `/api/cart` contract โ€” it should return `{ items: [] }`
   instead of an empty body when the cart is empty

The fix prompt includes:

  • Exact file and line of the error
  • Technical root cause
  • Concrete fix steps
  • API contract context if applicable
โ†’
Ready to get started? Create your account and run snapfail init in your project.