Skip to content

Leave a change to the skill under a running session to the harness, and say when Claude Code renews Leaf's hooks module - #7221

Merged
max-sixty merged 18 commits into
mainfrom
route-installed-copy-in-launcher
Nov 26, 2026
Merged

max-sixty merged 18 commits into
mainfrom
route-installed-copy-in-launcher

Conversation

@max-sixty

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

Copy link
Copy Markdown
Owner

Leaf no longer tells the agent to read the leaf skill again when the skill its session's hooks ship changes; the skill text the agent read is the harness's to keep or renew, as Claude Code's /reload-skills does. The notice fired on nearly every update a session picked up (444 of main's 2,093 commits in the last 30 days touched skills/leaf), and it needed a change for each way a copy of Leaf changes: Codex's and Pi's in-place updates, then a checkout loaded with --plugin-dir. Each hook now records only the root of the Leaf it runs (leases.mark_root, sessions/<digest>.root), which state.hooks_root still reads, and no longer hashes the skill's files on every call. The notice after a compaction stays.

It also corrects three texts (the carrier.py header, How it works' carrier paragraph, cmd_pages) that said Claude Code keeps the hooks module until /reload-plugins. A probe plugin loaded with --plugin-dir in an interactive 2.1.332 session showed that a save to the module file renews the instance within seconds and kills the children it spawned, while a save to any other file renews nothing, even through /reload-plugins --force. A module can't import JSON, so Claude Code can't see Leaf's Python or kernel registry move, which is why the follower's restart on a protocol move (_moved_on, from #5796) stays.

Worth weighing: the record's file is renamed from .skill to .root, so across the one update that ships this, a page server from the older copy won't follow to the newer one; both speak the same protocol.

The maintainer asked whether Leaf supports --plugin-dir well, then proposed dropping the skill notice. The hooks, forks, server-lifetime, session-lifecycle and hook-registration model tests pass.

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

… any Python

A session keeps the plugin copy it loaded, and Claude Code installs a new copy
for each commit the marketplace sweep picks up: 212 copies sat in the cache on
2026-11-19, about 30 a day. Every hook and bare command in an older session
started the old copy's uv and Python only to find, in `installed_launcher`, that
another copy delivers, and exec it. That hop cost about 100 ms per call
(`leaf --version`: 210-230 ms through an old copy, 110-130 ms direct), needed the
old copy's files to still be there (#6567 added a shell copy of the rule for a
copy that had lost them), and decided by where the running package was loaded
from, which is how a launcher importing another tree's `leaf` looped until uv's
recursion limit.

Claude Code marks each copy it replaces with `.orphaned_at` (211 of the 212; the
installed copy alone has none), so `bin/leaf` now checks for that marker first
and execs the launcher `installed_plugins.json` records, compared by path, or
refuses where none other is recorded. That is #6567's block applied to every
replaced copy rather than only to one that lost `pyproject.toml`. A replaced
copy never starts uv, so it no longer builds an environment, and the hop now
costs about 20 ms (`leaf --version`: 102-113 ms through the replaced copy, 76-104
ms direct, in a fake cache of two copies of this tree). Version managers that redirect (rustup, Volta, mise) make
the same choice: decide by path before the program starts.

`installed_launcher` goes, and `delivering_launcher` is the selected checkout
or this Leaf. The follower moves on once its own copy is replaced
(`session_runtime.replaced`), which the module answers by starting it from its
launcher, which runs the installed copy or refuses, so a follower can't
restart in a loop. The stubs #6567 gave tests that copy the launcher alone go.

The replaced-copy test fails on main's launcher, where a whole replaced copy
runs its own project.
… only gating the read

Claude Code's cache sweep (2.1.329) reads `installed_plugins.json`, removes
`.orphaned_at` from every copy it records and marks every copy it doesn't, so
the marker is a lagging copy of the record. A marked copy the record still
names, as a version folder installed again until the next sweep, refused every
call with advice a reload couldn't follow. Now the record decides: a marked copy
runs the first absolute, executable launcher it names unless that is its own,
and otherwise runs itself, so the refusal goes. `session_runtime.replaced`
follows the same rule for the pages follower, and the launcher test holds the
two to the same answer in each case, since a follower that moved on where the
launcher runs its own copy would be started again and again. That test fails on
main's launcher, on one that skips its own copy rather than stopping there, and
on a `replaced` that reads the marker alone.

The bin/leaf comment no longer says the session keeps working once the old
copy's files go: the hooks module, the Stop watch and `hooks.json` still load
from it.
`replaced` read Claude Code's record by the launcher's rule, a second reader of
`installed_plugins.json` that had to agree with the shell's on every input: where
they differed, as with no jq on PATH, the follower ended and the module started
it again in the same copy, over and over. Now `replaced` is the marker alone, and
the follower moves on only when its copy is marked after it started. One marked
before was run by its launcher anyway, as where the record still names it, so
the follower stays, and whatever the launcher decides, a follower restarts at
most once. The launcher alone reads the record.

