Repository navigation
Description
Unless managed settings set prependPlugins, Claude Code's built-in security-default plugin, cc-plugin-sec-default, seats itself outermost on any machine with managed settings and for Team and Enterprise organizations. It answers every classic.* event with next.to(e, "append"), so the hooks modules of plugins a person installs never see a classic event. Leaf's on("classic.Stop") therefore never runs. In Claude Code 2.1.304 each session shows this notice when its first turn ends:
leaf: its classic.Stop hook was skipped. "cc-plugin-sec-default" runs first and sent the event on past it.
Builds from 2.1.286, the first to load installed plugins' hooks modules by default, skip the hook. They did so silently until 2.1.303 added a note on the /plugin screen, and 2.1.304 added the notice.
This is by design. Claude Code's /plugin note for Leaf says that where an organization manages Claude Code, these events pass over the plugins a person installs, and that only a plugin counting as the organization's own runs hooks on them. User-settings prependPlugins is ignored on a machine with managed settings.
What still runs
Only the module's classic.Stop link is skipped. Leaf's hooks.json Stop command still runs, because Claude Code runs plugins' hooks.json commands and the non-managed settings hooks in its innermost link, below the tier the security-default plugin jumps to. The module's other hooks (session.start, tool.call, turn.start, turn.complete, ui.render, session.end) are on events the security-default plugin doesn't hook, so they run as before.
Effect on Leaf
The classic.Stop hook only observes. It sets stopping and running so that turnGoesOn() can hold a watch's wake until the Stop hooks decide. With the hook skipped, stopping is never set, and running stays true from turn.start to turn.complete. A wake that arrives while the Stop hooks run is turned away instead of held.
The watch that turn.complete starts then finds the input and wakes the session, since the Stop command has closed the turn. The input arrives one watch startup later, or up to STOP_HOOK_S (20 s) later when the Stop command did not close the turn. If a subagent or teammate turn starts before that watch wakes, the wake is turned away too, and the input waits for the next main-loop turn. No input is lost. In a session holding no page, the notice is the only effect.
test_a_wake_during_the_stop_hooks_waits_for_them still passes, because the test driver chains the module's hooks with no tiers. No test seats a link above the module that skips it, as the security-default plugin does.
Expected
Leaf's module behaves the same whether or not the security-default plugin is seated, and Claude Code shows no notice for it.
A possible fix
Drop on("classic.Stop"), stopping and the wait in turnGoesOn(), and let wake read running alone. Claude Code raises turn.complete only after the Stop hooks let the turn end. A Stop result that continues the turn, by blocking or by adding context, loops inside the same turn and raises no new turn.start. The security-default plugin doesn't hook turn.*, so Leaf's turn.start and turn.complete hooks run wherever it is seated.
turn.start also needs to follow the main loop alone. It sets running for subagent and teammate turns too, while turn.complete clears it only on the main loop. So a subagent or teammate turn that starts after the main turn completes leaves running true while the session is idle, and every wake is turned away until the next main-loop turn ends. That already happens to wakes after turn.complete. Without the Stop hook it also catches the wake that delivers input arriving during the Stop hooks. Returning next(e) first when e.agentId !== undefined, as the plugin API's TurnStartInput documentation advises, closes it.
The fix also needs:
- the docstring's sentence on a wake while Stop hooks run to say such a wake leaves its input to the watch the turn's completion starts, and the comment on
runningto say it ends atturn.complete; test_a_wake_during_the_stop_hooks_waits_for_themrewritten or deleted, sincetest_input_pending_as_a_turn_ends_wakes_a_turn_of_its_ownalready covers the path the wake then takes;- a test that emits
turn.startwith anagentIdafterturn.completeand expects the wake to submit.
The cost is that every session, seated or not, then delivers input that arrives during the Stop hooks one watch startup later, as seated sessions do now. The fix also removes the notice and the /plugin note, since Leaf would hook no event the security-default plugin passes over.
Repro
- Run Claude Code 2.1.304 on a machine whose managed-settings file is non-empty and sets no
prependPlugins. - Install Leaf, start an interactive session, and let one turn end.
- The notice above appears once. With
--debug, the log says the security-default plugin was seated outermost because the machine has managed settings, and that Leaf'sclassic.Stoplink was bypassed by it.
Adding "prependPlugins": [] to the managed settings unseats the security-default plugin, and the hook then runs. That setting belongs to whoever manages the machine, so Leaf can't rely on it.
Seen on leaf a7e5fe6.
This was written by Claude Code on behalf of max-sixty
Activity
fix: keep Claude Code wake tracking on main turns (#3511)
leaf-agent commentedon Oct 21, 2026
#3511 merged the fix. Leaf's module no longer registers the bypassed
classic.Stoplink, and a subagent turn can no longer mark the idle main loop as running. The regression failed before the change and passed after it; the PR's CI passed on its exact head. The live Claude Code journey could not start a session in this runner, so that path remains unverified here.