Skip to content

Have the Claude Code hooks module run the forks and completions Leaf's Python lists - #6438

Merged
max-sixty merged 5 commits into
mainfrom
fork-retro
Nov 19, 2026
Merged

max-sixty merged 5 commits into
mainfrom
fork-retro

Conversation

@max-sixty

@max-sixty max-sixty commented Nov 18, 2026 •

Copy link
Copy Markdown
Owner

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 the request the 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:

  • Line forks and working forks always run, as on main since Remove the fork flags, so line and working forks run in every Claude Code session #6463, so a line fork's take always spawns or resumes a working fork.
  • A failed report is reported once more as failed for every kind, so a completion fails at once rather than at its page server's deadline.
  • A session whose module predates this change can't read the new listing: it logs the pages follower failed in 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; and leaf-dev journey run claude-code on 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.

This was written by Claude Code on behalf of max-sixty

…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
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
leaf-agent previously approved these changes Nov 19, 2026

@leaf-agent leaf-agent left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@max-sixty
max-sixty merged commit 3c89bec into main Nov 19, 2026
5 checks passed
@max-sixty
max-sixty deleted the fork-retro branch November 19, 2026 03:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants