Spot tool calls above an elapsed-time threshold.

Part of OpenMod Lab, by Jerry Wang. MIT licensed.
Requires Claude Code 2.1.287+. Inspect the source before loading; native mods run with your user permissions.
claude plugin validate ./plugins/latency-lens
claude --plugin-dir ./plugins/latency-lens
Change SLOW_MS to tune the threshold. Keeps the latest 20 slow-call names/timings in module memory; displays the latest three. No command is registered. Reload/session restart clears memory.
hooks/register.js 38 lines1// OpenMod Latency Lens · MIT
2// Change this threshold, then rerun the replay.
3const SLOW_MS = 100;
4let slow = [];
5let total = 0;
6
7export function register(on) {
8 on('tool.call', async ($, e, next) => {
9 const start = await $.clock.now();
10 try {
11 return await next(e);
12 } finally {
13 const ms = Math.max(0, (await $.clock.now()) - start);
14 total += 1;
15 if (ms >= SLOW_MS) {
16 slow.push({ tool: e.tool, ms });
17 slow = slow.slice(-20);
18 }
19 $.ui.invalidate('ui.render');
20 }
21 });
22
23 on('ui.render', { component: 'AbovePrompt' }, ($, e, next) => {
24 if (e.props.hasSurvey || !total) return next(e);
25 const { Box, Text } = $.ui.resolve(e);
26 const recent = slow.slice(-3);
27 return Box({ paddingX: 1, children: [
28 Text({ color: 'cyan',
29 children: 'Latency Lens · ' + total + ' calls'
30 + ' · threshold ' + SLOW_MS + 'ms' }),
31 Text({ color: slow.length ? 'yellow' : 'green',
32 children: recent.length
33 ? recent.map(r => r.tool + ' ' + r.ms + 'ms').join(' / ')
34 : 'No calls above the threshold.' })
35 ] });
36 });
37}
38