Keyboard shortcuts

Press ← or → to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

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.

ToolTakesTests
press_keyschords in settings.json syntax — "cmd+shift+s", "ctrl+tab", "escape"the binding, resolved through the live keymap, including your overrides
run_actionkebab-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

OutcomeMeansExtra field
ranthe ladder applied itaction — the name that ran
inertnothing happenedreason — see below
overlayan open prompt consumed itwhich prompt
refuseda prompt’s confirmation typed nothing; it stays openwhich prompt, and refusal — why
typedbound to nothing, so it reached the focused terminal
unboundnothing 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:

ReasonMeansDo
no-surfacethe action is wired to nothing here: open-new-session everywhere, send-to-desktop on Linuxstop — retrying is pointless
no-contexta 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 revealcreate 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, enter quits 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) and tab-rename both commit on enter; escape abandons either edit. MCP and the widget submit use the same commit messages. When a rename targets a live Claude session, committing may open claude-command-confirm for /rename.
  • tab-menu (opened by open-tab-menu, or a human’s right-click on a tab) answers up, down and enter itself, so unlike the renames it is fully drivable: enter closes the menu and runs the selected entry exactly as run_action would run that entry’s action. The enter reports what that action did — ran with its name, or inert with its reason — and every other press while the menu is open reports overlay: "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): enter on it runs nothing, leaves the menu open and reports refused with 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 a focus_pane call while it is open dismisses it.
  • tab-color-picker (opened by pick-tab-color, or the tab menu’s colour entry) answers up, down and enter like the tab menu; its lines are red, 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 immediate enter leaves it uncoloured. enter on a shell tab sets the colour and closes the list. On a Claude tab it closes the list and opens claude-command-confirm for /color <name>, so a second enter types it; if that Claude cannot take a command any more, enter answers refused with the reason and the list stays open.
  • On claude-command-confirm, enter types the slash command the prompt names into its Claude session — or answers refused with 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; see claude_command.
  • paste-confirm opens when the paste action, or a right-click paste, carries a line break into a terminal that did not turn bracketed paste on; nothing is written until enter pastes the text unchanged, and escape drops it. See the terminal page.
  • doc-editor with unsaved edits answers escape by opening doc-discard-confirm rather than closing. There, enter discards the edits and escape returns to doc-editor with them intact — so escape alone 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