Skip to content

Tell the agent to read the leaf skill again once its session's hooks run another copy of Leaf - #6757

Merged
max-sixty merged 2 commits into
mainfrom
tell-agent-when-leaf-copy-changes
Nov 22, 2026
Merged

max-sixty merged 2 commits into
mainfrom
tell-agent-when-leaf-copy-changes

Conversation

@max-sixty

Copy link
Copy Markdown
Owner

When a session's Leaf hooks start running another copy of Leaf, and that copy's skills/leaf/ differs from the one before, the next prompt or tool boundary tells the agent to read the new copy's SKILL.md again.

A background job's wake or a resume starts a new process, which loads whichever copy Claude Code has installed, and a checkout selection moves a session's hooks to that checkout. The transcript carries over in both cases, so the agent kept following the skill text it had read under the old copy, with nothing telling it the commands and rules may have changed.

Each hook records the plugin root it ran from in a session file of its own (leases.mark_root). That file outlives the process while a claim names the session, unlike the hooks mark (removed at SessionEnd) and the lifecycle record (replaced on resume). The first hook under another root compares the two skill trees and queues the notice on the clerk queue. The prompt or tool-boundary hook then prints it beside any delivery, in a session holding a page. An unchanged root costs each hook one small read.

Worth weighing: a session that holds no page keeps the notice queued until it next holds one. Two root changes before a printing hook, or a compaction at the same moment, give two notices.

The maintainer asked for this on the Leaf page about keeping a session on one version of Leaf (open item #11). Tests: tests/model/test_hooks.py::test_a_hook_from_another_copy_sends_the_agent_back_to_the_skill, plus the focused hook, clerk, lifecycle, registration, fork and claim suites (214 passed).

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

…run another copy of Leaf

Claude Code loads a plugin's files from a copy in its cache as a process
starts, as on a resume or a background job's wake, and at /reload-plugins,
and a session can hand its delivery to another Leaf (session_runtime). The
transcript carries over, so the agent keeps following the skill and
references it read under the old copy while its hooks and leaf commands run
the new one. Nothing told it.

Each hook now records the plugin root it ran from (leases.mark_root). The
first hook under another root compares the two copies' skills/leaf/ byte for
byte and, where they differ or the old copy is gone, queues a notice naming
the new copy's SKILL.md (hooks.copy_changed) on the queue the clerk and
summary forks already use. The next prompt or tool boundary carries it beside
the input it hands over, in a session holding a page, and takes it off the
queue.

The root has a session file of its own rather than living in the hooks mark
or the lifecycle record. SessionEnd removes the hooks mark, and a new
generation replaces the lifecycle record, so either would forget the old root
across the resume or wake this notice is for; a hook's write to the
lifecycle record would also change the snapshot its own readings compare
against. The new file stays while a claim names the session, as the
lifecycle does. Whether the session holds a page is asked by the hook that
prints the notice, since a resumed session's claims stay inactive until its
first prompt serves its pages again, after the hook that marked the root.

An unchanged root costs each hook one small read.

@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.

On current main the hooks still hand themselves to the copy Claude Code installed since (session_runtime.installed_launcher). So until #6758 lands, a live session holding a page also gets this notice whenever that installed copy moves to a commit that touched skills/leaf/, which is most commits (156 of 805 on main over the last two weeks). The PR body names only wakes, resumes and checkout selections as triggers; with #6758 merged, those are the only ones left. Landing the two together, or #6758 first, keeps the notice to the cases the description names.

@max-sixty
max-sixty merged commit 73e1695 into main Nov 22, 2026
5 checks passed
@max-sixty
max-sixty deleted the tell-agent-when-leaf-copy-changes branch November 22, 2026 20:41
max-sixty added a commit that referenced this pull request 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.
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