How Simon Willison Gave Claude Code 'Ears' and Found a Beeping Sensor in a Closet Within 40 cmArticle · digest for December 1
Still life in a closet with cardboard boxes, five household gadgets, and concentric acoustic triangulation sound waves
Article4 sections≈ 10 min

How Simon Willison Gave Claude Code 'Ears' and Found a Beeping Sensor in a Closet Within 40 cm

After a move, almost every home ends up with one closet stacked high with unpacked boxes. One day, something inside developer Simon Willison's closet started beeping. The chirp came so rarely that standing in the clutter trying to place the sound by ear didn't work, and tearing through dozens of boxes by hand had zero appeal.

Instead of a deep clean, Willison opened Claude Code Cloud on his iPhone (Opus 5.5 in Extra thinking effort mode) and dropped a task into an empty repo: turn gadgets scattered around the room into an acoustic locator. That's how the open-source Beep Locator project was born under an Apache-2.0 license—along with a trick that literally gives a text-only agent "ears."

A closet full of boxes and a 2007 research paper

First, Willison asked Claude Code not to write code blind, but to draft problem.md and test one bold idea: could devices in the room ping each other with sound and calculate their own 2D positions without a tape measure?

The agent quickly dug up the classic 2007 BeepBeep paper by Microsoft Research Asia researchers (Chunyi Peng et al., ACM SenSys). It solved the exact same puzzle: how to measure distances between ordinary gadgets accurately without special sensors or clock sync.

Why can't you just turn on microphones and compare timestamps? System clocks on phones and laptops drift apart, and operating systems add variable delays to the audio path. At the speed of sound (around 340 m/s), a 10-millisecond error throws off your estimate by over three meters—in a closet, you might as well guess boxes at random.

The BeepBeep authors got around this with three ideas: two-way ranging, self-recording, and sample counting. Each gadget records both its own chirp and the other device's chirp on a single audio track, measuring the gap by counting samples inside its own stream. Internal microphone and speaker delays cancel out cleanly in the math.

Inside Beep Locator: Python, WebAudio, and a sound 'clapperboard'

The stack stayed simple: a local Python 3.10+ server (Starlette, Uvicorn, NumPy, Click, and QR generator Segno) plus plain browsers on five household devices—two iPads, a smartphone, a MacBook Pro, and a Surface Ultra.

A laptop opens the coordinator screen with a room map, event log, and QR code. The other devices scan the code, get color names ("Red," "Blue"), and tap Start listening to monitor the room. Audio enters the browser via the Web Audio API, a built-in engine with access to raw audio samples. Tabs talk to the server over WebSockets (a persistent two-way channel for events and commands). Mobile browsers require HTTPS for mic access, so uv run beep-locator serve --tunnel spins up a cloudflared tunnel right away. For testing without five devices, a /sim simulator is built in.

Web Audio API audio routing graph showing AudioContext, sources, effects, and destination (Source: developer.mozilla.org)

Each browser keeps a 60-second ring buffer and runs detector.js. A high-pass filter cuts anything below 800 Hz, while an adaptive floor (30th percentile) tracks background noise. On a sharp volume spike, the detector runs a Fast Fourier Transform (FFT)—an algorithm that splits a slice of audio into individual frequencies.

const N = 2048;
// Grab 2048 samples around the volume spike
const s = ctx.samples(p.frame - 256, p.frame - 256 + N);
const re = new Float64Array(N);
const im = new Float64Array(N);
// Smooth fragment edges with a Hann window
for (let i = 0; i < N; i++) {
  const w = 0.5 - 0.5 * Math.cos((2 * Math.PI * i) / (N - 1));
  re[i] = s[i] * w;
}
fft(re, im);

const lo = Math.max(1, Math.floor((c.band_lo * N) / sr));
const hi = Math.min(N / 2 - 1, Math.ceil((c.band_hi * N) / sr));
const mags = [];
let best = lo;
let bestMag = 0;
for (let k = lo; k <= hi; k++) {
  const m = Math.hypot(re[k], im[k]);
  mags.push(m);
  if (m > bestMag) {
    bestMag = m;
    best = k;
  }
}
// Compare peak to median and send event to server
const prominence = bestMag / (percentile(mags, 0.5) + 1e-12);
const freq = (best * sr) / N;
ctx.send("onset", {
  frame: p.frame,
  snr_db: +(p.db - p.floor).toFixed(1),
  freq: Math.round(freq),
  prominence: +prominence.toFixed(1),
});

