A wrapper, a hook and a trivia bank
Put dt in front of a slow command and the terminal shows a trivia question
until the command ends, then hands back its output and exit code untouched. The Claude
Code plugin does the same for an agent: its hooks note when a tool call or a subagent
starts and stops, and a companion pane asks questions once the work has run for
10 seconds.
claude -p runs on Claude Code 2.1.323, one of them recorded below. One hook call takes 46.5 ms at p50 and 48.9 ms at p95, and hooks run async, so Claude Code never waits on them.Recorded session
This is the companion pane. In another process, Claude Code ran headless and was asked to run sleep 24 && echo build ok. The
plugin's PreToolUse hook wrote the call down; after 10 seconds the companion put up a
question (the QWERTY layout), then two more as keys were pressed, and when PostToolUse arrived it printed the land-back
line with the tool and its duration.
Loading the recording...
Captured 2026-11-13 with tmux capture-pane -e every 200 ms while claude -p (Claude Code 2.1.323, model haiku, plugin loaded with --plugin-dir) ran on an Apple M4. Keys were sent with tmux send-keys by the recording script. The frames, timings and keys are in session.json; this page only replays them. Arrow keys step through frames when the slider has focus.
How the plugin knows
An interactive Claude Code session owns its terminal, so dt cannot draw over
it. The plugin's hooks/hooks.json runs node "${CLAUDE_PLUGIN_ROOT}/bin/downtime" hook
on each event below. The hook reads the event JSON from stdin, takes a lock (parallel tool
calls fire parallel hooks), updates ~/.downtime/claude/<session>.json,
prints nothing and exits 0. Every hook is async, so a slow disk can never
hold Claude Code up. The companion polls those files every 400 ms.
| Event | What the hook records |
|---|---|
| PreToolUse | A tool call starts: its name and one line of its input (the command, file or pattern), never a file's contents. |
| PostToolUse, PostToolUseFailure | The call ends. Async hooks can land out of order, so an end that arrives first leaves a marker that cancels its start. |
| SubagentStart, SubagentStop | A subagent works, keyed by its agent id. |
| UserPromptSubmit, Stop, StopFailure | The turn begins and ends, for the optional "turn" trigger that also counts the model thinking. |
| SessionEnd | The session file is deleted. |
The recording found a second, smaller bug: the footer's "running: ..." label was truncated to the screen width minus a fixed 30 columns, so after an answer, when the hint text grows, the long Claude Code label wrapped onto a new line. It is now cut to whatever the hints leave, and a test renders the question at 92 columns before and after an answer. The replay above is the run after the fix.
The first live run found a real bug. Claude launched a subagent through the Agent tool,
the tool returned in 6 ms, and the main Stop event fired while the subagent
was still running its own 8-second Bash call. The first version cleared everything on
Stop, so the companion would have handed you back early. Stop now keeps subagents and
their tools, and a test pins it.
Install
npm install -g github:lyhjeremy/downtime-cli dt npm run build
The wrapper. Node 18 or newer, no dependencies.
claude plugin marketplace add lyhjeremy/downtime-cli claude plugin install downtime@downtime-cli downtime companion # in a second pane; inside tmux this is automatic
The Claude Code plugin. The repository is its own marketplace. downtime config set claude.thresholdSeconds 20 waits longer; claude.trigger turn also counts the model thinking.
I checked the install path on Claude Code 2.1.323: claude plugin validate
passes, and a local-marketplace install with --scope project into a throwaway
CLAUDE_CONFIG_DIR lists the plugin as enabled. That config had no login, so the
live runs loaded the same folder with claude -p --plugin-dir, which installs
nothing. Inside tmux, a run with a 22-second Bash call opened a 16-line pane about 5
seconds after the threshold, and the pane closed itself when the call ended.
The wrapper
dt runs the command with its output held back and the keyboard handed to the
trivia. A command that ends inside 5 seconds prints exactly what it would have printed
bare. Piped output, CI, TERM=dumb and DOWNTIME_DISABLE=1 turn it
into a transparent pass-through. The exit code always comes back, and CI checks that
exit 42 survives. Past 32 MB of held output it stops the game and streams
instead. The plugin reuses this session loop as is: the companion swaps the child-process
runner for one that watches the hook files and emits the same two events.
Limits
The companion only sees what the hooks report. With the default trigger it counts tool
calls and subagents, so a long stretch of the model thinking shows nothing; the
turn trigger covers that but also fires on short answers. A permission prompt
waiting on you looks like a running tool. Outside tmux you open the second pane yourself.
If Claude Code is killed mid-call the end event never comes, so entries older than 30
minutes are ignored. The hook costs about 47 ms of Node start-up per event, off Claude's
critical path because it runs async, but it is CPU all the same. The tmux pane takes the
keyboard focus when it opens.
Next
Notification hook's permission prompts so the companion can say "Claude is waiting on you" and stop the round.src/claude/ holds the hook, the activity state and the companion.node --test; CI matrix Ubuntu and macOS by Node 18, 20, 22.node bench/hook_latency.mjs: 60 runs, p50 46.5 ms, p95 48.9 ms, Apple M4, Node 26.