Driving the keyboard
Two tools reach TermHerd’s own interface — the sidebar, the tab strip, the
overlays — rather than a terminal. Typing into a session stays
run_in_session’s job.
| Tool | Takes | Tests |
|---|---|---|
press_keys | chords in settings.json syntax — "cmd+shift+s", "ctrl+tab", "escape" | the binding, resolved through the live keymap, including your overrides |
run_action | kebab-case action names — "split-vertical", "activate-tab-3" | the behaviour, skipping the keymap, so it survives a rebind |
Both take a list applied in order and return one steps entry per item, plus
the resulting focused_handle.
press_keys names keys as the
chord syntax does. A chord bound to
nothing reaches the focused terminal through TermHerd’s own key encoder, so
"pageup" or "shift+f5" there shows the bytes TermHerd sends for that key.
An arrow follows the cursor-key mode the program asked for, so "up" sends
ESC O A in vim and ESC [ A at a shell prompt that leaves that mode off.
"alt+." sends ESC .: off macOS Alt is always Meta, and on macOS a
synthesised Alt has no side, so it is Meta unless terminal.option_as_meta is
"none" or the user holds only the Option key the setting excludes.
run_in_session writes the caller’s bytes as they are and cannot show it.
Why it is a real key event
A chord is dispatched as a synthesised key event fed to the app’s key handler — the whole routing ladder, not just a keymap lookup.
That is what makes Escape and Enter reachable at all: they are overlay keys, bound to no action. Without them an agent that armed a close confirmation would have no way to answer it, and would park the app until a human intervened.
escape leaves every prompt — that is what guarantees an agent can always
back out. enter confirms confirmation prompts and commits both inline
renames. Menus and pickers handle it themselves, as described below.
The corollary: an open overlay consumes an MCP press exactly as it consumes a
keypress. The step reports which prompt ate it, so a caller learns why its
chord did nothing. run_action is gated on the same ladder on purpose —
neither tool may reach a state the keyboard cannot.
Reading a step
| Outcome | Means | Extra field |
|---|---|---|
ran | the ladder applied it | action — the name that ran |
inert | nothing happened | reason — see below |
overlay | an open prompt consumed it | which prompt |
refused | a prompt’s confirmation typed nothing; it stays open | which prompt, and refusal — why |
typed | bound to nothing, so it reached the focused terminal | |
unbound | nothing claimed it |
ran means the shell applied the event, not that the effect was
interesting: activate-tab-9 on a single-tab workspace reports ran, because
the event was applied and absorbed. Collapsing that into inert would make the
distinction useless.
The two kinds of nothing
inert carries a reason because they call for opposite responses:
| Reason | Means | Do |
|---|---|---|
no-surface | the action is wired to nothing here: open-new-session everywhere, send-to-desktop on Linux | stop — retrying is pointless |
no-context | a precondition was absent — nothing focused to derive a repo from, no closed tab to reopen, no tab to rename, colour or open a menu on, nothing to scroll, nothing selected to copy, no Claude agent name to copy, no Claude able to take a command now (or a colour), no known directory or no transcript a scan has found to reveal | create it, then retry |
Each handler that can refuse this way says so at its own refusal site.
On Windows, copy-agent-name finds a Claude by walking down from the pane’s
shell to the nearest claude.exe. A Claude that runs under another image (an
npm install runs it as node.exe) is never named there, so that no-context
cannot be created.
copy refuses on the terminal’s own answer: it holds a selection or it does
not, wherever that selection has scrolled to. An MCP drag in a forwarded
pane selects nothing (it carries no Shift, so it is the program’s), so copy
after it is no-context — and the program’s own clipboard write (Claude Code
copies a drag on release) is left alone. A human’s Shift+drag there is a
selection, and copy runs on it.
Answering an overlay
escape usually cancels; enter usually confirms. Six cautions:
- On
quit-confirm,enterquits the app — killing every session and the connection you are speaking over, and dropping a modified doc’s edits. session-rename(the sidebar’s inline ✎ field) andtab-renameboth commit onenter;escapeabandons either edit. MCP and the widget submit use the same commit messages. When a rename targets a live Claude session, committing may openclaude-command-confirmfor/rename.tab-menu(opened byopen-tab-menu, or a human’s right-click on a tab) answersup,downandenteritself, so unlike the renames it is fully drivable:entercloses the menu and runs the selected entry exactly asrun_actionwould run that entry’s action. Theenterreports what that action did —ranwith its name, orinertwith its reason — and every other press while the menu is open reportsoverlay: "tab-menu". The entries and their order are on the tabs page. Tab colour… is always listed, but disabled when no colour can be picked for the focused pane (a Claude waiting on an answer, a draft in its prompt, the prompt off screen):enteron it runs nothing, leaves the menu open and reportsrefusedwith the reason. Send to Claude Desktop is disabled the same way, and also while Claude is busy. Copy agent name, Reveal directory, Reveal transcript and Send to Claude Desktop are listed only where they apply (see the tabs page); one left out shifts every entry below it by one. The menu closes if its pane loses focus, so afocus_panecall while it is open dismisses it.tab-color-picker(opened bypick-tab-color, or the tab menu’s colour entry) answersup,downandenterlike the tab menu; its lines arered,blue,green,yellow,purple,orange,pink,cyan, then None, and it opens on the colour the tab wears — on None when it wears none, so an immediateenterleaves it uncoloured.enteron a shell tab sets the colour and closes the list. On a Claude tab it closes the list and opensclaude-command-confirmfor/color <name>, so a secondentertypes it; if that Claude cannot take a command any more,enteranswersrefusedwith the reason and the list stays open.- On
claude-command-confirm,entertypes the slash command the prompt names into its Claude session — or answersrefusedwith the reason, leaving the prompt open, when meanwhile Claude raised a dialog, exited or is not in a state that takes the command, a draft appeared, or its prompt left the screen; seeclaude_command. paste-confirmopens when thepasteaction, or a right-click paste, carries a line break into a terminal that did not turn bracketed paste on; nothing is written untilenterpastes the text unchanged, andescapedrops it. See the terminal page.doc-editorwith unsaved edits answersescapeby openingdoc-discard-confirmrather than closing. There,enterdiscards the edits andescapereturns todoc-editorwith them intact — soescapealone never loses a modified doc, however many times it is pressed.- Every other overlay is exitable from the keyboard, and a test sweep derived from the overlay enumeration — not a hand-written list — is what keeps it that way. A new overlay added without an exit fails there.
Rejection is all-or-nothing
A malformed chord or an unknown action name rejects the whole call before anything applies. The error names the offender and the syntax. This is deliberate: a half-applied sequence is worse than none, because the caller cannot tell how far it got.
The action catalogue — less the activate-tab-N family, which run_action
accepts all the same — is published by the stdio server at
termherd://keys/schema; the live bridge serves tools only, so its run_action
error message carries the syntax instead.
Example: verify a keyboard gesture end to end
run_action(["split-vertical"]) → { steps: [{ result: "ran",
action: "split-vertical" }],
focused_handle: "4" }
screenshot({ max_width: 900 }) → the pixels, to check the divider
press_keys(["cmd+w"]) → { steps: [{ result: "overlay",
overlay: "tab-close-confirm" }] }
press_keys(["escape"]) → cancelled