The prominence metric separates a clean electronic tone from ordinary knocks or footsteps. Once a beep is caught, the listener sends an onset event to the server.

Next comes a trick like a movie clapperboard. When five cameras shoot a scene with mismatched clocks, one shared clap aligns every track during editing. In Beep Locator, the server picks the device with the lowest RTT (round-trip packet time) and asks it to play a short chirp pulse. Every listener slices a clip from 0.6 seconds before the beep to 0.8 seconds after the pulse and uploads it to SQLite and WAV files on the server. That shared chirp aligns clips without system clocks, and source coordinates are solved via TDOA (grid search plus Gauss–Newton) from millisecond arrival differences across microphones.

Hot-swapping code on the fly: installModule() and live debugging

On mobile browsers, reloading a page often drops microphone permission. Walking around five devices after every code edit is torture. So in his second prompt, Willison asked Opus 5.5 to build hot-swapping so the agent could update listener code over WebSocket. runtime.js gained an installModule() method.

async installModule({ name, code, version }) {
  const existing = this.modules.get(name);
  if (existing && existing.version === version && !existing.error) {
    this.sendRaw({ type: "module_status", name, version, ok: true });
    return;
  }
  // Wrap incoming JS code in a Blob and import on the fly
  let factory;
  const blob = new Blob(
    [code + `\n//# sourceURL=module:${name}.js`],
    { type: "text/javascript" }
  );
  const url = URL.createObjectURL(blob);
  try {
    const mod = await import(url);
    factory = mod.default;
  } finally {
    URL.revokeObjectURL(url);
  }
  // Tear down old module and start the new one
  if (existing) this._teardown(existing);
  const ctx = this.moduleContext(name);
  try {
    const instance = (await factory(ctx)) || {};
    this.modules.set(name, { version, ctx, instance, factory });
    this.sendRaw({ type: "module_status", name, version, ok: true });
  } catch (e) {
    // Roll back to previous working version on failure
    ctx.cleanup();
    if (existing?.factory) {
      const ctx2 = this.moduleContext(name);
      const inst2 = (await existing.factory(ctx2)) || {};
      this.modules.set(name, { ...existing, ctx: ctx2, instance: inst2 });
    }
  }
}

The browser receives the new module text, wraps it in a Blob, and loads it via dynamic import(). The old module shuts down via _teardown(), the new one starts on the same live AudioContext, and if anything crashes, the client rolls back to the last working version. Mic permission stays intact.

Hot-swap security note

Both installModule() and the ctl eval CLI command let the server run arbitrary JavaScript in connected browsers, while --auto-update pulls commits and restarts the server automatically. Keep the coordinator URL and BEEP_TOKEN secret, and leave auto-update off.

After cloning the project to his laptop, Fable 5.2 came out, so Willison switched debugging over to it. The agent kept the server running itself, checked logs, SQLite, and clips (ctl events, ctl sql, ctl clips), and pushed updates to browsers (ctl push) while Willison used short prompts to tailor the UI to the real closet.

Automatic sound-based self-calibration got thrown off by echoes and boxes, so they added "Rough mode": drag device icons onto the map by hand, and the system refines their positions from chirps. To check accuracy, they added a clap mode—claps appear as diamonds, beeps as crosses, each stamped with an HH:MM:SS timecode. The "Sounds located" log got sequential playback from each mic (pausing recording during playback) plus a "This is the mystery beep" button so the locator remembers the target frequency and tracks intervals between beeps. Near the end, they added "Reposition the devices" to move iPads closer without reloading tabs, plus a hint marker showing where an extra device helps most.

40 centimeters to the sensor and giving coding agents 'senses'

The locator narrowed the search zone to about 40 centimeters. Willison unpacked that exact stack of boxes and pulled out an old carbon monoxide detector with a dying battery.

Claude Code has no native audio input—on its own, the agent sees only text in a terminal. Yet a thin "sensory bridge" made of a Python server, browser mics, and hot-swapped code gave a text model ears and closed a feedback loop with a real room: hear a sound, test a hypothesis, rewrite the detector, and test again.

A similar trick works for "vision." At GitHub Universe, GitHub VP Martin Woodward shared how he debugged conference badges built on the Raspberry Pi RP2350 chip with a screen. He plugged the board in over USB-C and pointed a webcam at it: GitHub Copilot built firmware, flashed the badge, and looked through the camera to check whether the screen lit up—all the way to porting Doom.

Want a deep diveVotes help us choose what to break down in detail. This material has 0 votes.
Sources · 4