From 985e1a18bd6ab72f441a9ae1feda12abcfc5e44b Mon Sep 17 00:00:00 2001 From: Bastien Gallay Date: Wed, 11 Nov 2026 11:02:00 +0100 Subject: [PATCH 1/3] docs(book): troubleshooting, environment and orchestration pages; mcp crate no longer deferred - live-bridge.md: drop the hand-kept "What is still open" table for a pointer to the releases, CHANGELOG.md and the area:mcp issue list. - New Reference pages: Troubleshooting (symptom, cause, fix, linking to the page that owns each fact) and Environment variables (what TermHerd reads, what a session receives or loses, and what a custom ZDOTDIR means for zsh integration). - New MCP page: Orchestrating sessions, the recipes for one Claude session driving others through the live bridge. - ARCHITECTURE.md: the mcp name belongs to the shipped control surface; only the IDE bridge stays deferred, and no IdeBridge port exists. The stdio page and docs/agents/mcp.md now point at section 7 for its sketch. - Book architecture page: add private-fs, and the second sanctioned unsafe module. Closes #260 --- docs/ARCHITECTURE.md | 23 +++-- docs/agents/mcp.md | 8 +- docs/src/SUMMARY.md | 3 + docs/src/guide/installation.md | 5 +- docs/src/mcp/index.md | 3 +- docs/src/mcp/live-bridge.md | 16 ++-- docs/src/mcp/orchestrating.md | 123 ++++++++++++++++++++++++++ docs/src/mcp/stdio.md | 10 +-- docs/src/project/architecture.md | 16 ++-- docs/src/reference/environment.md | 83 +++++++++++++++++ docs/src/reference/settings.md | 3 +- docs/src/reference/troubleshooting.md | 118 ++++++++++++++++++++++++ 12 files changed, 377 insertions(+), 34 deletions(-) create mode 100644 docs/src/mcp/orchestrating.md create mode 100644 docs/src/reference/environment.md create mode 100644 docs/src/reference/troubleshooting.md diff --git a/docs/ARCHITECTURE.md b/docs/ARCHITECTURE.md index 1d1d2559..b8c5cafc 100644 --- a/docs/ARCHITECTURE.md +++ b/docs/ARCHITECTURE.md @@ -43,10 +43,11 @@ validated: a session workspace is squarely in pure-native-Rust territory. | PTY process | **portable-pty** | cross-platform spawn/resize, cleaned env | Must | | Storage | **rusqlite** (bundled) + FTS5 | embedded SQLite, WAL, full-text; no entitlement cost | Must | | FS scan/watch | **notify** + **rayon** | debounced watch + parallel scan off the UI thread | Must | -| Async runtime | **tokio** | PTY read loops, fs watch, (later) MCP | Must | +| Async runtime | **tokio** | PTY read loops, fs watch, the MCP servers | Must | | Errors / logging | **thiserror**/`anyhow` + **tracing** | typed errors, structured logs | Must | | Release/update | **dist** (CLI archives) + **cargo-packager** (installers) | one GitHub release; installers unsigned for now and no self-update yet (§14) | Must (update = Should) | -| MCP/IDE server | tokio-tungstenite | per-session WS + JSON-RPC | **Deferred (Unsure)** | +| IDE bridge (termherd as MCP client, §7) | tokio-tungstenite | per-session WS + JSON-RPC | **Deferred (Unsure)** | +| MCP servers (live bridge, stdio) | `rmcp` (live bridge); `serde_json` only (stdio) | termherd as MCP *server* (§7, §15) | Shipped | | Diff / highlight | `similar` + `syntect` | diff + syntax for the panel | **Deferred (Unsure)** | Tabs, splits, and the keymap need **no new crates** — they are pure logic in @@ -101,10 +102,12 @@ structurally prevents a new god-object. written, so a reader looking for it is not missing something, and the file read that would have used it goes through `ProjectScanner`. - ~~`mcp` exists in the workspace only if/when the Unsure bet is taken; nothing - in the v1 path imports it.~~ **Superseded.** This still holds for the `mcp` - *crate* below (§15, `IdeBridge` — termherd as a **client**). It does not hold - for the MCP **control surface** (`F-mcp-control-surface`, #90), which shipped - in the v1 path as a module inside `app` — see §8. + in the v1 path imports it.~~ **Superseded.** The name now belongs to the + shipped MCP **control surface** (`F-mcp-control-surface`, #90): its live + bridge is a module inside `app` (§7, §8), and `crates/mcp` holds its stdio + server and the option catalogue both servers share (§15). What stays + deferred is the IDE bridge (`IdeBridge`, termherd as an MCP **client**, + §7), which has no crate and no port yet. - The rule is CI-enforceable, so "main.js → 1,461 LOC" cannot recur. ## 5. The headless core (the quality keystone) @@ -372,7 +375,7 @@ their job graphs. | `app` | iced GUI: sidebar, tabs, splits, terminal; live MCP bridge | `iced` | Must | | `mcp` | stdio MCP server binary + settings-option catalogue | `core` | Shipped | | `private-fs` | owner-only files and directories | — | Shipped | -| IDE bridge | per-session IDE/MCP WS server (termherd as MCP client) | `tokio-tungstenite` | Deferred | +| IDE bridge | per-session IDE/MCP WS server (termherd as MCP client, sketched in §7); no crate yet, and not `mcp` | `tokio-tungstenite` | Deferred | ## 16. Migration path from the Electron app @@ -396,5 +399,7 @@ their job graphs. - **GUI framework churn.** Mitigation: logic is in `core`; the GUI crate is replaceable without touching tests or adapters. - **Claude format/OSC drift.** Mitigation: isolated, property-tested `claude`. -- **The Unsure bet (MCP/diff) returning later.** Mitigation: the `IdeBridge` - port already exists in `core`; adding the adapter is additive, not a rework. +- **The Unsure bet (IDE bridge/diff) returning later.** Mitigation: it would + enter as a new port in `core::ports` and an adapter implementing it — + additive, not a rework. No `IdeBridge` port exists yet; it is written when + the bet is taken, not ahead of it. diff --git a/docs/agents/mcp.md b/docs/agents/mcp.md index 2479c876..27f9b3ec 100644 --- a/docs/agents/mcp.md +++ b/docs/agents/mcp.md @@ -276,7 +276,7 @@ alongside the widget's `on_submit` path for human input (#246). **Two things named `mcp`.** `crates/mcp` is built: the stdio server `termherd-mcp` and the pure option catalogue both servers share. The live -bridge runs the other way round from it and lives in `app` (`app::mcp`). -`docs/ARCHITECTURE.md` §15 also sketches an `mcp` adapter for -`F-mcp-ide-bridge` — termherd as an MCP *client* of Claude's IDE bridge — and -that one is unbuilt. +bridge is the other server, and lives in `app` (`app::mcp`). What runs the +other way round is `F-mcp-ide-bridge` — termherd as an MCP *client* of +Claude's IDE bridge — which `docs/ARCHITECTURE.md` §7 sketches and §15 lists +on a row of its own: unbuilt, with no crate and no port. diff --git a/docs/src/SUMMARY.md b/docs/src/SUMMARY.md index 5e0806a6..b8481aed 100644 --- a/docs/src/SUMMARY.md +++ b/docs/src/SUMMARY.md @@ -20,6 +20,8 @@ - [Keyboard shortcuts](./reference/keyboard.md) - [settings.json](./reference/settings.md) +- [Environment variables](./reference/environment.md) +- [Troubleshooting](./reference/troubleshooting.md) # Driving termherd over MCP @@ -27,6 +29,7 @@ - [The live bridge](./mcp/live-bridge.md) - [Driving the keyboard](./mcp/keyboard.md) - [Attaching from outside](./mcp/attach.md) +- [Orchestrating sessions](./mcp/orchestrating.md) - [The stdio server](./mcp/stdio.md) # Project diff --git a/docs/src/guide/installation.md b/docs/src/guide/installation.md index 40c1e0fc..4e0f7107 100644 --- a/docs/src/guide/installation.md +++ b/docs/src/guide/installation.md @@ -125,8 +125,9 @@ one; closing it closes TermHerd. The `RUST_LOG` environment variable sets what is logged wherever it goes, for example `termherd=debug`. -TermHerd is **single-instance**: an advisory lock file under the system temp -directory. A second launch carrying a `termherd://` link hands it to the +TermHerd is **single-instance**: a lock named after the system temp directory +(a file there on macOS, a named mutex on Windows, an abstract socket on +Linux). A second launch carrying a `termherd://` link hands it to the running instance and exits with code 0; the tab opens there without bringing the window forward. Without a link, it exits with code 2. To run a second build alongside one that already holds the lock, point it at a diff --git a/docs/src/mcp/index.md b/docs/src/mcp/index.md index 77d36626..83ef4e56 100644 --- a/docs/src/mcp/index.md +++ b/docs/src/mcp/index.md @@ -57,7 +57,8 @@ a terminal is a decision, not a default. ## Which one you want - *"Split this pane and run the tests"* → **live bridge**. It only exists - inside a session TermHerd started. + inside a session TermHerd started. One session driving others through it: + [Orchestrating sessions](./orchestrating.md). - *"Switch me to a light theme"* → either. Both carry `list_options` and `set_option`, over one shared catalogue; the write lands in `settings.json` and a running TermHerd applies it at once. From a session TermHerd started, diff --git a/docs/src/mcp/live-bridge.md b/docs/src/mcp/live-bridge.md index 065a87af..7e3e7461 100644 --- a/docs/src/mcp/live-bridge.md +++ b/docs/src/mcp/live-bridge.md @@ -390,10 +390,12 @@ A worked example, from inside a session TermHerd launched: unknown pointer word, is refused the same way. - A wedged shell surfaces as a tool error, never a hang. -## What is still open - -One follow-up: - -| Gap | Issue | -| --- | --- | -| No pointer at TermHerd's own interface: the sidebar, the tab strip, a split gutter. | [#301](https://github.com/Termherd/termherd/issues/301) | +## What has shipped, and what is open + +This page describes the bridge as it is built. What each release added is in +the [release notes](https://github.com/Termherd/termherd/releases) and the +project's +[`CHANGELOG.md`](https://github.com/Termherd/termherd/blob/main/CHANGELOG.md); +what is still open is the issue list filtered on the +[`area:mcp`](https://github.com/Termherd/termherd/issues?q=is%3Aissue%20is%3Aopen%20label%3Aarea%3Amcp) +label. diff --git a/docs/src/mcp/orchestrating.md b/docs/src/mcp/orchestrating.md new file mode 100644 index 00000000..4e35fd53 --- /dev/null +++ b/docs/src/mcp/orchestrating.md @@ -0,0 +1,123 @@ +# Orchestrating sessions + +Recipes for one Claude session driving others through the +[live bridge](./live-bridge.md): opening workers, handing them work, waiting +for them and reading what they did. Every tool named here is a live-bridge +tool; a Claude session lists them as `mcp__termherd__`. + +The driving session must be one TermHerd launched as a Claude tab, or a client +[attached from outside](./attach.md). A `claude` typed by hand into a shell +pane has no bridge. + +## Find a session, and keep its handle + +`list_sessions` answers one row per live session. Address every later call by +the row's **`handle`**. Never use `resume_id`: Claude Code re-keys a +conversation on a fork or a plan-accept, while the handle stays the same for +as long as the session lives. + +Each row also says what the session runs (`kind` is `shell` or `claude`), its +working directory, its status, and, for a Claude, the `peer_name` other Claude +sessions address it by. Two Claude tabs in the same directory are told apart +by their handle and `peer_name`, not by their title. + +## Open a worker without taking the user's keyboard + +```json +{ "tool": "open_session", + "args": { "project": "/path/to/worktree", "kind": "claude", "background": true } } +``` + +`background: true` appends the tab without activating it, so the next key the +user types still lands where they were typing. Read the new session from +`opened_handle`, not from `focused_handle`. A new Claude session starts on +`starting`: wait for `idle` before handing it work. + +Close a finished worker the same way, with `close_pane` and +`background: true`. + +## Hand work over as a brief file + +Write the task into a file in the worker's own directory — say +`.personal/brief.md` in its worktree — and type one short line: + +```json +{ "tool": "run_in_session", + "args": { "session": "12", "text": "Read .personal/brief.md and carry it out.\n" } } +``` + +A file can be as long as the task needs, the user can read and amend it, and +it outlives the conversation that wrote it. A one-line prompt is typed +reliably, and the worker reads the whole brief with its own tools. A trailing +newline in `text` is sent as Enter and submits; earlier newlines stay line +breaks, so a multi-line prompt is still submitted once. + +## Act, wait, observe + +`run_in_session` returns as soon as the text is sent. Follow it with a wait, +then a read: + +1. `run_in_session` — type the prompt. +2. `wait_for_status` with `statuses: ["busy"]` — just after typing, the + session still shows the status it had *before*, so a wait for `idle` + straight away answers at once with the old one. +3. `wait_for_status` with `statuses: ["idle", "attention"]`. +4. `read_terminal` — the last lines of the screen, as text. + +`prompt_in_session` does all three in one round trip: it types, waits up to +2 s for the status to leave its old value, waits for the target statuses, and +returns the screen text. Prefer it for a prompt; keep the separate calls when +you need to act between the steps. + +Never poll `snapshot` to wait: it races the very transition you are waiting +for, and a `snapshot` loop costs far more than one wait. + +`attention` means the worker is asking for something — a permission prompt, a +question. Read the screen and decide. An outward action it proposes (a push, +a public comment, closing an issue) waits for the user's answer, not yours. + +## Long runs and the wait cap + +A wait is bounded: `timeout_ms` defaults to 30 000 and is capped at 300 000 +(five minutes), on `wait_for_status` and `prompt_in_session` alike. A timeout +is not an error: the call returns `{ status, timed_out: true }` with the +session's current status. For a task that runs longer, wait again — reading +the screen between two waits shows how far it got. A session that exits +settles any wait with `exited`. + +## Prompting another Claude needs an opt-in + +`prompt_in_session` refuses a **Claude** target unless nesting is allowed, +either for every call: + +```json +{ "mcp": { "allow_claude_nesting": true } } +``` + +or for one call, with `allow_claude_nesting: true` among its arguments. A +shell target is never gated. The separate `run_in_session` + +`wait_for_status` calls are not gated either: the opt-in guards the composed +call only. + +## Text already in another tab's input box + +Before typing into a Claude session you did not just open, read its screen. +Text already sitting in its input box is usually a **suggestion** Claude Code +offers, drawn there for the user to accept or ignore — and in plain text it +looks exactly like something the user typed. It may also be the user's own +unfinished draft. Either way, it is not yours to send: never submit it +without asking the user. + +## Leave the screenshot for last + +`read_terminal` answers what a session printed. `screenshot` returns the whole +window as a PNG and weighs hundreds of times a `snapshot`: take one only for a +question text cannot answer — a colour, a glyph, a layout — and at the end of +the run rather than inside a loop. + +## TermHerd's own interface + +`press_keys` and `run_action` drive TermHerd, not a terminal. An open prompt +takes their keys, and `escape` leaves any prompt. `enter` on the quit prompt +quits TermHerd, and with it the bridge the driving session is talking through. +See [Driving the keyboard](./keyboard.md). diff --git a/docs/src/mcp/stdio.md b/docs/src/mcp/stdio.md index 2f443e5d..4d2995d9 100644 --- a/docs/src/mcp/stdio.md +++ b/docs/src/mcp/stdio.md @@ -88,11 +88,11 @@ platform the server runs on. ## What it is not It does not reach the running app: no sessions, no tabs, no terminals, no -keyboard. That is the [live bridge](./live-bridge.md), and it exists only -inside a session TermHerd launched. +keyboard. That is the [live bridge](./live-bridge.md), which reaches a session +TermHerd launched, or a client [attached from outside](./attach.md). It is also **not** `F-mcp-ide-bridge` — a deferred, unbuilt feature that would run the other way round, with TermHerd as an MCP *client* of Claude's IDE -bridge. `docs/ARCHITECTURE.md` §15 lists an `mcp` crate as deferred under that -name; the server described here lives in the same repository but answers a -different question. +bridge. `docs/ARCHITECTURE.md` §7 sketches that bridge, and §15 lists it as a +row of its own, apart from the `mcp` crate: the crate holds the server +described here and the option catalogue both servers share. diff --git a/docs/src/project/architecture.md b/docs/src/project/architecture.md index 8b5bca18..46a336e2 100644 --- a/docs/src/project/architecture.md +++ b/docs/src/project/architecture.md @@ -28,8 +28,13 @@ adapter. | `claude` | a pure codec for the Claude CLI's own formats — path encode/derive, JSONL digest, OSC decode | nothing | | `app` | the iced GUI shell; builds the adapters in `main()` and injects them; owns the one effect executor and the MCP control surface | `core` + adapters | | `scan` | filesystem discovery — walks `~/.claude/projects` | `core` | -| `pty` | the terminal adapter (`portable-pty` + `alacritty_terminal`) | `core` | -| `mcp` | the stdio settings server | `core` | +| `pty` | the terminal adapter (`portable-pty` + `alacritty_terminal`) | `core`, `private-fs` | +| `mcp` | the stdio settings server, and the option catalogue both MCP servers share | `core` | +| `private-fs` | owner-only files and directories (`0600` / `0700`) | nothing | + +The live MCP bridge is not a crate: it lives in `app`, as a bridge *into* the +shell. The IDE bridge — TermHerd as an MCP *client* of Claude's own — is +deferred and unbuilt. When adding code the question is *which crate does this belong in?* If the answer is "the core should call this adapter directly", the answer is wrong — @@ -67,9 +72,10 @@ Non-negotiable, and CI-enforced: - `unwrap`, `expect` and `panic` are **clippy-denied** in `core` and `claude`. Production paths return typed errors. -- `unsafe_code` is **denied workspace-wide**. The one sanctioned exception is - the macOS AppKit FFI (the Cmd+Q quit path, the menus, the text and link - relays): a `cfg`-gated module with a `SAFETY:` note on every block. +- `unsafe_code` is **denied workspace-wide**. The two sanctioned exceptions + are the macOS AppKit FFI (the Cmd+Q quit path, the menus, the text and link + relays) and the Win32 process listing a ConPTY pane's Claude is found + through: each a `cfg`-gated module with a `SAFETY:` note on every block. - **No global mutable state** — no `static mut`, no `lazy_static`, no require-time singletons. Dependencies are built in `main()` and injected. - **One logging stack**: `tracing`. No `println!` outside tests. diff --git a/docs/src/reference/environment.md b/docs/src/reference/environment.md new file mode 100644 index 00000000..7289d7e0 --- /dev/null +++ b/docs/src/reference/environment.md @@ -0,0 +1,83 @@ +# Environment variables + +TermHerd reads a few variables from the environment it starts in, and sets a +few on every session it spawns. None is required. + +## What TermHerd reads + +| Variable | Read for | Notes | +| --- | --- | --- | +| `TERMHERD_MCP_ATTACH` | publishing the live bridge for this launch | `1` / `true` / `yes` / `on` turns `mcp.attach` on, `0` / `false` / `no` / `off` turns it off, case-blind. Anything else is ignored, and so is any value when the setting is `"never"`. See [Attaching from outside](../mcp/attach.md#turning-it-on). | +| `RUST_LOG` | what is logged | For example `termherd=debug`. Where the log goes: [Installation](../guide/installation.md#where-the-log-goes). | +| `TMPDIR` (macOS, Linux), `TMP` (Windows) | the system temp directory | The single-instance lock is named after it, so a build given its own temp directory runs beside the installed one. Each session's private files (the MCP config, shell integration) live there too. | +| `USERPROFILE`, then `HOME` | your home directory | `~/.termherd` and `~/.claude` are found from it. With neither set, nothing is persisted. | +| `ZDOTDIR`, `TERMHERD_ORIG_ZDOTDIR` | where a zsh session replays your startup files from | See [below](#termherd_orig_zdotdir). | + +## What a session receives + +Every session TermHerd spawns, shell or Claude, inherits TermHerd's own +environment with these changes: + +| Variable | Value | Why | +| --- | --- | --- | +| `TERM` | `xterm-256color` | a colour-capable terminal type | +| `TERM_PROGRAM` | `iTerm.app` | Claude Code emits its busy / idle / attention stream only when it believes it runs under iTerm2 — see [Status and attention](../workspace/status.md#where-the-signal-comes-from) | +| `TERM_PROGRAM_VERSION` | `3.5.0` | read with `TERM_PROGRAM` as "a recent iTerm2" | +| `ZDOTDIR` | a private per-session directory | zsh only: how the prompt marks are installed | +| `TERMHERD_ORIG_ZDOTDIR` | the directory your own startup files were replayed from | zsh only, and only when TermHerd found one — your `ZDOTDIR`, or else your home | + +Some variables are **removed**: the ones a Claude Code session exports to name +*itself* — `CLAUDECODE`, `CLAUDE_CODE_ENTRYPOINT`, +`CLAUDE_CODE_CHILD_SESSION`, `CLAUDE_CODE_SESSION_ID`, +`CLAUDE_CODE_SESSION_ATTENDED`, `CLAUDE_CODE_MESSAGING_SOCKET`, +`CLAUDE_CODE_MESSAGING_TOKEN`, `CLAUDE_CODE_EXECPATH`, `CLAUDE_PID`, +`CLAUDE_EFFORT` and `AI_AGENT`. A TermHerd started from inside a Claude session +would otherwise hand them on, and each Claude it launched would take itself +for part of that session. The variables you set on purpose, such as +`CLAUDE_CONFIG_DIR` or `CLAUDE_CODE_USE_BEDROCK`, reach every session +unchanged. + +The live bridge's address and token are **not** in the environment: a Claude +session receives them in a private file passed with `--mcp-config`. + +## `TERMHERD_ORIG_ZDOTDIR` + +zsh reads every startup file from `$ZDOTDIR`. To install its prompt marks, +TermHerd points `ZDOTDIR` at a private directory whose `.zshenv`, +`.zprofile`, `.zshrc` and `.zlogin` each source your own file of the same name +first, then (in `.zshrc` only) add the hooks. Your own files are looked for in, +in order: + +1. `TERMHERD_ORIG_ZDOTDIR`, when set; +2. `ZDOTDIR`, when set to a directory TermHerd did not generate; +3. `HOME`. + +`TERMHERD_ORIG_ZDOTDIR` records the directory that was displaced, so a +TermHerd started from a TermHerd zsh still finds your files rather than the +outer session's private ones. + +What this means if you use a custom `ZDOTDIR`: + +- **Inside a session, `$ZDOTDIR` is not yours.** It names the private + directory. A script that needs your configuration directory reads + `${TERMHERD_ORIG_ZDOTDIR:-$ZDOTDIR}`. +- **Export it before TermHerd starts.** A `ZDOTDIR` in the environment + TermHerd inherits works: a launch from a terminal whose shell exported it, + for example. +- **A `ZDOTDIR` set in `~/.zshenv` takes the session over.** Sourcing your + `~/.zshenv` changes `ZDOTDIR`, and zsh then reads `.zprofile` and `.zshrc` + from *your* directory instead of the private one. Your configuration loads, + but TermHerd's hooks never do: the session gets no prompt marks, and its + status falls back on the foreground process (macOS, Linux). This is what + happens when TermHerd starts from the Dock, Finder or a desktop launcher, + whose environment never ran your shell. Starting TermHerd from a terminal + avoids it. +- **`.zlogout` is not replayed.** zsh reads it from the private directory, + where there is none. +- **A `ZDOTDIR` typed on a command line inside a session is overridden.** + `ZDOTDIR=… termherd` started from a TermHerd zsh still replays from + `TERMHERD_ORIG_ZDOTDIR`, which takes precedence. Unset it first to + choose another directory. + +bash and fish read only `HOME`, and take their hooks as a command-line +argument; neither sets a variable. diff --git a/docs/src/reference/settings.md b/docs/src/reference/settings.md index e5dd22bb..2fbb87a8 100644 --- a/docs/src/reference/settings.md +++ b/docs/src/reference/settings.md @@ -177,7 +177,8 @@ Two keys, both off by default. `allow_claude_nesting`: whether the live bridge's `prompt_in_session` may prompt another **Claude** session — one agent driving another. A shell session is never gated. A single call can opt in on its own with -`allow_claude_nesting: true` (see [The live bridge](../mcp/live-bridge.md)). +`allow_claude_nesting: true` (see [The live bridge](../mcp/live-bridge.md), +and [Orchestrating sessions](../mcp/orchestrating.md) for the whole loop). ```json "mcp": { "allow_claude_nesting": false } diff --git a/docs/src/reference/troubleshooting.md b/docs/src/reference/troubleshooting.md new file mode 100644 index 00000000..3258b966 --- /dev/null +++ b/docs/src/reference/troubleshooting.md @@ -0,0 +1,118 @@ +# Troubleshooting + +Each entry gives a symptom, its cause and the fix, then links to the page that +explains it in full. The environment variables named here are listed in +[Environment variables](./environment.md). + +## TermHerd will not start a second time + +**Symptom.** A second launch exits at once, with code 2, and no window opens. + +**Cause.** TermHerd is single-instance. The lock is named after the system temp +directory, so a second launch from the same environment finds it taken. A +launch that carries a `termherd://` link hands the link to the running instance +and exits with code 0 instead. + +**Fix.** Use the window already open. To run a second build beside it — a +build from source, a worktree — give that build a throwaway temp directory +(`TMPDIR` on macOS and Linux, `TMP` on Windows), so its lock has another name. +The commands are in +[Installation](../guide/installation.md#where-the-log-goes). + +## Where is the log? + +| Platform | The log goes to | +| --- | --- | +| macOS, Linux | stderr: start TermHerd from a terminal to read it | +| Windows, release build | `%USERPROFILE%\.termherd\termherd.log`, even when started from a terminal | +| any OS, debug build from source | the terminal it was started from | + +On Windows the log is renamed `termherd.log.old` at the first launch after it +reaches 5 MB, and a fresh one starts. `RUST_LOG` sets what is logged, for +example `RUST_LOG=termherd=debug`. Details: +[Where the log goes](../guide/installation.md#where-the-log-goes). + +## A console window opens beside TermHerd on Windows + +**Symptom.** Started from Explorer or the Start menu, TermHerd opens a black +console window as well as its own; closing the console closes TermHerd. + +**Cause.** TermHerd asks Windows not to allocate a console when nothing hands +it one. Only Windows 11 24H2 and later read that request; older versions +ignore it. + +**Fix.** Leave the console open, or update Windows. Started from a terminal, +TermHerd uses that terminal's console on every version. + +## A notification click does nothing + +**Symptom.** Clicking a desktop notification does not bring the session +forward. + +| Platform | Cause | Fix | +| --- | --- | --- | +| Windows | Once a toast times out into the action centre, its click is lost. | Click the toast while it is still on screen. | +| Linux | The notification server must support actions; some do not. | Use a notification server that supports actions. | +| Linux, Wayland | The compositor may refuse to raise the window. | Switch to TermHerd by hand; the right tab is already active. | +| any | More than 16 notifications wait for a click. | Click or dismiss earlier ones. | + +A click also changes nothing but the window when the tab has closed, or while +a prompt is open (a close confirmation, the settings panel, the document +editor). + +On Windows a toast is attributed to **PowerShell**, not TermHerd: TermHerd does +not register an application id of its own yet. That is expected, not a sign of +something else posting it. + +Details: [Desktop notifications](../workspace/status.md#desktop-notifications). + +## A Claude session has no `termherd` MCP server + +**Symptom.** `/mcp` in a Claude session lists no `termherd` server, or a +client cannot reach the live bridge. + +**Cause.** TermHerd hands the live bridge only to the Claude sessions it +launches itself: a new Claude tab, or a session reopened from the sidebar. It +passes the endpoint on that launch's command line. A `claude` typed by hand +into a shell pane, or started in another terminal, gets nothing. + +**Fix.** + +- Open the session from TermHerd as a Claude tab. +- To reach the bridge from a client TermHerd did not launch, turn on + `mcp.attach`, restart TermHerd, and register the client with + `termherd mcp-config` — see + [Attaching from outside](../mcp/attach.md#turning-it-on). When that command + prints nothing, its message on stderr says why: + [When there is nothing to print](../mcp/attach.md#when-there-is-nothing-to-print). +- With `"attach": "never"` in `settings.json`, `TERMHERD_MCP_ATTACH=1` is + ignored on purpose: see + [Refusing it outright](../mcp/attach.md#refusing-it-outright). + +To change settings from any Claude session, TermHerd-launched or not, the +[stdio server](../mcp/stdio.md) needs no running app. + +## `settings.json` seems ignored + +| Symptom | Cause | Fix | +| --- | --- | --- | +| At startup, the sidebar says the file was set aside, and defaults apply. | The file was not valid JSON. It was moved to `settings.json.corrupt-1` (then `-2`, …) so nothing TermHerd saves can overwrite it. | Fix the copy and move it back. | +| An edit made while TermHerd runs changes nothing. | The saved file does not parse; the running settings stay as they were. | Fix the syntax and save again. | +| A number is not the one you wrote. | Out-of-range values clamp: `terminal.font_size` to 6–40, for example. | Use a value inside the range. | +| One key has no effect, the rest do. | A bad value (a typo'd colour, an unknown action name) degrades alone, with a warning in the log. | Read the warning in the [log](#where-is-the-log). | +| A change shows up only later. | Some keys apply at the next session, recording or launch: `shell`, `record`, `mcp.attach`. | Open a new session, start a new recording, or restart. | + +The file is strict JSON: no comments, no trailing commas. Details: +[How it loads](./settings.md#how-it-loads). + +## A plain shell's status stays on `starting` + +**Cause.** The shell reports no prompt marks. TermHerd injects them into zsh +always, and into bash and fish only when `settings.shell` names them; an +unknown shell gets none. On macOS and Linux the foreground process stands in +until the first mark; Windows has no such fallback. + +**Fix.** Name your shell in `settings.json`. A zsh whose `~/.zshenv` sets +`ZDOTDIR` loses the marks too: see +[`TERMHERD_ORIG_ZDOTDIR`](./environment.md#termherd_orig_zdotdir). Details: +[Where the signal comes from](../workspace/status.md#where-the-signal-comes-from). From e90e783c30583cf7ebb0f8ed7ded82a246ae0eb1 Mon Sep 17 00:00:00 2001 From: Bastien Gallay Date: Wed, 11 Nov 2026 11:05:57 +0100 Subject: [PATCH 2/3] docs(book): orchestrating page matches a live run over the bridge A new Claude worker is already idle when the open returns, and Claude Code pads its screen with blank rows, so the default 40-line read can miss the reply. --- docs/src/mcp/orchestrating.md | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/docs/src/mcp/orchestrating.md b/docs/src/mcp/orchestrating.md index 4e35fd53..c62c4f3a 100644 --- a/docs/src/mcp/orchestrating.md +++ b/docs/src/mcp/orchestrating.md @@ -30,8 +30,9 @@ by their handle and `peer_name`, not by their title. `background: true` appends the tab without activating it, so the next key the user types still lands where they were typing. Read the new session from -`opened_handle`, not from `focused_handle`. A new Claude session starts on -`starting`: wait for `idle` before handing it work. +`opened_handle`, not from `focused_handle`. Wait for `idle` before handing the +new session work: the wait answers at once when Claude is already at its +prompt. Close a finished worker the same way, with `close_pane` and `background: true`. @@ -64,6 +65,11 @@ then a read: 3. `wait_for_status` with `statuses: ["idle", "attention"]`. 4. `read_terminal` — the last lines of the screen, as text. +Ask for more lines than the default 40 when reading a Claude session, on +`read_terminal` and `prompt_in_session` alike: Claude Code pads its screen with +blank rows between the conversation and the input box, and on a tall pane the +last 40 lines can hold none of the reply. `lines: 80` or more reaches it. + `prompt_in_session` does all three in one round trip: it types, waits up to 2 s for the status to leave its old value, waits for the target statuses, and returns the screen text. Prefer it for a prompt; keep the separate calls when From 42dd0930dcd6b93805b87cebaa5f668795e5ee5f Mon Sep 17 00:00:00 2001 From: Bastien Gallay Date: Wed, 11 Nov 2026 11:09:41 +0100 Subject: [PATCH 3/3] docs(architecture): rewrap the merged risk line to 80 columns --- docs/ARCHITECTURE.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/docs/ARCHITECTURE.md b/docs/ARCHITECTURE.md index d55989d4..6ddd2289 100644 --- a/docs/ARCHITECTURE.md +++ b/docs/ARCHITECTURE.md @@ -400,4 +400,5 @@ their job graphs. replaceable without touching tests or adapters. - **Claude format/OSC drift.** Mitigation: isolated, property-tested `claude`. - **The Unsure bet (IDE bridge/diff) returning later.** Mitigation: an - `IdeBridge` would be one more `core::ports` trait and adapter; additive, not a rework. + `IdeBridge` would be one more `core::ports` trait and adapter; additive, + not a rework.