The new follower test fails on a `_moved_on` that ignores when the copy was
marked.
…eared

Claude Code's sweep never rewrites a mark that is already there, so a follower
that started in a copy marked while still recorded never saw a later genuine
replacement. The follower now forgets the mark it started with once a pass finds
the copy unmarked, which the sweep does where the record names the copy, and a
mark after that moves it on. The new follower test runs the whole follower
through that sequence and fails on one that ignores the mark at its start or
never lets it clear.
…se where none is recorded

A removal that stops partway can take a copy's root `.orphaned_at`, which sorts
first, and keep its launcher, so the mark alone missed the state #6562 reported:
the project gone, and uv left to run the caller's `python`. A copy in Claude
Code's cache now reads the record when it is marked or has lost its project, and
#6567's refusal comes back for a launcher whose project is gone with no other
copy to run, so uv never runs without a project. `session_runtime.replaced`
takes the same two checks, so the follower moves on when the launcher would
look. Reading the record by parameter expansion rather than `dirname` costs
about 4 ms a launch rather than 21; the two checks keep it off the installed
copy's launches, which measured the same as main's (63-66 ms for
`leaf --version`).

The launcher test now fails on main's launcher, on one that skips its own copy,
and on one that drops either check; the project stubs the hook tests need for
the refusal come back.
… copy installed since

A session's hooks, watch and bare `leaf` commands now run the plugin copy the
session loaded, as Claude Code intends: it puts that copy's `bin/` on the Bash
tool's PATH and names it in each hook. They still hand themselves to a checkout
the session selected. This reverses #4557, which handed every session to the
copy `installed_plugins.json` records, and deletes that hop from the launcher
(`bin/leaf`) and `session_runtime`, with the pages follower's restart on it.

The hop stopped buying what it was added for a day after it landed. #4557 fixed
idle sessions refusing pages a newer Leaf had re-vendored (94% of pickup wait,
20-27 Oct). #4551 then stopped copying the layer into pages, so the protocol
covers only the log and records, and only the session holding a page renews it
(`vendoring.renew_layer`), so a session's pages stay at its own copy's protocol.
Of 36 live sessions on 2026-11-19, 34 ran a replaced copy, and 33 were at the
installed copy's protocol (51) anyway; the protocol moved 15 times in the last
1,318 commits.

