Repository navigation
Description
Stop hook event is registered but never fires at runtime
Summary
The Stop hook event is listed as supported in the bundled zcode-guide/diagnosing-hooks skill and is accepted at plugin registration time (visible in Plugin Management UI, counted in bootstrap.app.startup.plugins.completed log), but it is never actually invoked at runtime when the agent finishes a reply. Other events in the same plugin (PreToolUse, UserPromptSubmit) work as documented.
Environment
- ZCode version: (the version that was current on 2026-07-26 — please confirm exact version if needed; issue reproducible across session restarts)
- OS: Windows 10 19045 x64
- Shell: Git Bash (MSYS2)
- Plugin type: local marketplace (
~/.zcode/my-plugins/)
Reproduction
Step 1: Plugin with a Stop hook
hooks/hooks.json:
{
"hooks": {
"PreToolUse": [
{
"matcher": ".*",
"hooks": [
{
"type": "process",
"command": "python",
"args": ["${CLAUDE_PLUGIN_ROOT}/hooks/check.py"],
"timeoutMs": 5000
}
]
}
],
"UserPromptSubmit": [
{
"matcher": ".*",
"hooks": [
{
"type": "process",
"command": "python",
"args": ["${CLAUDE_PLUGIN_ROOT}/hooks/check.py"],
"timeoutMs": 5000
}
]
}
],
"Stop": [
{
"matcher": ".*",
"hooks": [
{
"type": "process",
"command": "python",
"args": ["${CLAUDE_PLUGIN_ROOT}/hooks/stop_probe.py"],
"timeoutMs": 5000
}
]
}
]
}
}hooks/stop_probe.py is a minimal probe that appends the raw stdin payload to a file and exits 0 (full source: https://gist.github.com/... — happy to paste inline if useful; ~70 lines, never blocks, robust to malformed/empty input).
Step 2: Install + restart
- Plugin Management UI: uninstall old version, Get new version, Restart ZCode
- After restart,
Settings → Plugin Management → agent-gate-nudgeshows all 3 hooks as registered: PreToolUse, UserPromptSubmit, Stop. - ZCode log shows
bootstrap.app.startup.plugins.completedwith"hookCount": 4(was1before adding UserPromptSubmit + Stop).
Step 3: Send prompts and observe
Sent 3 prompts in the same session:
- A non-trivial prompt ("добавь X в Y...")
- A trivial prompt ("прочитай файл plugin.json")
- A conversational prompt
Expected: the stop_probe.py script runs after each agent reply completes, appending to its dump file.
Actual: the dump file contains zero entries from runtime. Only manual smoke tests (piping JSON directly into the script via py -3.13 stop_probe.py) produce entries.
Meanwhile, in the same session:
UserPromptSubmitfires correctly on every prompt (verified: the hook's<GATE-NUDGE-B4>output appears in the agent's prompt context).PreToolUsefires correctly on tool calls (verified: hook output appears as[Hook additional context]on Write/Edit/etc).
Evidence
Plugin Management UI
3 hooks visible: PreToolUse, UserPromptSubmit, Stop — all registered.
ZCode log
{"event":"bootstrap.app.startup.plugins.completed",
"context":{"enabledPluginCount":8,"hookCount":4,...}}
(hookCount increased from 1 → 4 after adding UserPromptSubmit + Stop.)
Stop probe dump file
After 3 runtime prompts and multiple agent replies: 0 new entries.
For comparison, manual smoke tests on the same script (5 invocations: empty stdin, malformed JSON, huge input, normal payload, timeout stress) all produced entries within seconds. The script is healthy.
Side observation: env vars not injected
The probe also dumps os.environ.get("CLAUDE_PLUGIN_ROOT"), ZCODE_PLUGIN_ROOT, CLAUDE_SESSION_ID. Per zcode-guide/diagnosing-hooks/SKILL.md line 35:
Template variables (expanded in the command and each argument, and also injected as environment variables):
${CLAUDE_PROJECT_DIR}/${ZCODE_PROJECT_DIR},${CLAUDE_SESSION_ID}; and, for plugin hooks only,${CLAUDE_PLUGIN_ROOT}/${ZCODE_PLUGIN_ROOT}and the plugin data directory.
In every smoke test (both for the Stop probe and for the UserPromptSubmit hook), all three env vars are None. The UserPromptSubmit hook works anyway because it doesn't need them, but a Stop hook that needs ${CLAUDE_PLUGIN_ROOT}/data/ for state would have no working path.
This may be related (template-variable injection broken across the board) or separate (only Stop is broken). Reporting together since they showed up in the same diagnostic.
Impact
I'm trying to enforce an "em-dash ban" rule via a Stop hook (block replies that contain triple em-dash flourishes). Without Stop event firing, there's no way to inspect or block the agent's reply text. PostToolUse only sees tool output, not reply text. UserPromptSubmit fires too early (before the reply exists).
What I'd like to know
- Is
Stopevent actually implemented in ZCode runtime, or only declared in the skill docs? - If implemented, are there undocumented trigger conditions (specific
finishReason, only on errors, etc.)? - Separately: should
${CLAUDE_PLUGIN_ROOT}etc. be injected as env vars for plugin hooks? The docs say yes; reality says no.
Happy to provide more diagnostic data (full plugin source, full ZCode log snippet, screen recording of the reproduction) on request.
Workaround
For my em-dash use case: none — the rule remains prose-only in AGENTS.md, enforced via post-hoc fable-judge review instead of mechanical hook. Works less well than a hook would.
For the env-var issue: hardcode Path.home() instead of ${CLAUDE_PLUGIN_ROOT} in the hook script. Works but defeats the portability the template variables are supposed to provide.
Thanks for looking into this. The hook framework overall is excellent — PreToolUse and UserPromptSubmit give us a lot of mechanical-enforcement surface. Closing the Stop gap would unlock reply-text validation (format rules, banned phrases, required sections).
Activity
github-actions commentedon Jul 26, 2026
👋 感谢你的反馈,我们已经收到。
status: 待评估,你可以随时补充信息。needs: 更多信息标签并 @ 你。👋 Thanks — we've received your issue.
status: 待评估(Triage); feel free to add context.needs: 更多信息and ping you.panda920 commentedon Aug 17, 2026
这条和 #167 是同一个问题,已合并到 #167 统一跟进。
共同根因:hooks 在配置/插件里注册成功、UI 也显示已加载,但运行时多个事件(Stop、PreToolUse、SubagentStart/Stop 等)从不触发,导致依赖 hook 的插件(dcg、SAP 等)整体失效。
合并是为了让研发看到完整上下文,而不是同一件事被拆成 4 条各自跟进。你的反馈没有丢——我已经在 #167 里把这几条一起列了出来,后续进展都会更新在那边,建议去 #167 点一下 Subscribe。
如果你认为这其实是另一个问题,直接回复本条,我们会重新拆开。
This is the same problem as #167, and is now tracked there.
Shared root cause: Hooks register successfully in config/plugins and show as loaded in the UI, but several events (Stop, PreToolUse, SubagentStart/Stop, …) never fire at runtime, which breaks any plugin built on hooks (dcg, SAP, and others).
We're consolidating so the team sees one complete picture instead of the same thing split across 4 issues. Nothing is lost — your report is listed in #167, all updates will go there, and you're welcome to subscribe to it.
If you think this is actually a different problem, reply here and we'll split it back out.