Skip to main content
rule CX Codex

debug-devtools — Claude Code rule for Three.js debugging

The debug-devtools rule guides an agent through adding diagnostics for Three.js performance, scene parameters, and WebGL context loss. Use it when tracking down a rendering bottleneck or inspecting a scene.

MIT ★ 4,719 updated 2026-10-24

Install into Claude Code · Manually: put the files in place All methods and platforms ↓
.claude/rules/debug-devtools.md
Open on GitHub

What debug-devtools does

The rule covers FPS monitoring with stats-gl, live camera and material tweaks through lil-gui, and renderer counters for draw calls, triangles, geometries, and textures. It also describes inspecting WebGL frames with Spector.js and timing stages of an animation loop with performance.now().

Other topics include Three.js helper objects, context-loss handling, and using setAnimationLoop for rendering. For React Three Fiber, it shows r3f-perf; for raycasting, it uses three-mesh-bvh. These tools serve different purposes: Spector.js exposes individual WebGL calls, while renderer.info reports renderer counters.

WebGPU timing queries require the adapter to support timestamp-query. The Chrome instructions point to the “WebGPU Developer Features” flag in chrome://flags. Remove debugging code before production.

What it helps with

  • check FPS and renderer counters
  • find a slow stage in the animation loop
  • tweak camera and material parameters live
  • inspect WebGL frames and individual draw calls
  • handle WebGL context loss and restoration

Example prompts for the agent

  • Add Three.js diagnostics for FPS and renderer counters to this scene.
  • Measure the physics, controls, and rendering stages in the animation loop.
  • Handle WebGL context loss and restart the scene after the context returns.

How to install debug-devtools

Manually: put the files in place

.claude/rules/debug-devtools.md

The paths frontmatter field limits the files

Step by step, with commands for each platform: AGENTS.md vs CLAUDE.md: what they are and which one to use

Questions about debug-devtools

How do I install debug-devtools in Claude Code?

Add the rule file at .claude/rules/debug-devtools.md.

What does debug-devtools do?

It guides Three.js debugging, including performance monitoring, scene tweaks, WebGL profiling, and context-loss handling.

Does the rule cover React Three Fiber?

Yes. It shows how to place r3f-perf inside <Canvas> to display performance information.

Source text

debug-devtools.md · MIT
# Debug & DevTools

