Repository navigation
A plugin event starts one hook process that loads only its mode's scripts, and the instructions ask for a first call only to a loaded tool - #1720
Open
zlareb1 wants to merge 8 commits into
Conversation
… a first call only to a tool loaded up front Work in progress on this branch; the pull request is squash-merged. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com> Signed-off-by: Lareb Zafar <lareb.zafar@clickhouse.com>
Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com> Signed-off-by: Lareb Zafar <lareb.zafar@clickhouse.com>
…ripts Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com> Signed-off-by: Lareb Zafar <lareb.zafar@clickhouse.com>
Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com> Signed-off-by: Lareb Zafar <lareb.zafar@clickhouse.com>
Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com> Signed-off-by: Lareb Zafar <lareb.zafar@clickhouse.com>
Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com> Signed-off-by: Lareb Zafar <lareb.zafar@clickhouse.com>
Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com> Signed-off-by: Lareb Zafar <lareb.zafar@clickhouse.com>
…iewed sender pins follow the edited scripts Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com> Signed-off-by: Lareb Zafar <lareb.zafar@clickhouse.com>
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Changelog category (leave one):
Changelog entry (one or two sentences a user of Loom can read without the diff; the release pull request collects these into the release notes):
The Claude Code plugin starts one hook process after a tool call, at Stop and before a compaction, where it started two to four, and in
codeormemorymode that process loads only that plane's scripts. A shell command with no read or search in it costs the code shunt no git call, a prompt waits for its lookups no longer thanLOOM_PROMPT_PACK_TIMEOUT_MS, and the plugin's MCP instructions ask for a first call only to a code tool whose schema is loaded up front.Why
A benchmark ran one bug-fix task in 29 sessions with the plugin installed. The agent called no Loom tool in any of them, so what the plugin added was overhead, and the hook processes were the part of it that costs time.
hooks.jsonis fixed per event, not per plane, so an install of one plane still started the other plane's scripts:codemode: the file context, which is memory's and exits unused, the test gate and the recorder. A Stop started four, a compaction four.initializeparagraph said "Use Loom first" and namedloom_code_search, whose schema is deferred, so following it costs the client a tool-search request before the call.What is true now:
loom-record.mjs, which already ran an event's recording scripts and a prompt's two lookups, also runs the scripts the session waits for after a tool call (file context, mentor hint, blast radius, tests line, each for the tools it was wired for) and at Stop (the three gates), withrunHooksTogether, and prints their answers as one. It loads a script only for its tools and only where the mode runs its plane. Before a compaction it runs the four scripts in its own process, as at SessionEnd.LOOM_PROMPT_PACK_TIMEOUT_MS, and the recall's request has the same bound. A lookup that has not answered by then is skipped.loom_code_edit_contextandloom_code_grepby default) and, where a deployment loads none up front, asks for no first call.Measured on one shared machine, base and branch back to back, the order alternating (
tests/bench/hook-wall-time.mjs, stub server at 20 ms, 50 tool calls and one stop):maincodemodecodemode, median of 10 roundscodemode: before a shell callcodemode: after a shell callboth, 3 roundsThe machine was under a load average of 22 to 60 for all of it, and an empty
nodeprocess took 84 to 303 ms to start and exit, so 104 of them alone took 12 to 20 s. The absolute times say little about an idle machine; the ratios are the result. The paired ratio incodemode ranged from 0.77 to 1.50, median 0.92.What this does not fix:
codemode first request is 5,964 bytes with the plugin's defaults (5,960 onmain; the sentence is four bytes longer). WithLOOM_MCP_ALWAYS_LOAD_TOOLSempty it is 3,337 bytes and the paragraph asks for no first call.Scope and risk
hooks/hooks.json(PostToolUse, PreCompact and Stop each wire the launcher alone),hooks/loom-record.mjs, six scripts that now return their answer throughrunHookMaininstead of writing it (loom-file-context,loom-mentor-hint,loom-blast-radius,loom-test-gate,loom-validate-gate,loom-namespace-health),loom-code-shunt, the two prompt lookups, and on the server the plugin paragraph inserver/transport/mcp_primer.py.additionalContext, joined by a newline, where the client showed two. Two gates holding the same stop are one block with a reason on each line. Each script's text is unchanged.LOOM_HOOK_DEBUG=on, as every script that ends inrunHookMaindoes. They were silent.Compatibility, rollout and rollback
initializeinstructions changes for a plugin connection (schema_profile=plugin), in every mode.LOOM_PROMPT_PACK_TIMEOUT_MS(2,500 ms) now also bounds the memory recall's request.Tests
Ran; each passes except where a line says otherwise:
node --test, one file at a time, on the four plugin test files this changes (tests/hooks-json.test.mjs8,tests/record-hook.test.mjs24,tests/hook-contract.test.mjs7,tests/code-shunt-hook.test.mjs27) and ontests/plugin-modes.test.mjs(4, unchanged: it runs a scripted session per mode through the wiring). Run as one invocation while a replay shared the machine, three tests failed on timing in one run and three others in the next.tests/unit/test_mcp_primer_order.py(the plugin paragraph, with the new test),test_codex_plugin.py,test_mcp_coding_toolset.py,test_mcp_listing_budget.py,test_search_switch_ab.py,test_public_copy.py,test_agent_instructions.py,test_published_links.py. Intest_session_content_senders.pythe reviewed pins of the eight scripts this edits are renewed (their send sites and bodies are unchanged); the test still fails on the pin ofsdk/python/loom/memory.py, which does not match onmaineither.ruff format --check,ruff check, the function-length gate,agent_plugin_sync.py --check,docs_reference.py --check,op_reach_census.py --check,settings_reference.py --check, Biome and Prettier on the changed files,node --checkon every changed plugin file,claude plugin validate integrations/claude-code-plugin --profile directory --strict. The mypy gate reports onlyserver/llm/vertex_auth.py, where this machine has no stubs forgoogle-auth.node integrations/claude-code-plugin/tests/e2e/agent-session.mjs claude: one session of the installed plugin on the current client, against a local fake for the model API and Loom. Every event fired, every hook exited 0 with nothing on stderr, and each event's Loom call arrived (PASS claude on darwin-arm64: 24 requests).Replay: the hook inputs of the 29 recorded sessions (344 events) went through the hooks of
mainand of this branch, started the way the client starts them, against a stub server whose answers make the hooks inject. The recorded shell commands were not run; a call that writes a file of the checkout appends a line to it.both, replayed twice: every event's output is byte-identical, 69,417 bytes over 139 events with output, and both arms sent the same requests. The sessions waited for 660 processes onmainand 344 here. The hooks took 264.0 s onmainand 247.2 s here in the first replay, and 402.7 s and 406.5 s in the second, which shared the machine with the test runs.tests/record-hook.test.mjs, not by the replay.code: every event's output is byte-identical, 10,848 bytes over 75 events. In one session one arm sent onecode.test_gaterequest fewer during a load spike; replayed alone, that session sent the same requests in both arms.Not run: the unit suite and the integration suite (CI), the other plugin test files, the plugin skill evals, a session on Codex.
The client's hook schema was read in two versions. The wiring uses the fields
mainuses (type,command,args,matcher,timeout) and adds none. A client older than the documented minimum, 2.1.139, dropsargsand runs no plugin hook, onmainas here.Not verified:
AI assistance in the code (leave one; writing this description with AI is fine):
AI-generated (an agent wrote most of the diff): Claude Code wrote the diff and ran the measurements and tests listed above. A person has not read it yet.
I can explain every line of this diff and how it interacts with the rest of Loom.
Checklist
make test-unitand applicable integration results are reported by CI; a full local run is not required before pushing.docs/reference/configuration.mdand thedocs/reference/tables (python scripts/codegen/docs_reference.py), the reach manifest,schemas/schema.sql(make schema-dump) and the Codex plugin copies (python3 scripts/codegen/agent_plugin_sync.py).main; no merged migration is edited.hooks/,lib/,bin/,skills/,.mcp.json, the Codexplugin-defaults.json) bumps both plugin manifests' version, and no other open PR uses that version.npm --prefix frontend run build) and its tests pass, iffrontend/changed.docs/describe the system as it now is, and this description names any operator steps and wire changes.tests/unit/test_public_copy.py).git commit -s), as CONTRIBUTING.md asks.🤖 Generated with Claude Code
Note
Medium Risk
Consolidating multiple hooks into one launcher changes timing, merging, and mode gating of injected context and stop gates; replay/tests claim byte-identical outputs in
bothmode but paired hook timing varied under load.Overview
Hook wiring no longer starts separate processes for post-tool context, gates, and PreCompact housekeeping.
hooks.jsonwiresloom-record.mjsalone forPostToolUse,PreCompact, andStop; the launcher runs mode-filtered “waited” scripts (loom-file-context, mentor hint, blast radius, tests line, stop gates) in-process viarunHooksTogether, merges their outputs into oneadditionalContextor block reason, and still spawns a detached process for recording-only scripts.Individual hook scripts return JSON answers through
runHookMaininstead of writing stdout, so they can run standalone (Codex) or under the launcher (Claude Code).Prompt latency is capped by a single shared bound:
LOOM_PROMPT_PACK_TIMEOUT_MS(default 2.5s) applies to the code pack’s repository lookup plus search answer and to prompt recall; slow lookups are skipped.Code shunt exits early on Bash commands with no file read, grep, or issue search, avoiding git and repository resolution.
PreCompact runs capture, working memory, session brief, and file-context reset inside
loom-recordsynchronously so the working-memory note exists before the post-compaction primer.Documentation and plugin version 1.2.78 (Claude Code and Codex manifests) align with the new event model and MCP startup guidance (first call only to tools loaded up front).
Reviewed by Cursor Bugbot for commit a052d09. Bugbot is set up for automated code reviews on this repo. Configure here.