Repository navigation
Hand the session-list closing rule to the agent at each leaf wait launch - #1026
Conversation
The rule for ending a turn with a `needs input:` line lived in the host reference, read hours before the closing reply it governs. Replaying session e390c26f's final turn, neither that wording nor a note in the delivery envelope moved the reply (0/6 across settings); the same rule added to the background launch's tool result did (6/6), and stayed quiet on a turn where nothing was owed (0/6). A PostToolUse entry now prints hooks/wait-started.json after a `leaf wait` launch. Claude Code's `if` filter keeps it off other commands. Codex runs the same hooks.json, ignores `if`, and fires it on every shell call, so the command gates on CLAUDECODE and the command text itself. The reference keeps the mechanism and points at the file. TODO records when to move this into `leaf hook`. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
Codex started from inside Claude Code inherits CLAUDECODE, the one case the command-text check covered; it is rare enough not to carry a second condition. Claude Code's `if` filter already keeps the hook off other commands. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
leaf-agent
left a comment
There was a problem hiding this comment.
The only thing confining this hook to a leaf wait launch is if, which the host evaluates. The registered command never reads its stdin payload — it prints whenever CLAUDECODE is set — so on a Claude Code build that does not honor if (zod strips unknown keys rather than rejecting the entry), every Bash tool result gains "leaf wait is now watching your pages in the background" plus the needs input: directive. Running the registered command out of the merged tree, it prints the guidance for echo hello and ls -la exactly as it does for the launch.
The host dimension is guarded in the command itself, precisely because Codex ignores if. The command dimension is left to the host, and nothing records which Claude Code honors if — the repo does pin a host version where one carries a behavior, in skills/leaf/scripts/leaf/session-lifetime.md ("Claude Code 2.1.274 fires UserPromptSubmit for…").
The new test cannot see this: launch never reaches the command, so test_a_leaf_wait_launch_under_claude_code_carries_the_closing_guidance passes identically with launch = "echo hello", and its docstring's "and nothing anywhere else" holds only along the CLAUDECODE axis. The suggested clause makes that argument load-bearing while leaving the test green.
It closes the unbounded case, not the substring one: a grep -rn "leaf wait" skills/ still matches the payload the same way *leaf wait* matches the command.
…lter The review found the command printed its guidance for any Bash call under Claude Code, leaving the command dimension to an `if` filter a Claude Code build may not honor. The command now reads the payload, and the test runs a non-launch command to hold that. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
…nch (#1026) Claude Code's session list (`claude agents`) groups a background session by how its last reply ends. It moves the session to Needs input only on a `needs input:` line. The rule asking for that line sat in `host-claude-code.md`, which the agent reads hours before the closing reply it governs. Replays of session e390c26f's final turn showed that neither that wording nor a note in the `leaf wait` envelope got the line written (0/6 across settings). A `PostToolUse` hook now adds the rule to the tool result of each `leaf wait` launch, the last thing the agent reads before its closing reply. In the same replay that got the line written 6/6: 3/3 with a user CLAUDE.md, 3/3 with project settings only. It wrote none (0/6) on a turn where nothing was owed. - `hooks/hooks.json`: a `PostToolUse` Bash entry with `"if": "Bash(*leaf wait*)"`, which prints `hooks/wait-started.json` only when `CLAUDECODE` is set and the payload names `leaf wait`. Codex 0.156.1 runs the same file, ignores `if`, and fires the entry on every shell call, as I measured, so the command checks both itself rather than relying on the filter. - `host-claude-code.md`: "Session list" keeps the mechanism (the row reads Working while `leaf wait` runs) and points at the hook file, so the rule has one home. - `TODO.md`: when to route tool-result guidance through `leaf hook` instead of static text, and the case for making `leaf hook` cheap enough to use that way. It costs about 0.3–0.5s warm and 2.5s cold today, and the host waits on it. - Test: runs the registered command through `sh` with a hook payload and checks that it prints the guidance under Claude Code and nothing otherwise. > _This was written by Claude Code on behalf of max-sixty_ 🤖 Generated with [Claude Code](https://claude.com/claude-code) --------- Co-authored-by: Claude Opus 5.5 (1M context) <[email protected]>
…1033) Claude Code's session list groups a background session by the closing line of its last reply, and that grouping ignores background tasks. A `result:` line files the session under Completed even while `leaf wait` runs; only the row's word stays Working, since Claude Code checks for a running task before anything else. The hook from #1026 asked only for `needs input:`. A session holding a settled page ended with neither line, and Claude Code's classifier filed it under Working. That is why Leaf sessions waiting on a page sat under Working indefinitely. - `hooks/wait-started.json` also asks for `result: <what you delivered>`, but only when nothing waits on the user or on work the agent still has running (the watcher itself aside). - `host-claude-code.md` "Session list" explains both parts: the word Claude Code holds at Working, and how the closing line sets the group, including what happens with neither line. I replayed the closing turn with the new wording, 6 runs per scenario, and every run chose the right ending: - e390c26f's open decisions → `needs input:` (6/6) - a merged fix whose page had settled → `result:` (6/6) - a merge whose CI watcher was still running → neither line (6/6) Two earlier wordings failed the second and third cases. > _This was written by Claude Code on behalf of max-sixty_ 🤖 Generated with [Claude Code](https://claude.com/claude-code) --------- Co-authored-by: Claude Opus 5.5 (1M context) <[email protected]>
Claude Code's session list (
claude agents) groups a background session by how its last reply ends. It moves the session to Needs input only on aneeds input:line. The rule asking for that line sat inhost-claude-code.md, which the agent reads hours before the closing reply it governs. Replays of session e390c26f's final turn showed that neither that wording nor a note in theleaf waitenvelope got the line written (0/6 across settings).A
PostToolUsehook now adds the rule to the tool result of eachleaf waitlaunch, the last thing the agent reads before its closing reply. In the same replay that got the line written 6/6: 3/3 with a user CLAUDE.md, 3/3 with project settings only. It wrote none (0/6) on a turn where nothing was owed.hooks/hooks.json: aPostToolUseBash entry with"if": "Bash(*leaf wait*)", which printshooks/wait-started.jsononly whenCLAUDECODEis set and the payload namesleaf wait. Codex 0.156.1 runs the same file, ignoresif, and fires the entry on every shell call, as I measured, so the command checks both itself rather than relying on the filter.host-claude-code.md: "Session list" keeps the mechanism (the row reads Working whileleaf waitruns) and points at the hook file, so the rule has one home.TODO.md: when to route tool-result guidance throughleaf hookinstead of static text, and the case for makingleaf hookcheap enough to use that way. It costs about 0.3–0.5s warm and 2.5s cold today, and the host waits on it.shwith a hook payload and checks that it prints the guidance under Claude Code and nothing otherwise.🤖 Generated with Claude Code