The hop also ran code the session's instructions didn't describe: two live
sessions loaded a copy at protocol 44 whose references tell the agent to pass
`--markup` to a thread message, a flag the installed Leaf dropped (#6208). With
it gone, a session's instructions, hooks module and Python are one copy, except
under a selected checkout, and Leaf no longer reads Claude Code's undocumented
install record or cache marks. An update now reaches a running session when it
runs /reload-plugins or starts anew. A copy that has lost its project still
refuses, naming /reload-plugins, rather than leave uv to run the caller's
`python`.
…p to the copy installed since"

This reverts commit f75e61a.
# Conflicts:
#	tests/model/test_forks.py
# Conflicts:
#	bin/leaf
#	src/leaf/hooks.py
#	src/leaf/session-lifetime.md
#	src/leaf/session_runtime.py
#	tests/model/test_forks.py
#	tests/model/test_hook_registration.py
#	tests/process/test_bridge.py
…e Code renews Leaf's hooks module

A hook whose skill differs from the previous hook's now tells the agent to
read the skill again whatever copy ships it, a checkout the session's hooks
run included. Before, a checkout at the same root was exempt, on the guess
that a session running a checkout is the one editing its skill, so a merge
or branch switch that changed the skill under a `--plugin-dir` session went
unnoticed (the gap #6782 named). An edit the session makes to that skill
now draws the notice too.

Three texts said Claude Code keeps the hooks module until `/reload-plugins`.
Measured at 2.1.332 with a probe mod loaded by `--plugin-dir` in an
interactive session: a save to the module file renewed the instance within
seconds (register and session.start ran again, and the child the old
instance spawned was killed); a save to any other file, a SKILL.md or a data
file, renewed nothing, and neither did `/reload-plugins` or
`/reload-plugins --force` after it. A module can't import JSON ("not named
like code and was not loaded"), so Claude Code can't learn that Leaf's
Python or kernel registry moved. The follower's restart on a protocol move
(`_moved_on`, #5796) therefore stays: it is the one part of running a
checkout in place that Claude Code can't do for Leaf.

The skill-notice test now expects the notice for an edited checkout skill.
leaf-agent
leaf-agent previously approved these changes Nov 26, 2026
Leaf no longer tells the agent to read the leaf skill again when the skill
its session's hooks ship changes. The skill text the agent read is the
harness's to keep or renew; Claude Code 2.1.332 has `/reload-skills`
("Pick up skills added or changed on disk during this session").

The maintainer asked how much the notice costs to maintain and proposed
dropping it. It landed on 2026-11-22 (#6757) and has needed a change in
each of #6782 (Codex's and Pi's in-place updates), #7061 and the previous
commit on this branch (a checkout's own skill). Over the last 30 days 444
of main's 2,093 commits touched skills/leaf, so nearly every update a
session picked up made it reread SKILL.md and its references. A command
whose interface changed still reports that through its own error or
`--help`, which is the agent's path for any command it misremembers.

Each hook now records only the root of the Leaf it runs (`leases.mark_root`,
`sessions/<digest>.root`), which `state.hooks_root` reads for a checkout's
right to act for the session and for a server's follow to another copy. The
hook no longer hashes the skill's 33 files on every call. The record's file
is renamed from `.skill` to `.root`. An older Leaf at this protocol reads only
`.skill`, so across the one update that ships this commit a page server from
the older copy doesn't see the newer copy's root and stays where it is, which
two versions of Leaf at one protocol may. The clerk queue's schema description drops the
notice, an annotation the protocol baseline carries without a bump.

The notice after a compaction (`hooks.reload_skill`) stays: it covers the
text a compaction dropped, not a skill that changed.
@max-sixty max-sixty changed the title Send the agent back to a checkout's changed skill, and say when Claude Code renews Leaf's hooks module Leave a change to the skill under a running session to the harness, and say when Claude Code renews Leaf's hooks module Nov 26, 2026
@max-sixty
max-sixty merged commit c7af362 into main Nov 26, 2026
6 checks passed
@max-sixty
max-sixty deleted the route-installed-copy-in-launcher branch November 26, 2026 05:51
leaf-agent added a commit that referenced this pull request Nov 26, 2026
… name or a gone reason

- `visual-mark-paint.js` said `data-lf-mark` is drawn in `surfaces.css`;
  its rules are in `element-marks.css`.
- `idioms.css`, `sample.css` and `tabs.css` said `.lf-label` is in
  `base.css`; it is in `elements.css`.
- `schema.py` and the Worker's `storage.py` named `reading.UNWATCHED`; the
  constant is `page_inputs.UNWATCHED`.
- `reading.css` cited "A rule for focus anywhere in a box" as a section of
  `browser/AGENTS.md`; it is a sentence under "What a style rule costs".
- `layer.py` imported `layer_metadata_of` inside `layer_vocabulary` so that
  a hook hashing the skill would skip it. Hooks no longer hash the skill
  (#7221), and the import makes no cycle at the top (import-linter keeps
  both contracts), so it moves there.
- `how-it-works` said browser drafts live outside the page directory; they
  travel with it (`schema.PAGE_STATE_FILES` holds `drafts.json`), as the
  figure caption below that paragraph says.
- `page_code.py`'s header kept an eval's counts; it keeps the reason.

No behavior changes.
leaf-agent added a commit that referenced this pull request Nov 26, 2026
… name or a gone reason (#7247)

Eight comments and one sentence on the how-it-works page pointed a
reader at the wrong place, or kept a reason that no longer holds. This
corrects them. No behavior changes, apart from one import moving to its
module's top.

- `visual-mark-paint.js` said `data-lf-mark` is drawn in `surfaces.css`.
Its rules are in `element-marks.css`.
- `idioms.css`, `sample.css` and `tabs.css` said `.lf-label` is in
`base.css`. It is in `elements.css`.
- `schema.py` and the Worker's `storage.py` named `reading.UNWATCHED`.
The constant is `page_inputs.UNWATCHED`.
- `reading.css` cited "A rule for focus anywhere in a box" as a section
of `browser/AGENTS.md`. That phrase is a sentence under "What a style
rule costs".
- `layer.py` imported `layer_metadata_of` inside `layer_vocabulary`, so
that a hook that only hashes the skill would skip it. Hooks stopped
hashing the skill in #7221. The import makes no cycle at the module's
top, so it moves there.
- `docs/how-it-works.html` said browser drafts live outside the page
directory. They travel with it, since `schema.PAGE_STATE_FILES` holds
`drafts.json`, and the figure caption below that paragraph already says
so. The sentence now says only session ownership lives elsewhere, in the
state home.

Verified with `lint-imports` (both contracts kept), `ruff`, and
`tests/model/test_product_page.py`. The nightly survey and the review of
recent commits found these.

---------

Co-authored-by: leaf-agent <[email protected]>
Co-authored-by: Claude <[email protected]>
Co-authored-by: leaf-agent <[email protected]>
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