Skip to content

refactor(launcher): scope SessionStart provision pre-warm to the startup matcher - #5

Merged
zaynram merged 2 commits into
mainfrom
refactor/provision-hook-startup-matcher
Jun 7, 2026
Merged

zaynram merged 2 commits into
mainfrom
refactor/provision-hook-startup-matcher

Conversation

@zaynram

@zaynram zaynram commented Jun 6, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

Scope the SessionStart provisioning pre-warm hook to the startup matcher
(matcher: "startup"), in both the committed source-sync manifest and the
generated per-OS bundle manifests.

Provisioning the pinned bun into CLAUDE_PLUGIN_DATA is a first-session
concern. There's no point re-firing the pre-warm on resume/clear/compact —
the bun already exists by then. Narrowing the matcher avoids that wasted work.

This is a follow-up to the launcher unification (PR #4, merged). It targets
main.

Why startup, and why not Setup

The instinct "this is setup, not per-session, so use the Setup event" is
wrong here. Per the Claude Code hooks reference:

  • Setup fires only on explicit claude --init-only / -p --init | --maintenance ("one-time preparation in CI or scripts") — never on plugin
    install or normal startup. Moving the pre-warm there would skip it for ordinary
    users, so the first scholar tool call would pay the full cold bun download +
    (on the source-sync path) the ~67 MB import-graph auto-install — the cold-start
    latency already seen in the field.
  • SessionStart / startup fires on a new session — exactly the
    first-session case we want.

The plugins reference prescribes the SessionStart-into-CLAUDE_PLUGIN_DATA
mechanism (install a dependency once, reuse across sessions and updates), but
its example is unscoped, guarding idempotency with an in-hook diff. The
startup narrowing is scholar's own decision, not a doc prescription, and is
safe because:

  • ensure-bun is already idempotent + flock-guarded (scholar's guard-equivalent
    to the docs' diff), and
  • launch.mjs (no flag) is the real correctness gate — it provisions
    synchronously before spawning the server, hook or not. The SessionStart hook is
    a latency-only pre-warm (SessionStart does not block MCP spawn).

So even on a CLAUDE_PLUGIN_DATA wipe or a bundledBunVersion bump — where a
resume session would otherwise skip re-provisioning — correctness still holds:
the launcher re-provisions on the next spawn regardless.

Changes

  • .claude-plugin/plugin.json (committed source-sync manifest): matcher added.
  • scripts/build-plugin.ts buildManifest(): matcher added to the generated
    per-OS manifests + rationale comment. buildMcpbManifest emits no SessionStart
    hook (Claude Desktop schema), so it is unaffected.
  • tests/manifests.test.ts + tests/build-plugin.test.ts: assert
    matcher: "startup" (committed manifest + linux/win32 generated manifests).
  • docs/.../2026-06-01-slim-plugin-pivot.md: hook-scope description updated.

Verification (and its boundary)

  • Full suite 386 pass / 0 fail (391 incl. 4 skip / 1 todo); tsc --noEmit
    clean.
  • The startup matcher value is confirmed against the Claude Code hooks
    reference (startup/resume/clear/compact) and corroborated by the exact
    trigger descriptions in that table.

Boundary: the green checks prove the emitted JSON carries matcher:"startup"
and that both bundles build — they do not exercise a live plugin install, so
they don't prove Claude Code honors the matcher on a plugin SessionStart hook at
load time. Low risk (it's a documented field), but that leg is unproven here.

Doc-hygiene follow-up (resolved — second commit)

The first surfacing of this PR flagged retired launch.{sh,cmd} references in the
docs. On full review, every such reference already carries an adjacent
supersede banner (repo convention: keep the dated record + add a banner) — so
nothing was unguarded. The one residual failure mode is the grep/scroll-lander:
two lines state the retired shell-pair launcher as the current mechanism when
read without the banner in view. The second commit (docs(launcher): self-label …) self-labels those two lines inline, keeping the historical data per the
banners:

  • docs/.../2026-06-01-slim-plugin-pivot.md — the "Both packages build" bullet
    intro now names the 2026-06-01 bullets as the retired record + points at
    bun launch.mjs.
  • docs/audits/2026-06-02-maintenance-readiness.md — the "Launch chain" status
    row is tagged a 2026-06-02 snapshot, superseded by the note directly below.

Left as-is (already adequately framed): the supersede banners; the RESOLVED+moot
launch.cmd CRLF section; HUMAN.md's bold-dated "(2026-06-03)" launcher-proof
paragraph. Docs-only commit; no code/test change.

🤖 Generated with Claude Code

…rtup` matcher

Provisioning the pinned bun into CLAUDE_PLUGIN_DATA is a first-session concern,
so the pre-warm hook does not need to re-fire on resume/clear/compact (the bun
already exists by then). Add `matcher: "startup"` to the SessionStart hook.

Why not the `Setup` event (the obvious "this is setup, not per-session" instinct):
`Setup` fires only on explicit `claude --init-only` / `-p --init|--maintenance`
("one-time preparation in CI or scripts") — never on plugin install or normal
startup. Moving the pre-warm there would skip it for ordinary users, so the first
scholar tool call would pay the full cold bun download + (on the source-sync path)
the ~67 MB import-graph auto-install — the cold-start latency already seen in the
field. The Claude Code plugins reference prescribes a guarded SessionStart hook
writing into CLAUDE_PLUGIN_DATA for exactly this "install a dependency once, reuse
across sessions and updates" case; this change keeps that mechanism and just
narrows when it fires.

Changes:
- .claude-plugin/plugin.json (committed source-sync manifest): matcher added.
- scripts/build-plugin.ts buildManifest(): matcher added to the generated per-OS
  manifests + rationale comment. buildMcpbManifest emits no SessionStart hook
  (Desktop schema), so it is unaffected.
- tests/manifests.test.ts + tests/build-plugin.test.ts: assert matcher:"startup"
  (committed manifest + linux/win32 generated manifests).
- 2026-06-01-slim-plugin-pivot spec: forward-looking hook description updated.

Verified: both targets build (linux 2.9 MB / win32 3.0 MB, 19 files each) and the
generated manifests carry matcher:"startup"; suite 391 pass / 0 fail; tsc clean.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Copilot AI review requested due to automatic review settings June 6, 2026 20:03

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

This PR scopes the SessionStart bun pre-warm hook to only run on the startup matcher, avoiding redundant provisioning work on other session triggers while preserving correctness (the launcher remains the synchronous provisioning gate).

Changes:

  • Add matcher: "startup" to the committed .claude-plugin/plugin.json SessionStart hook.
  • Update scripts/build-plugin.ts to emit matcher: "startup" in generated per-OS plugin manifests.
  • Strengthen tests and documentation to assert/describe the startup-scoped pre-warm behavior.

Reviewed changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated no comments.

Show a summary per file
File Description
tests/manifests.test.ts Updates the committed-manifest assertion to require matcher: "startup" on the SessionStart hook.
tests/build-plugin.test.ts Adds checks that generated linux/win32 manifests include SessionStart[0].matcher === "startup".
scripts/build-plugin.ts Emits matcher: "startup" for the generated SessionStart pre-warm hook and documents the rationale inline.
docs/superpowers/specs/2026-06-01-slim-plugin-pivot.md Updates the spec to reflect that the SessionStart pre-warm is scoped to startup.
.claude-plugin/plugin.json Adds "matcher": "startup" to the committed SessionStart hook group.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

…as current in isolation

Follow-up to the matcher-scoping change (this branch / PR #5), addressing the
doc-hygiene item it surfaced. The bun-launcher unification (PR #4) retired the
per-OS `launch.{sh,cmd}` shell pair, and every stale reference in the docs already
carries an adjacent supersede banner (repo convention: keep the dated record, add a
banner). The residual problem is the grep/scroll-lander: two lines state the
retired shell-pair launcher as the *current* mechanism when read without the
banner in view. Self-label them inline; the historical data stays put (the banners
say to keep it).

- docs/.../2026-06-01-slim-plugin-pivot.md: the "Both packages build" bullet-list
  intro now names the 2026-06-01 sizes + `launch.{sh,cmd}` in the bullets below as
  the retired shell-pair record and points at the current `bun launch.mjs`.
- docs/audits/2026-06-02-maintenance-readiness.md: the "Launch chain" status row is
  tagged as a 2026-06-02 snapshot superseded by the note directly below it.

Left as-is (already adequately framed): the supersede banners themselves; the
RESOLVED+moot `launch.cmd` CRLF section; HUMAN.md's "(2026-06-03)" launcher-proof
paragraph (bold dated header + adjacent banner). Docs-only; no code/test change.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@zaynram
zaynram merged commit 6a6800f into main Jun 7, 2026
2 checks passed
@zaynram
zaynram deleted the refactor/provision-hook-startup-matcher branch June 7, 2026 22:32
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