Claude Code for Inspector v2 Workflow (2026)
Claude Code for Inspector v2 Workflow
The Inspector v2 represents a significant evolution in Claude Code’s debugging and inspection capabilities. This workflow combines powerful runtime inspection, intelligent debugging, and AI-assisted analysis to help developers identify issues faster and write more reliable code. this guide covers practical patterns for integrating Claude Code into your Inspector v2 workflow. from initial setup through advanced async debugging, memory analysis, and CI/CD integration.
Understanding Inspector v2 Architecture
Inspector v2 introduces a redesigned debugging layer that provides deeper visibility into code execution while maintaining minimal performance overhead. Unlike traditional debuggers that interrupt execution, Inspector v2 works smoothly with Claude Code’s agentic capabilities.
The architecture consists of three core components:
- Event Pipeline: Captures execution events without blocking
- AI Analyzer: Uses Claude’s reasoning to interpret complex state
- Interactive Console: Provides real-time query capabilities
This design allows you to debug complex issues while Claude Code assists with understanding the root cause.
How Inspector v2 Differs from Inspector v1
If you have used the original Inspector, the key improvements in v2 are worth understanding before diving into the workflow:
| Capability | Inspector v1 | Inspector v2 |
|---|---|---|
| Async state tracking | Partial (Promise chains only) | Full (async/await, generators, workers) |
| Performance overhead | ~8-12% in dev mode | ~2-3% in dev mode |
| AI integration | Post-capture analysis only | Real-time query during live session |
| Heap snapshot diff | Manual comparison | Automatic leak detection |
| Network capture | HTTP only | HTTP, WebSocket, gRPC |
| Multi-process | Single process | Full process tree |
The reduced overhead is significant if you have previously avoided attaching Inspector to staging environments due to performance concerns. With v2, it is practical to run Inspector in non-production environments continuously.
Setting Up Claude Code with Inspector v2
First, ensure your environment is properly configured. Install the latest Claude Code CLI and enable Inspector v2 support:
Install Claude Code
npm install -g @anthropic-ai/claude-code
Verify installation and confirm Inspector v2 is available
claude --version
claude-code v1.6.0 (Inspector v2 enabled)
Inspector v2 is enabled by default in CLI versions 1.5.0 and later. If you are on an older version, upgrade before proceeding.
Project-Level Configuration
Create a .claude/settings.json file in your project root to configure Inspector behavior per project:
{
"inspector": {
"v2": {
"autoAttach": true,
"captureEvents": ["exception", "promise-rejection", "http-request", "http-response", "console-error"],
"maxBufferSize": 10000,
"redactFields": ["password", "token", "authorization", "cookie"],
"captureStackDepth": 20,
"snapshotOnException": true,
"snapshotDir": "./inspector-captures"
}
}
}
The redactFields array is important for any project that handles authentication tokens or user credentials. Inspector v2 will automatically replace matching field names with [REDACTED] in all captured payloads, preventing accidental credential exposure in debug output.
The snapshotOnException flag is one of the most valuable settings. Rather than manually triggering a capture, Inspector v2 automatically freezes the full execution state the moment an unhandled exception or rejection occurs. giving you a complete picture of exactly what went wrong without needing to reproduce the issue.
Environment-Specific Configuration
Most projects need different Inspector settings across local, staging, and CI environments:
{
"inspector": {
"v2": {
"autoAttach": true,
"captureEvents": ["exception", "promise-rejection"],
"maxBufferSize": 5000
}
},
"env": {
"CI": {
"inspector": {
"v2": {
"captureEvents": ["exception", "promise-rejection", "test-failure"],
"maxBufferSize": 20000,
"exportOnExit": true,
"exportPath": "./inspector-reports/ci-run.json"
}
}
}
}
}
With exportOnExit: true in CI, every test run automatically produces an Inspector report that can be uploaded as a build artifact. making it straightforward to analyze failures after the fact without re-running the suite.
Practical Debugging Workflow
When encountering a bug, follow this structured approach combining Inspector v2 with Claude Code:
Step 1: Capture the Failure State
Use Inspector v2 to capture the exact state when the error occurs:
Start with Inspector attached; snapshot fires automatically on exception
node --inspect npm start
For tests, run with the --runInBand flag to serialize execution and get cleaner Inspector captures:
node --inspect npx jest --runInBand --forceExit
If you need to manually trigger a snapshot at a specific point in the code rather than waiting for an exception, add an Inspector checkpoint:
// In your application code, trigger a named snapshot
if (process.env.NODE_ENV !== 'production') {
const { InspectorV2 } = require('@anthropic-ai/claude-code/inspector');
await InspectorV2.checkpoint('before-db-migration');
}
This is useful when diagnosing issues that produce incorrect output rather than thrown errors. the bug is subtle but no exception fires.
Step 2: Query the State with Claude
Once you have a captured state, ask Claude to analyze it:
Claude, analyze the captured state in ./inspector-captures/fail-001.json.
Focus on understanding why the database connection failed and suggest
potential fixes. Cross-reference with our db/connection.ts and
config/database.ts files.
Claude Code will examine the captured state, trace through the execution context, and provide insights based on its understanding of your codebase. The combination of the Inspector capture. which contains the actual runtime values. and Claude’s knowledge of your source code is what makes this workflow faster than traditional debugging. You are not guessing at what variable values were; they are right there in the capture.
Step 3: Examine the Suggested Root Cause
Before implementing any fix, use Claude to walk through the causal chain:
Based on the fail-001.json capture, trace the sequence of events that led
to the connection timeout. Start from the initial request in app.ts and
identify every point where a configuration value was read or a connection
parameter was set.
This trace is especially valuable for bugs that involve multiple files or modules. Claude can hold the full execution context in mind and surface the specific line where a misconfigured value propagated through the system.
Step 4: Implement and Verify the Fix
Apply the suggested fix and verify with a focused re-run:
Use --inspect-brk to pause at startup and set breakpoints before resuming
node --inspect-brk npm start
After applying the fix, compare before and after captures to confirm the specific failure path is resolved:
Claude, compare fail-001.json and pass-001.json. Confirm that the database
connection path in pass-001 is different and explain what changed.
Advanced Patterns for Complex Issues
Async Debugging
One of Inspector v2’s strongest features is its async state tracking. When debugging Promise-based code or async/await chains, v2 maintains the full async context stack. something that was very difficult to reconstruct in v1.
Run tests with serialized execution for cleaner async traces
node --inspect npx jest --runInBand
After capturing an async failure, ask Claude to analyze the promise resolution timeline:
Claude, in fail-002.json, trace the async execution timeline for the
userService.authenticate() call. Identify which promise resolved out of
order and explain the race condition.
A common pattern that Inspector v2 makes visible is a race between an authentication check and a session write. In synchronous tracing, you would only see that the session was invalid. In v2’s async timeline, you can see that the session write resolved 14ms after the authentication check had already read the (not yet written) session. a classic race that only appears under load.
Diagnosing Specific Async Anti-Patterns
Inspector v2 captures are particularly useful for these categories of async bugs:
// Pattern 1: Unhandled rejection that only fires sometimes
async function fetchUserData(userId) {
const [profile, permissions] = await Promise.all([
userRepo.find(userId), // Can throw if user deleted
permissionRepo.findByUser(userId) // Silently returns [] on error
]);
// If userRepo.find throws, permissions result is lost silently in v1
// Inspector v2 captures the full Promise.all rejection with both branches
return { profile, permissions };
}
// Pattern 2: Missing await creating phantom async operations
async function processQueue(items) {
items.forEach(async (item) => { // forEach doesn't await!
await processItem(item); // These run concurrently, untracked
});
// Function returns before any items are processed
// Inspector v2 shows the orphaned async operations in the event pipeline
}
When Claude analyzes a capture containing Pattern 2, it will typically identify the forEach anti-pattern immediately and suggest replacing it with for...of or Promise.all(items.map(...)).
Memory Leak Investigation
For memory issues, Inspector v2 provides heap snapshots with automatic leak detection:
Generate heap profile during a suspected leak
node --heap-prof npm start
For interactive heap comparison, run two snapshots 60 seconds apart
node --inspect npm start
In another terminal:
claude inspect heap-snapshot --label baseline
... wait for memory to grow ...
claude inspect heap-snapshot --label after-load
Then ask Claude to analyze the snapshots:
Claude, compare ./snapshots/baseline.heapsnapshot and
./snapshots/after-load.heapsnapshot. Identify objects that are growing
unexpectedly and trace their allocation sites. Focus on anything
referencing EventEmitter or closure scope.
Inspector v2’s heap diff output categorizes retained objects by constructor, making it straightforward to spot EventEmitter listener accumulation (a very common Node.js leak) versus closure captures or cache objects that were never evicted.
For large applications with significant heap sizes, use the --max-old-space-size flag to prevent the snapshot process itself from running out of memory:
node --max-old-space-size=4096 --heap-prof npm start
Network Request Tracing
Inspector v2 captures HTTP, WebSocket, and gRPC traffic automatically when enabled. This is especially useful when debugging API integrations where the issue is in the request construction, response parsing, or error handling:
Enable full network capture in settings.json, then run the failing scenario
node --inspect npm start
After capture, query specific failed requests
Ask Claude to analyze network failures with full context:
Claude, in fail-003.json, find all HTTP requests to /api/payments that
returned a 4xx status. For each failed request, show the request body,
the response body, and the JavaScript call stack at the point the request
was made.
This is far more efficient than adding console.log statements around every fetch call and re-running the scenario.
Integrating with Existing Tools
Inspector v2 works alongside your existing development tools. Here’s how to integrate with popular workflows:
VS Code Integration
Add this to your .vscode/launch.json to launch with Inspector v2 pre-configured:
{
"version": "0.2.0",
"configurations": [
{
"type": "node",
"request": "launch",
"name": "Debug with Claude Inspector v2",
"runtimeExecutable": "node",
"runtimeArgs": ["--inspect", "--require", "@anthropic-ai/claude-code/inspector/register"],
"program": "${workspaceFolder}/src/index.js",
"console": "integratedTerminal",
"env": {
"CLAUDE_INSPECTOR_V2": "true",
"CLAUDE_INSPECTOR_SNAPSHOT_DIR": "${workspaceFolder}/inspector-captures"
}
}
]
}
This launch configuration registers the Inspector v2 hooks at process startup, so you get automatic snapshot-on-exception behavior from the moment the process starts. without any code changes.
JetBrains IDE Integration
For WebStorm or IntelliJ with Node.js plugin, add the Inspector v2 environment variables to your run configuration:
Node parameters: --inspect --require @anthropic-ai/claude-code/inspector/register
Environment variables: CLAUDE_INSPECTOR_V2=true;CLAUDE_INSPECTOR_SNAPSHOT_DIR=./inspector-captures
CI/CD Integration
For automated testing pipelines, capture failures for post-run analysis:
.github/workflows/test.yml
name: Test Suite
on: [push, pull_request]
jobs:
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Install dependencies
run: npm ci
- name: Run tests with Inspector v2
run: |
node --require @anthropic-ai/claude-code/inspector/register \
npx jest --runInBand --forceExit 2>&1 | tee ./inspector-reports/test-output.log
env:
CLAUDE_INSPECTOR_V2: "true"
CLAUDE_INSPECTOR_SNAPSHOT_DIR: "./inspector-reports/snapshots"
- name: Upload Inspector reports on failure
if: failure()
uses: actions/upload-artifact@v3
with:
name: inspector-v2-reports
path: ./inspector-reports/
retention-days: 14
With 14-day artifact retention, your team has two weeks to download and analyze any CI failure without needing to reproduce it locally. This is particularly valuable for flaky tests that fail intermittently under CI load conditions.
Best Practices and Common Pitfalls
Do’s
- Start with broad capture, then narrow: Begin with full event capture (
captureEvents: ["*"]), then restrict to specific event types once you know where the issue lives. Broad capture on the first run ensures you do not miss context. - Use descriptive labels for checkpoints: Tag your inspection sessions and checkpoints with scenario names like
user-login-high-loadrather than timestamps. This makes captures far easier to search and compare later. - Combine Inspector data with unit tests: After resolving a bug with Inspector, write a unit test that reproduces the exact failure state from the capture. This ensures the regression cannot silently return.
- Set up redaction before your first capture: Configure
redactFieldsbefore any capture that touches authentication, payment, or user PII. It is much harder to remove sensitive data from captures after the fact than to prevent it from being captured. - Archive captures that document resolved bugs: Inspector captures of notable bugs are valuable training material and postmortem documentation. Keep them in a
./inspector-archive/directory, not in your source tree.
Don’ts
- Don’t run high-frequency capture in production: Full event capture in production can increase latency by 5-8% and generates significant log volume. Use exception-only capture (
captureEvents: ["exception"]) if you need Inspector in production at all. - Avoid capturing sensitive data without redaction: Inspector captures request bodies by default. In any environment that handles tokens, passwords, or financial data, configure
redactFieldsfirst. - Don’t skip the analysis phase: Raw Inspector output is JSON data. The real value comes from Claude’s interpretation. identifying which of the 200 captured events is the one that matters, and explaining why. Always take the time to ask Claude for an analysis rather than manually scrolling through raw capture files.
- Don’t use
--inspect-brkin CI: The--inspect-brkflag pauses execution at startup waiting for a debugger to attach. In CI environments without an attached debugger, this will hang your build indefinitely.
Automating Repetitive Inspections
Create reusable inspection scripts for common debugging scenarios:
// scripts/inspector-helper.js
const { execSync, spawn } = require('child_process');
const path = require('path');
const fs = require('fs');
const CAPTURE_DIR = path.resolve('./inspector-captures');
function ensureCaptureDir() {
if (!fs.existsSync(CAPTURE_DIR)) {
fs.mkdirSync(CAPTURE_DIR, { recursive: true });
}
}
function inspectAndCapture(cmd, context = {}) {
ensureCaptureDir();
const timestamp = Date.now();
const label = context.scenario ? `${context.scenario}-${timestamp}` : `${timestamp}`;
const captureFile = path.join(CAPTURE_DIR, `${label}.json`);
const env = {
...process.env,
CLAUDE_INSPECTOR_V2: 'true',
CLAUDE_INSPECTOR_SNAPSHOT_DIR: CAPTURE_DIR,
CLAUDE_INSPECTOR_LABEL: label
};
console.log(`Starting inspection: ${label}`);
console.log(`Command: ${cmd}`);
console.log(`Capture will be written to: ${captureFile}`);
execSync(`node --require @anthropic-ai/claude-code/inspector/register ${cmd}`, {
stdio: 'inherit',
env
});
if (fs.existsSync(captureFile)) {
const capture = JSON.parse(fs.readFileSync(captureFile, 'utf-8'));
console.log(`Capture complete: ${capture.events.length} events recorded`);
return capture;
}
return null;
}
module.exports = { inspectAndCapture };
Then use this in your debugging routine:
const { inspectAndCapture } = require('./scripts/inspector-helper');
// Capture the login flow for analysis
const loginCapture = inspectAndCapture('npm run dev', {
scenario: 'user-login-flow'
});
if (loginCapture) {
console.log(`Events captured: ${loginCapture.events.length}`);
console.log(`Exceptions: ${loginCapture.events.filter(e => e.type === 'exception').length}`);
console.log(`HTTP requests: ${loginCapture.events.filter(e => e.type === 'http-request').length}`);
}
Building a Capture Library
For long-running projects, it is worth building a small capture library that documents known failure scenarios:
// scripts/known-scenarios.js
const { inspectAndCapture } = require('./inspector-helper');
const SCENARIOS = {
loginFlow: () => inspectAndCapture('npx jest tests/auth/login.test.js --runInBand', {
scenario: 'login-flow'
}),
paymentProcessing: () => inspectAndCapture('npx jest tests/payments/ --runInBand', {
scenario: 'payment-processing'
}),
bulkImport: () => inspectAndCapture('node scripts/import-fixtures.js', {
scenario: 'bulk-import'
})
};
module.exports = SCENARIOS;
When a regression is reported, run the relevant scenario from this library to immediately get a fresh capture for Claude to analyze. rather than manually reconstructing the reproduction steps.
Troubleshooting Inspector v2 Setup
Inspector v2 Not Attaching
If you see Inspector v2 not available at startup:
Check CLI version
claude --version
Confirm the inspector register module exists
ls $(npm root -g)/@anthropic-ai/claude-code/inspector/
Verify CLAUDE_INSPECTOR_V2 is set if not using settings.json
echo $CLAUDE_INSPECTOR_V2
Captures Not Being Written
If the process runs but no capture files appear in the snapshot directory:
Confirm the directory is writable
ls -la ./inspector-captures/
Run with verbose Inspector logging
CLAUDE_INSPECTOR_DEBUG=true node --inspect npm start
Verbose mode will print every event to stderr as it is captured, confirming the pipeline is active even if the final snapshot write is failing due to a permissions issue.
Snapshot Files Are Too Large
On large applications with many concurrent requests, capture files can grow to hundreds of MB quickly. Reduce file size with these settings:
{
"inspector": {
"v2": {
"captureEvents": ["exception", "promise-rejection"],
"maxBufferSize": 2000,
"captureStackDepth": 10,
"truncateBodyAt": 1024
}
}
}
truncateBodyAt: 1024 limits request and response bodies to 1KB each, which is usually enough to identify the issue without capturing full multi-MB payloads.
Conclusion
Inspector v2 transforms debugging from a reactive, manual process into an AI-assisted workflow. By capturing rich execution state and using Claude’s reasoning capabilities, you can diagnose complex issues faster and with greater confidence. Start with the basic setup, then gradually incorporate advanced features like async tracing, heap analysis, and CI integration as your debugging needs evolve.
The combination of Inspector v2’s non-blocking event capture with Claude Code’s ability to reason across your full codebase is qualitatively different from traditional debugging. You are no longer just looking at a stack trace. you are giving Claude a complete picture of what the application was doing, thinking, and communicating at the exact moment something went wrong. That context is what makes the difference between a ten-minute diagnosis and a three-hour debugging session.
The key is treating Inspector v2 not as a replacement for your debugging skills, but as an amplifier that makes your expertise more effective. Combined with Claude Code’s understanding of your specific codebase, you will have a powerful ally for tackling the most challenging bugs your team encounters.
Try it: Paste your error into our Error Diagnostic for an instant fix.
Related Reading
- AI Assisted Architecture Design Workflow Guide
- AI Assisted Code Review Workflow Best Practices
- Best Way to Integrate Claude Code into Team Workflow
- Claude Code Literature Review Summarization Workflow
- Claude Code for Halmos Symbolic Workflow Guide
- Claude Code for Polygon zkEVM Workflow
- Claude Code for ZenRows Scraping Workflow Tutorial
- Claude Code for Kotlin Coroutines Flow Workflow
- Claude Code For Lemonsqueezy — Complete Developer Guide
- Claude Code for Notion Workflow Tutorial Guide
- Claude Code for Wasmtime Runtime Workflow Guide
Built by theluckystrike. More at zovo.one
Find the right skill → Browse 155+ skills in our Skill Finder.
Configure permissions → Build your settings with our Permission Configurator.