Skip to content

Show the session's Leaf pages above Claude Code's prompt, and make the hooks module its only watcher - #3399

Merged
max-sixty merged 9 commits into
mainfrom
cc-mod
Oct 21, 2026
Merged

max-sixty merged 9 commits into
mainfrom
cc-mod

Conversation

@max-sixty

Copy link
Copy Markdown
Owner

Leaf's Claude Code hooks module now shows the session's pages above the prompt and is the session's only watcher between turns. Claude Code 2.1.305 loads an installed plugin's hooks module with nothing turned on, so the opt-in and the background Stop hook it stood in for are gone.

The band

Each live page the session holds gets a line above the prompt: a link to the page, its On me count, and its open threads with how many hold replies the user hasn't read, e.g. Leaf Band demo · On me 1 · Threads 3, 1 new. It draws above whatever other plugins draw in that slot rather than replacing it. Checked in a real Claude Code 2.1.305 session, alone and beside a second plugin's band.

  • Counts: each serving page's row (server_rows.py) carries on_user and threads: {open, unread}, computed from the active view's browser projection in the row's own transaction. The row's format moves to protocol 16. The panel and the row count threads by one rule (threadCounts in runtime/thread/model.js, thread_counts in served_state/thread.py), which tests/thread_count_cases.json holds both runtimes to; that fixed a drift where a bare reaction counted as an open thread on the row only.
  • Follower: leaf hook --harness claude-code --if-claimed --pages prints the session's pages as JSON each time they change, woken by rows/ and the session's claim locators, and exits once the session holds no page. It checks only the session's own pages' server leases (presence.live_leaves(among=...)).
  • Module: hooks/claude-code.ts starts the follower as the session starts, as a turn starts or ends, and after a Bash call that runs leaf, and draws the band from its last list.

The module is the only watcher

  • The plugin's hooks_module option, hooks.json's background asyncRewake Stop registration, hooks/scripts/background-watch.py, the leaf_watch stand-down mark, and leaf-dev journey --hooks-module are deleted.
  • The module reads Claude Code's process on whichever hook comes first, so a module loaded mid-session still watches.
  • Behavior change: a Claude Code that loads no hooks module keeps no watch between turns; its input arrives through admission's nudge, as after an Escape. The nudge stays.
  • The shipped Claude Code reference, session-lifetime.md, the harness declarations, the README and the site's integration notes describe the module's watch.

Build

Every build script calls esbuild through build/esbuild.mjs, which ignores any tsconfig.json in the tree. Claude Code writes one at the plugin root when it loads a checkout with --plugin-dir, and its alwaysStrict was adding "use strict" to the widget bundles.

Left as they are

  • The row producer now runs the browser projection on each refresh (about 1 ms on top of the fold, measured); a fault there ends the serving process as a fold fault already does.
  • A leaf command run with run_in_background claims after its tool call returns, so its page joins the band at the turn's end.
  • The follower is a second long-lived process beside the watch for a session holding a page; folding the two into one session-level process would retire the follower's restart logic.

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

max-sixty and others added 8 commits October 20, 2026 16:20
Leaf's Claude Code hooks module now draws a band above the prompt with one
line per live page the session holds: a link to the page, its On me count,
and its open threads with how many hold replies the user hasn't read, the
counts the page's own Leaf panel marks. The band draws whatever the
`hooks_module` option says; the option still decides only who keeps the
watch between turns.

- Each serving page's row (`server_rows`) carries the user's counts
  (`on_user`, `threads.open`, `threads.unread`), read from the active
  view's browser projection in the same transaction as its activity. The
  row's format moves to protocol 15, so rows from older servers read as
  absent until those servers restart.
- `presence.live_leaves` is the one reading of live rows; `other_leaves`
  and the new `session_leaves` filter it.
- `leaf hook --harness claude-code --if-claimed --pages` prints the
  session's pages as JSON each time they change, woken by rows/ and the
  session's claim locators, and exits once the session holds no page. The
  launcher's claim gate answers it without uv in a session holding none.
- The module starts that follower as the session starts, after a Bash call
  that runs `leaf`, and as a main-loop turn ends.

Behavior change: with `hooks_module` off the module now hooks session
start and end, Bash calls, turn completion and the band; it still keeps no
watch. The test driver streams a child's output as it arrives and draws
the band on each redraw the module asks for.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
- The module clears the band as a session ends, and starts the follower as
  each turn starts too, since a cleared or resumed session raises no
  session.start.
- A follower request while one runs starts another once it exits, so a
  page claimed just as the last one is released still shows.
- The Bash hook matches a command that runs `leaf` in its registration, as
  hooks.json's PreToolUse globs do, rather than any command naming the
  word, which nearly every command in this repository does.
- `turn.complete` clears `running` before it awaits the session id, so a
  wake in that gap is not dropped.
- The follower prints only the fields the band draws, so an activity
  change alone no longer redraws it, and reads the claims before the rows.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
