# moth harness adapters Each adapter sends the coding agent's **final reply of a turn** to the running moth server, one way: `POST $MOTH_URL/api/agent` with `{"text": "", "source": "claude-code", "session": "", "label": "moth-repo"}`. `source` is the harness name; `session` is a stable id of the agent session and `label` a short name for it, the basename of its working directory (else the first 8 characters of the session id). Cards show them as "claude · moth-repo said…" in moth's page and `moth tail`. `session` and `label` are optional: an older adapter without them counts as one session per harness. `MOTH_URL` defaults to `http://127.0.0.1:4747`. Every adapter follows the same rules: - It uses a 1 s timeout and never throws or prints. The JS and Hermes adapters never wait inside the agent's own code path; the Claude Code and Codex hooks run in the foreground, so a one-shot run can't kill them before they post (the wait is the hook's start-up plus one local POST that moth only queues, 1 s at most). - It posts nothing when moth is down. If moth is slow, it hangs up after 1 s, but moth keeps the text: `serve.py` reads the request body first and the page polls `/api/log`. - It posts nothing for subagent turns, aborted turns, or turns with no assistant text. It never re-sends an older reply. - It needs no dependencies beyond Python's stdlib or the harness's own JS runtime (`fetch`). - It sends moth's per-install token (`X-Moth-Token`, read from `~/.moth/token` on every post; moth makes the file on its first run, `MOTH_TOKEN_FILE` overrides). Python adapters bypass any HTTP proxy set in the environment. moth doesn't react to every turn: at most one reaction per 2 minutes (`--react-every`), except when the agent apologises, reports a failure or an error, or writes a very long message. While you're chatting with moth (the last 60 s, `--quiet-after`) it holds its reaction until you stop. Every turn still shows up as a card; only ~25 words of each one stay in moth's memory after it reacted, so agent turns don't push your conversation out. Several sessions at once (any mix of harnesses): - **Batching.** When moth may react, it first waits `--batch-window` seconds (default 4) for other sessions to finish too. Then it reacts to the most interesting message: a failure, apology or error first, then a question to you, then a long message, then a routine "done" (the newest wins a tie). The others show as skipped cards. Batched cards appear when the window closes, the chosen one last, so moth's reply sits right under it. `--batch-window 0` turns this off, and `--react-every 0 --quiet-after 0` (the judge tooling) still reacts to every message at once, with no window. - **No mix-ups.** moth's history keeps one agent turn per session: when it reacts to session B, the older agent turns of B, and all but the newest of every other session, are dropped together with moth's replies to them (agent turns carry a session marker in the history that the model never sees). moth's input stays exactly what it trained on (`[the agent said]` + the message); session names never go into it. - **Seeing them.** The page shows "2 agents active · 1 skipped" (sessions that posted in the last 30 min) and, with two or more sessions, a dropdown to show one session's cards (moth's replies always show). `moth tail --session