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 firesNotificationwithidle_promptregardless of running agents; the marker flipped the state toneeds_inputand the needs-input push fired while the agents were still working. This is deterministic for every turn that ends with agents pending. - After
/cleara 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 theidle_promptmarker, newer than the fresh transcript), andLocateTranscriptreturned 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, isquestion; (2) registrywaitingisneeds_input(questionif a dialog is composed); (3) registrybusyisworking, overriding the fold; (4) registryidlelets the transcript fold decideneeds_inputvsidleexactly as before, pending-work hold included; (5) no usable status falls back to the fold alone. Registryidleis never mapped straight toneeds_input: it cannot tell "the turn just ended" from "a fresh session". - Entry selection and staleness.
statusandwaitingForare read from the very entryLocateTranscriptpicks (cwd match, live pid, neweststartedAt), so transcript and state come from one session. Unusable means the entry is missing orstatusis empty or not one ofbusy/waiting/idle(the CLI has been seen to write others, such asshell). There is no age bound onstatusUpdatedAt: 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.blockedStateand the marker file are gone, andSpoolSigno longer digests a marker. There is no whitelisted fallback: the pinned CLI always writesstatus. - A reason surfaces as
state_detail.waitingForbecomes an optionalstate_detailstring onprovider.Chat, the messages response, therun.messages.changedenvelope 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. /clearfollows the registry. ThesessionIdrotates at clear time;LocateTranscriptreturns the computed transcript path even before the file exists; for an active run a missing transcript reads as an empty idle chat, neverErrTranscriptGone. Ended runs are unchanged (StateEnded, transcript only,ErrTranscriptGonefor a retired file).- Seam shape.
provider.ReadSpecgainsHome(the instance HOME for an active run,""for an ended one, so a terminal view never consults a registry) andWorktree(the cwd the registry entry is matched by).LiveSignals.SpoolSigbecomesSpoolSig(runID, dir, home)and digests the registry too, so a status flip republishes while the transcript is byte-frozen.provider.ChatgainsStateDetail. Core passes opaque locations and interprets nothing; the codex adapter ignoresHomeandWorktree. - The notify gate is untouched. The edge-triggered push still fires when the state settles into
needs_inputorquestion; 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_promptis 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
statusUpdatedAtso a stalebusyexpires. 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
idledirectly toneeds_input. Rejected:idleis also what a fresh session and a just-cleared one report, and those must readidle. The fold stays the arbiter for that case. - A SessionStart hook on the
clearsource to signal rotation. Rejected: not needed, since the registry rotatessessionIdat clear time. It stays available if a future CLI makes that lag. - Surface
waitingForas 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
workingon 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 readsneeds_inputand pushes once, as before. /clearreadsidlewithin 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_inputwith the CLI's own reason beside it, on the status line, the state dot and the push. internal/provider/claudecodeno longer arms a Notification hook; the per-run settings file shrinks to the two dialog hooks andenv. Operators see no new setting.- The state now depends on a registry field Claude Code does not document, so compat §2 pins
status,waitingForandstatusUpdatedAtwith a fixture per status, §5 thesystem/local_commandclear 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. pidAlivechecks 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'spidDomain: 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
workingwith registrybusyreadsworking; with registryidlethe fold decides), unusable statuses, the/clearwindow and the ended-run read.