The AbovePrompt band is one slot every plugin shares. Leaf's hook now
passes the band on first and puts its page lines above whatever the
plugins beneath it drew, so a page the session holds no longer hides
another plugin's band. Checked in Claude Code 2.1.305 beside a second
plugin drawing its own line, and alone, where it adds no empty row.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
esbuild reads the nearest tsconfig.json above each source, so an
untracked one changed committed bytes: the tsconfig.json Claude Code
writes at the root of a plugin it loads with --plugin-dir sets
alwaysStrict, which added "use strict" to each widget's IIFE bundle and
failed check:browser. Every build script now calls esbuild through
build/esbuild.mjs, which passes an empty tsconfigRaw. check:browser
passes with such a file at the root.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
The panel's Threads mark counts the threads it lists, which leave out a
bare reaction, while the served row counted every thread, so a page with
a reaction alone showed an open thread in Claude Code's band and none in
the panel. Both now count through one named rule, `threadCounts` in the
runtime's thread/model.js and `thread_counts` beside `browser_thread`,
and tests/thread_count_cases.json holds the two to the same cases, as the
rank cases hold the board order. The panel's New filter and row word use
the same `hasUnread` predicate its count does.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
Claude Code 2.1.305 loads an installed plugin's hooks module with nothing
turned on (its debug log: `hooks module leaf@leaf loaded ... tier user`),
which is the trigger the module's TODO named. So the module now keeps the
watch between turns in every session, and the opt-in goes:

- The plugin's `hooks_module` option is gone, and the module hooks the
  session's start, turns, Stop hooks and end unconditionally.
- `hooks.json`'s background `asyncRewake` Stop registration and its
  supervisor, `hooks/scripts/background-watch.py`, are deleted, with the
  `leaf_watch: "module"` mark that stood it down. The synchronous prompt,
  tool-batch, Stop, SessionStart and SessionEnd registrations stay: they
  carry and confirm input, and the module only watches and wakes.
- `leaf-dev journey claude-code` loses `--hooks-module`; every run is the
  module's, and the chart no longer names it.

Behavior change: a Claude Code that loads no hooks module now keeps no watch
between turns; input to its pages reaches it through admission's nudge, as
after an Escape. The nudge stays, since Claude Code still drops a plugin's
prompt after an Escape (WakeRefused) and a session may load no module.

The shipped Claude Code reference, the session-lifetime contract, the
harness declaration, the README and the tests that described the
background registration now describe the module's watch; the tests of the
supervisor and of the stand-down are deleted with them.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
… watch's prose

From /code-review of the branch:

- The module read Claude Code's process only at session.start, so a module
  loaded or reloaded mid-session started every watch without it and never
  watched. Whichever hook comes first now reads it (`sessionOf`).
- The pages follower checks the server lease of the session's own pages only,
  rather than every live page on the machine, and reads the session's claims
  once per look.
- Prose that still described the background Stop hook watch now describes the
  module's: the site's Claude Code integration, /developing-leaf's journey
  advice, the harness declarations, session-lifetime.md, and two comments.
- The README and the shipped Claude Code reference no longer say nothing
  watches after Escape: the module watches, and Claude Code refuses its wake
  until the user types, so Leaf messages the session instead.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
The row record moves its format to protocol 16, which main bumped to; the
kernel and the protocol baseline are rebuilt on the merged tree.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
leaf-agent
leaf-agent previously approved these changes Oct 21, 2026
Takes main's removal of the comparisons note's host-integration paragraph and
rebuilds the kernel on the merged tree.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
@max-sixty
max-sixty merged commit a69bf53 into main Oct 21, 2026
3 checks passed
@max-sixty
max-sixty deleted the cc-mod branch October 21, 2026 00:36
max-sixty added a commit that referenced this pull request Oct 22, 2026
…the hooks module's watch opt-in (#3512)

Claude Code's watch between turns goes back to the background
`asyncRewake` Stop hook, and the hooks module's watch becomes opt-in
again behind the plugin's `hooks_module` option. The band above the
prompt stays on in both cases.

Since #3399 the module has been the only watcher. It wakes an idle
session with `$.prompt.submit`, which Claude Code draws as a full
user-styled prompt: "The leaf plugin sent a message: Leaf: <page path>
has new input…" followed by the engine's paragraph on plugin prompts.
The background hook's wake draws as one dim "Stop hook feedback" row. A
survey of transcripts since 2026-10-13 also found two kinds of visible
rows that only the module produces. One is a queued wake that fires as
an empty turn after the user's own prompt has already taken the input (2
of 4 module wakes). The other is a pair of `leaf: Leaf: … exit code 143`
notices when the session's children are terminated while it is idle.

- `hooks/hooks.json` gets the background Stop registration back, and
`hooks/scripts/background-watch.py` gets its supervisor back. The
supervisor stands down when `CLAUDE_PLUGIN_OPTION_HOOKS_MODULE` is
`true`, which Claude Code exports to each of the plugin's hooks. This
replaces the `leaf_watch` payload mark, which relied on the module's
`classic.Stop` link, a link #3511 found is bypassed in managed sessions.
- `hooks/claude-code.ts` starts watches only while
`options.hooks_module` is on, and draws the band either way.
- `leaf-dev journey claude-code --hooks-module` is back, so both
watchers run the same journey. On Claude Code 2.1.307 both pass every
step. The default run shows 8 "Stop hook feedback" rows and 1
cross-session nudge. The module run shows 2 plugin prompts and 3 nudges,
and its debug log shows no asyncRewake wake, which confirms the
background hook stood down.
- The shipped Claude Code reference, `session-lifetime.md`, the harness
declarations, the README and the site's integration notes describe the
background watch as the default again.

Comparing the two watchers properly, and cutting what the module shows,
comes in a follow-up.

> _This was written by Claude Code on behalf of max-sixty_
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