> Source: [100 Three.js Tips - Utsubo](https://www.utsubo.com/blog/threejs-best-practices-100-tips)

Comprehensive debugging toolkit for Three.js applications.

## stats-gl (WebGL/WebGPU)

Modern performance monitor that works with both renderers:

```javascript
import Stats from 'stats-gl';

const stats = new Stats();
document.body.appendChild(stats.dom);

function animate() {
  stats.begin();
  // ... render
  stats.end();
  requestAnimationFrame(animate);
}
```

## lil-gui for Live Tweaking

```javascript
import GUI from 'lil-gui';

const gui = new GUI();

gui.add(camera.position, 'x', -10, 10);
gui.add(camera.position, 'y', -10, 10);
gui.add(camera.position, 'z', -10, 10);
gui.add(light, 'intensity', 0, 2);
gui.addColor(material, 'color');

// Folders for organization
const folder = gui.addFolder('Material');
folder.add(material, 'metalness', 0, 1);
folder.add(material, 'roughness', 0, 1);
```

## renderer.info

Monitor GPU memory and draw calls:

```javascript
setInterval(() => {
  console.log('Calls:', renderer.info.render.calls);
  console.log('Triangles:', renderer.info.render.triangles);
  console.log('Geometries:', renderer.info.memory.geometries);
  console.log('Textures:', renderer.info.memory.textures);
}, 1000);
```

## Spector.js for WebGL Profiling

Browser extension that captures WebGL frames with draw call visualization.

1. Install Spector.js extension
2. Click extension icon on any WebGL page
3. Click red record button
4. Inspect individual draw calls, shaders, state

## three-mesh-bvh for Fast Raycasting

```javascript
import { MeshBVH, acceleratedRaycast } from 'three-mesh-bvh';

// Build BVH for mesh
mesh.geometry.boundsTree = new MeshBVH(mesh.geometry);

// Replace default raycast with accelerated version
mesh.raycast = acceleratedRaycast;

// Now raycasting is much faster
raycaster.intersectObject(mesh);
```

## GPU Timing Queries (WebGPU)

```javascript
const adapter = await navigator.gpu.requestAdapter();
const hasTimestamps = adapter.features.has('timestamp-query');

if (hasTimestamps) {
  const device = await adapter.requestDevice({
    requiredFeatures: ['timestamp-query']
  });
  // Use timestamp queries for GPU profiling
}
```

## Profile Animation Loop

```javascript
function animate() {
  const t0 = performance.now();

  physics.update();
  const t1 = performance.now();

  controls.update();
  const t2 = performance.now();

  renderer.render(scene, camera);
  const t3 = performance.now();

  console.log(
    `Physics: ${(t1-t0).toFixed(2)}ms`,
    `Controls: ${(t2-t1).toFixed(2)}ms`,
    `Render: ${(t3-t2).toFixed(2)}ms`
  );

  requestAnimationFrame(animate);
}
```

## Context Lost Handling

```javascript
renderer.domElement.addEventListener('webglcontextlost', (event) => {
  event.preventDefault();
  console.warn('WebGL context lost');
  // Stop animation loop
  cancelAnimationFrame(animationId);
});

renderer.domElement.addEventListener('webglcontextrestored', () => {
  console.log('WebGL context restored');
  // Reinitialize and restart
  init();
  animate();
});
```

## Chrome WebGPU DevTools

Enable "WebGPU Developer Features" in `chrome://flags` for:
- Shader compilation error tracking
- Resource inspection
- Performance profiling

## Browser DevTools Performance Tab

Profile real sessions to identify:
- Frame timing issues
- Garbage collection pauses
- JavaScript bottlenecks
- Layout thrashing

## r3f-perf (React Three Fiber)

```jsx
import { Perf } from 'r3f-perf';

<Canvas>
  <Perf position="top-left" />
  <Scene />
</Canvas>
```

## Debug Helpers

```javascript
// Axes helper
scene.add(new THREE.AxesHelper(5));

// Grid helper
scene.add(new THREE.GridHelper(10, 10));

// Box helper for bounds
const box = new THREE.BoxHelper(mesh, 0xffff00);
scene.add(box);

// Skeleton helper
const skeleton = new THREE.SkeletonHelper(skinnedMesh);
scene.add(skeleton);

// Light helpers
const lightHelper = new THREE.DirectionalLightHelper(light, 5);
scene.add(lightHelper);
const shadowHelper = new THREE.CameraHelper(light.shadow.camera);
scene.add(shadowHelper);
```

## Clean Render Loop

Use `setAnimationLoop` for cleaner code:

```javascript
renderer.setAnimationLoop(() => {
  controls.update();
  renderer.render(scene, camera);
});

// Stop when needed
renderer.setAnimationLoop(null);
```

## Debug Checklist

- [ ] Add stats-gl for FPS monitoring
- [ ] Use lil-gui for parameter tweaking
- [ ] Check renderer.info for draw calls
- [ ] Profile with Spector.js
- [ ] Use three-mesh-bvh for raycasting
- [ ] Handle context loss gracefully
- [ ] Use r3f-perf for React apps
- [ ] Remove debug code in production

© zebbern · MIT · zebbern/claude-code-guide

Similar IDE rules

All IDE rules for Game dev and 3D: Unity, Unreal, Godot, Blender →

From the same set86

The whole set →
loading-suspense loading-suspense — a rule that keeps async React Three Fiber components inside Suspense, so a model still downloading doesn't leave the canvas blank. CX Codex +1 ★ 4,719repo stars lighting-shadows-advanced The lighting-shadows-advanced rule covers lighting and shadow settings in Three.js with rendering cost in mind. Use it when tuning a scene with several lights or shadow maps. CX Codex +1 ★ 4,719repo stars migration-checklist migration-checklist teaches the agent how to migrate code when Three.js updates. Lists breaking changes from r125 onwards and current import paths. CX Codex +1 ★ 4,719repo stars audio-spatial The audio-spatial rule for Claude Code provides Three.js 3D audio patterns for source positioning, distance falloff, and response to user interaction. CX Codex +1 ★ 4,719repo stars tsl-post-processing A reference rule for TSL post-processing in Three.js: chain effects onto postProcessing.outputNode instead of stacking EffectComposer passes. CX Codex +1 ★ 4,719repo stars tsl-compute-shaders tsl-compute-shaders guides the agent in writing WebGPU compute shaders with Three.js TSL for GPGPU tasks like particle systems and physics. CX Codex +1 ★ 4,719repo stars animation-system animation-system — a practical guide to Three.js animation, from playing and blending clips to morph targets and bones. Useful when building scenes with animated models. CX Codex +1 ★ 4,719repo stars gltf-loading-optimization gltf-loading-optimization is a Claude Code rule with Three.js snippets and commands for glTF loading, decoder setup, progress reporting, lazy loading and model compression. CX Codex +1 ★ 4,719repo stars

Project sponsors

Companies that keep this analytics open