Repository navigation
Have the Claude Code hooks module run the forks and completions Leaf's Python lists - #6438
Merged
Merged
Conversation
…ering Leaf The pages follower no longer checks that the Claude Code hooks module a session loaded is byte-for-byte the delivering Leaf's `hooks/claude-code.ts`. A follower whose module asks for forks now takes the session's forks lane and keeps thread messages back for line forks, whichever copy of the module loaded. Where the module's exchange with Leaf's Python has changed, the Python refuses the `leaf hook --fork` step, which hands the thread to the session at once, or at worst the line turn lapses after `activity.STARTING_GRACE` (30 s), and the message reaches the session as it would without forks. The gate guarded one of the six crossings between the module and Leaf's Python; the clerk, completions, beside and summary forks, and agent ends already ran without it. On real pages from 14 to 18 November, 203 of 346 thread messages (59%) were not kept back, every one because of the gate: the module changed 24 times in 13 days (5 to 17 November), so most sessions had loaded a module that no longer matched. Root `AGENTS.md`, "Stage", spends no code on compatibility with earlier runtimes, and that is what the gate was. Removed: `session_runtime.module_current`; the module's `loadedDigest`, `digestOf` and the follower payload's `module` field, so the module no longer reads its own source through `$.fs`; the test driver's `$.fs` stand-in; and the `module` and `current` fields of the follower's `follower` note, which now records only whether the module asked for forks. `leaf-dev logs timeline` no longer names a stale module as a reason a message found no fork lane. Tests: deleted `test_a_follower_for_another_copies_module_keeps_nothing_back`, which protected the gate's behavior that a follower under another copy's module keeps nothing back; the follower fixtures drop the module digest. > _This was written by Claude Code on behalf of max-sixty_
…s Python lists
The hooks module now carries instructions rather than running each kind of fork's steps itself. Leaf's Python lists `{id, do, request, basis}` instructions (`report`, `fork`, `complete`, `spawn`, `send`) in the pages follower's listing and in its answer to each report. The module passes each `request` as it stands to the Claude Code call `do` names, runs each id once, and reports what it came to through `leaf hook --fork`; `carrier.step` hands the result to the turn-end check, a thread's forks or a completion by the basis's `kind`. The module keeps only what it alone sees: the tool calls the main thread is running, sent with every report; the main thread's last request, sent with a fork's result as `resent`; a main-loop turn's end (`turn_end`); and each spawned fork's run ending, kept in `$.state` across reloads as before. `src/leaf/carrier.py`'s header holds the contract.
Claude Code keeps the module it loaded until `/reload-plugins`, while each hook runs the newest Leaf, so most sessions run a module older than their Python. Of the 24 commits to `hooks/claude-code.ts` from 5 to 18 November, 7 changed what it exchanged with the Python; by a reading of their diffs, a carrier's exchange would have changed for 3 of them, each adding a call: the follower starting again under a newer Leaf, completions, and working forks. The fork's effort, which the module set and Leaf changed three times in ten days, is now a field of the Python's request (`carrier.fork`). Max chose this on the forks review page on 18 November, over keeping each fork's steps in the module. A new kind of fork, or a change to what Leaf asks of a call or does with an answer, now changes only the Python, and an instruction an older module doesn't know comes back failed at once.
Behavior that changed:
- `LEAF_FORK_REPLIES` and `LEAF_FORK_WORK` are read by the Python (`forks.replies_on`, `forks.work_on`), which inherits Claude Code's environment through the module's processes, so the follower's payload no longer carries `forks`, the module reads only `SSH_CONNECTION`, and `isolated_session` clears both for the suite.
- Every failed report step is reported once more as `failed`, for every kind. For a completion that writes a failed reply at once rather than leaving its page server to its deadline; for the turn-end check it adds a note.
- An answer the turn-end check refuses no longer fails the step: `clerk.checked` returns `refused` with a log line, which `fork_eval` reads in place of the exit code.
- The follower lists kept-back threads for every page it holds, where it nested them under the live pages it drew.
- `completions.cmd_reply` is `completions.replied`, taking the module's report, and the suite's module stand-in reports through `carrier.step`.
A new test holds the contract's central guarantee: an instruction the module doesn't run comes back failed at once.
leaf-agent
previously approved these changes
Nov 18, 2026
Main removed both fork flags (#6463), so the carrier's Python no longer reads LEAF_FORK_REPLIES or LEAF_FORK_WORK: forks.replies_on, forks.work_on and the tests' clearing of them go, and a line fork's take always spawns or resumes a working fork.
leaf-agent
previously approved these changes
Nov 19, 2026
leaf-agent
left a comment
Collaborator
There was a problem hiding this comment.
The description becomes main's commit message, and since the merge of #6463 its first "Worth weighing" bullet no longer holds: nothing in the tree reads LEAF_FORK_REPLIES or LEAF_FORK_WORK now, so the Python doesn't take them over from the module. Dropping that bullet, and the --forks / --fork-work flags in the Checks line, which leaf-dev journey run no longer has, would keep the message accurate.
# Conflicts: # hooks/claude-code.ts
leaf-agent
approved these changes
Nov 19, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Leaf's Claude Code hooks module now only runs the model calls and agents Leaf's Python lists, and reports what each came to. The Python lists instructions (
report,fork,complete,spawn,send), each with therequestthe module passes as it stands to the matching Claude Code call, in the pages follower's listing and in its answer to each report.src/leaf/carrier.py's header holds the contract. The module keeps the band, the follower's lifecycle and what only it sees: the main thread's running tool calls, its last request, a main-loop turn's end, and each spawned fork's run ending.Claude Code keeps the module it loaded until
/reload-plugins, so most sessions run a module older than their Python. With this, a new kind of fork, or a change to a fork's prompt, effort or outcome, changes only the Python, and an instruction an older module doesn't know comes back failed at once. Max chose this on the forks review page.Worth weighing:
takealways spawns or resumes a working fork.failedfor every kind, so a completion fails at once rather than at its page server's deadline.the pages follower failedin its conversation and draws no band until/reload-plugins.Checks: the focused fork, clerk, hooks, thread-title, LLM, hook-gate, module and timeline tests, with a new one for an unknown instruction;
pnpm run check:hooks; andleaf-dev journey run claude-codeon the branch merged with main, which passed all 16 steps, its working forks' lines coming 2.2 s and 2.8 s after the message.