If you've ever clicked through Awwwards winners or Apple's interactive product pages, you know that instant hit of awe: glowing 3D objects drifting smoothly behind your cursor, light refracting through frosted glass, particles exploding into a cinematic swirl as you scroll.
Open the source code of one of those pages, though, and awe turns into quiet dread. Web 3D graphics built on Three.js and low-level GLSL shaders (OpenGL Shading Language) is one of the most unforgiving corners of frontend engineering. You have to think like an artist, a mathematician fluent in transformation matrices, and a systems programmer manually chasing GPU memory leaks.
Anthropic's terminal agent, Claude Code CLI, flips that pipeline on its head. Unlike standard chatbots that spit code snippets into a text box, Claude Code lives right inside your terminal. It reads your file tree, installs npm packages, compiles shaders, and fixes WebGL rendering bugs on the fly. Let's walk through a step-by-step recipe for building an interactive 3D scene with an agent doing the heavy lifting.
Pipeline Architecture: Why an Agent Handles 3D Better Than Copy-Paste
Why does copy-pasting Three.js code from a web chatbot almost always leave you staring at a blank black screen? Because 3D rendering demands tight alignment across half a dozen layers at once:
- Initializing the Canvas and
WebGLRenderer; - Configuring
PerspectiveCameraaspect ratios and updating the projection matrix on window resize; - Running the
requestAnimationFramerender loop; - Setting up geometries, physical materials, and light sources;
- Compiling external fragment shaders through bundler plugins.
Miss a single line and the scene simply refuses to render—often without throwing a single error in the console. A terminal agent takes over that whole setup. It scaffolds a clean Vite project, wires up the bundler, and connects each module into a working pipeline step by step.
Practical Workflow: From Empty Terminal to Floating Torus Knot
Let's run through it in five minutes. All you need upfront is Node.js 18+ and Claude Code CLI installed globally.
First, spin up the project and install dependencies:
# Create a Vite project and install Three.js
npm create vite@latest 3d-interactive-showcase -- --template vanilla
cd 3d-interactive-showcase
npm install three
claude
Inside the Claude Code session, we don't write code by hand. We give an architectural spec in plain English:
"Design an interactive 3D scene in main.js: a central floating TorusKnot reacting with smooth inertia (LERP 0.05) to mouse movement, a system of 2,000 glowing particles, and dynamic resizing when the browser window changes."
The agent analyzes the brief and writes a clean main.js structure. Look at how neatly it handles motion smoothing:
import * as THREE from 'three';
const scene = new THREE.Scene();
const camera = new THREE.PerspectiveCamera(75, window.innerWidth / window.innerHeight, 0.1, 1000);
camera.position.z = 5;
const renderer = new THREE.WebGLRenderer({ antialias: true, alpha: true });
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
document.body.appendChild(renderer.domElement);
const geometry = new THREE.TorusKnotGeometry(1.2, 0.35, 128, 32);
const material = new THREE.MeshStandardMaterial({
color: 0x6366f1,
roughness: 0.2,
metalness: 0.8
});
const torusKnot = new THREE.Mesh(geometry, material);
scene.add(torusKnot);
const pointLight = new THREE.PointLight(0xffffff, 2, 50);
pointLight.position.set(5, 5, 5);
scene.add(pointLight, new THREE.AmbientLight(0x222233, 1.5));
let mouseX = 0, mouseY = 0;
let targetX = 0, targetY = 0;
window.addEventListener('mousemove', (event) => {
mouseX = (event.clientX / window.innerWidth - 0.5) * 2;
mouseY = (event.clientY / window.innerHeight - 0.5) * 2;
});
function animate() {
requestAnimationFrame(animate);
// Smooth coordinate interpolation (LERP)
targetX += (mouseX - targetX) * 0.05;
targetY += (mouseY - targetY) * 0.05;
torusKnot.rotation.y = targetX * 1.5;
torusKnot.rotation.x = targetY * 1.5;
torusKnot.rotation.z += 0.005;
renderer.render(scene, camera);
}
animate();
window.addEventListener('resize', () => {
camera.aspect = window.innerWidth / window.innerHeight;
camera.updateProjectionMatrix();
renderer.setSize(window.innerWidth, window.innerHeight);
});
Custom Shader Generation: The Fresnel Glow Effect
When standard Three.js materials aren't enough and you want a signature look—like a neon rim glow around an object—the agent reaches for custom GLSL shaders.
Instead of spending hours wrestling with vector math, you tell Claude: "Add a pulsing Fresnel glow shader effect." The model writes the fragment shader:
uniform float uTime;
varying vec2 vUv;
varying vec3 vNormal;
void main() {
vec3 normal = normalize(vNormal);
float pulse = sin(uTime * 2.0) * 0.5 + 0.5;
float fresnel = pow(1.0 - dot(normal, vec3(0.0, 0.0, 1.0)), 2.0);
vec3 glowColor = mix(vec3(0.2, 0.4, 1.0), vec3(0.9, 0.2, 0.8), pulse);
gl_FragColor = vec4(glowColor * (fresnel + 0.3), 1.0);
}
Claude Code automatically updates vite.config.js to handle .glsl imports and wires the uTime uniform into the render loop.
WebGL Traps: Phone Batteries and VRAM Leaks
Building 3D interfaces comes with two classic traps that trip up newcomers every time.
First is hardware greed. Run native-resolution rendering with antialiasing on a high-DPI 3x Retina phone screen, and frame rates tank to 15 FPS while the battery melts. Notice that line renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2))—capping pixel density at 2 keeps mobile devices from overheating.
Second is memory leaks. In normal JavaScript, the garbage collector sweeps up unused variables automatically. In WebGL, geometries and textures live directly in GPU memory. If you only remove an object from the scene with scene.remove(mesh), it disappears from view while staying stuck in VRAM. Switch views a few times and memory leaks until the browser tab crashes with WebGL Context Lost. Claude Code knows the cleanup rules and explicitly calls geometry.dispose() and material.dispose() on teardown.
Pairing Three.js with a terminal agent shrinks the gap between a bold visual idea and working code down to minutes. You don't need a linear algebra degree anymore to ship smooth, cinematic graphics on the web.

