Skip to content

Claude Code's conversational state is driven by the CLI's own session-registry status; the Notification hook and its blocked marker are removed

ADR-0038 made the adapter own "what state is my agent in", composed from the agent's best signals. For Claude Code those signals were the transcript tail (a fold that guesses working vs needs_input vs idle), the PreToolUse dialog spool (ADR-0020), and a Notification-hook "blocked marker" that mapped any notification_type to needs_input. On the pinned CLI (2.1.284) two failures recurred (issue #79):

  • A run waiting on background subagents read "Waiting for you". The turn ends with agents still running and the fold correctly holds working. Sixty seconds later the CLI fires Notification with idle_prompt regardless of running agents; the marker flipped the state to needs_input and the needs-input push fired while the agents were still working. This is deterministic for every turn that ends with agents pending.
  • After /clear a run sometimes read "Waiting for you" instead of idle. The marker could outlive the clear (a clear within 60 s of the last turn still got the idle_prompt marker, newer than the fresh transcript), and LocateTranscript returned a miss until the new transcript file existed, so the old transcript's tail kept deciding the state.

The CLI already publishes the right signal. The session registry file lab reads for sessionId (<home>/.claude/sessions/<pid>.json, compat §2) carries a status the CLI rewrites on every transition: busy (a query is loading or delegated background agents are still active), waiting with waitingFor (a dialog or prompt is on screen), or idle (neither). /clear rewrites the same entry with the new sessionId in the same step. Verified live on CLI 2.1.284 (2026-10-09): busy for the whole background-agent wait, waiting / "permission prompt" on a permission dialog, waiting / "input needed" on AskUserQuestion, and the sessionId rotating at /clear time, before any next message.

The decisions, pinned:

  • Layered composition inside the Claude adapter's ReadChat (ADR-0038 stands). Precedence: (1) a spool dialog, or a transcript-flushed pending dialog, is question; (2) registry waiting is needs_input (question if a dialog is composed); (3) registry busy is working, overriding the fold; (4) registry idle lets the transcript fold decide needs_input vs idle exactly as before, pending-work hold included; (5) no usable status falls back to the fold alone. Registry idle is never mapped straight to needs_input: it cannot tell "the turn just ended" from "a fresh session".
  • Entry selection and staleness. status and waitingFor are read from the very entry LocateTranscript picks (cwd match, live pid, newest startedAt), so transcript and state come from one session. Unusable means the entry is missing or status is empty or not one of busy/waiting/idle (the CLI has been seen to write others, such as shell). There is no age bound on statusUpdatedAt: it is event-driven, not a heartbeat, and a dead CLI is caught by tmux liveness.
  • The Notification hook and the blocked marker are removed. Per-run settings carry PreToolUse and PostToolUse (plus env) only. blockedState and the marker file are gone, and SpoolSig no longer digests a marker. There is no whitelisted fallback: the pinned CLI always writes status.
  • A reason surfaces as state_detail. waitingFor becomes an optional state_detail string on provider.Chat, the messages response, the run.messages.changed envelope and the instances list. The status line reads "Waiting for you · permission prompt", the Runs page state dot's tooltip and aria label carry it, and the needs-input push uses it as the body when no dialog prompt exists (ahead of the latest assistant text). It is secret-masked like other chat content, and core forwards it verbatim without branching on it.
  • /clear follows the registry. The sessionId rotates at clear time; LocateTranscript returns the computed transcript path even before the file exists; for an active run a missing transcript reads as an empty idle chat, never ErrTranscriptGone. Ended runs are unchanged (StateEnded, transcript only, ErrTranscriptGone for a retired file).
  • Seam shape. provider.ReadSpec gains Home (the instance HOME for an active run, "" for an ended one, so a terminal view never consults a registry) and Worktree (the cwd the registry entry is matched by). LiveSignals.SpoolSig becomes SpoolSig(runID, dir, home) and digests the registry too, so a status flip republishes while the transcript is byte-frozen. provider.Chat gains StateDetail. Core passes opaque locations and interprets nothing; the codex adapter ignores Home and Worktree.
  • The notify gate is untouched. The edge-triggered push still fires when the state settles into needs_input or question; it simply stops seeing a false edge.

Status

Accepted 2026-10-09. Resolves issue #79. Amends ADR-0020: the PreToolUse/PostToolUse dialog spool stands as shipped, but its Notification hook and blocked marker (the "residual blocked states" badge) are retired and superseded by the registry status. Amends ADR-0038: composition stays adapter-owned, but its precedence list (spool dialog, flushed dialog, blocked marker, transcript) is replaced by the one above, ReadSpec gains Home and Worktree, and SpoolSig gains a home argument. Compat §2, §5 and §9 are updated in the same change.

Considered options

  • Keep the Notification hook and whitelist the types that mean "blocked". Rejected: the CLI's type list is wider than the compat record pinned, idle_prompt is the one that fires after every turn, and the marker still outlived /clear. Any whitelist is a guess about a moving enum, where the registry states the condition directly.
  • Age-bound statusUpdatedAt so a stale busy expires. Rejected: the field changes on transitions, not on a timer, so a long permission prompt or a long agent wait would look stale and flip to the fold's guess. A crashed CLI is already caught by its pid and by tmux liveness.
  • Map registry idle directly to needs_input. Rejected: idle is also what a fresh session and a just-cleared one report, and those must read idle. The fold stays the arbiter for that case.
  • A SessionStart hook on the clear source to signal rotation. Rejected: not needed, since the registry rotates sessionId at clear time. It stays available if a future CLI makes that lag.
  • Surface waitingFor as a free-form message in the chat stream. Rejected for the same reason as ADR-0038's synthetic dialog message: the message stream stays purely transcript-derived so seq numbers stay stable. A side-channel field carries it.

Consequences

  • A run that ends its turn with background agents pending stays working on the Runs page, rail and status line for the whole wait and pushes nothing until the agents finish and the agent truly stops; then it reads needs_input and pushes once, as before.
  • /clear reads idle within one poll, whether issued seconds or minutes after the last turn, and the chat resets to the fresh conversation.
  • A permission or elicitation prompt lab cannot render reads needs_input with the CLI's own reason beside it, on the status line, the state dot and the push.
  • internal/provider/claudecode no longer arms a Notification hook; the per-run settings file shrinks to the two dialog hooks and env. Operators see no new setting.
  • The state now depends on a registry field Claude Code does not document, so compat §2 pins status, waitingFor and statusUpdatedAt with a fixture per status, §5 the system/local_command clear echo and the "fresh transcript may not exist yet" rule, and §9 records the hook's removal and why. A CLI upgrade that changes the field degrades to the transcript fold (decision 5 of the precedence), not to an error.
  • pidAlive checks the registry entry's pid on the host. For a container run that pid is in the container's namespace and passes by accident of matching a host thread; this is harmless because every run has its own HOME and registry, and is recorded in compat §2 rather than fixed here. Amended 2026-11-03: the accident stopped holding under nested containers (ADR-0086), where claude is not pid 2 and the entry was dropped, so a nested run read as an empty chat. Liveness is now decided per entry by the registry's pidDomain: an entry in the lab process's own pid namespace is probed as before, an entry in another namespace (or without the field) is taken as live, and tmux liveness stays the dead-CLI signal for containers. The rule is pinned in compat §2.
  • The Claude adapter's tests cover the precedence table, the subagent sequence (fold working with registry busy reads working; with registry idle the fold decides), unusable statuses, the /clear window and the ended-run read.