A hook should be a function call, not a shell
说明与用途
在 Claude Code 中,每个钩子都作为单独的 shell 脚本运行,产生多个进程并导致延迟。通过将钩子移动到单个插件模块并在现有进程中执行,执行时间降至接近零,提升了性能。
问题
Each hook in Claude Code ran as a separate shell script, spawning multiple processes and causing significant latency.
结果
Hook execution time dropped from ~90 ms to near zero, reducing overall latency and resource usage.
工作流
- Identify hooks that can be converted to function calls
- Create register.js to load hooks once per session
- Move hook logic into hooks/mods/*.js as plain functions
- Update workkit to use the new module for hook execution
- Test with claude plugin test to ensure no Claude Code dependencies
证据
Until this week every hook was a shell script. Each fire went through a loader script, which started bash, which usually called jq to read the event, and often node for the real logic.
Claude Code can now load a plugin module once per session and call it on each event.
workkit 0.79 moved thirteen hooks into one such module, and fifteen live there now.
A bare bash, jq and node chain alone took about 38 ms. A function call inside a process that is already running rounds to zero.
- 记录日期: 2026-10-21T21:11:33.218Z