Skip to content
Apothem
参考

钩子

在 SessionStart、PreToolUse 和 Stop 上触发的工具事件处理器,加载用于强制执行 git 隔离和计划纪律的消息上下文。

钩子在工具事件上触发,并加载助手将其视为附加系统提示词的消息上下文。接线位于 Claude Code 的 settings.json 钩子块、Codex 的 hooks.json 钩子文件 以及 Qwen Code 的 settings.json 钩子映射中。

事件超时用途
SessionStart30 秒读取内存、检查计划状态、报告就绪情况
PreCompact30 秒在压缩前验证状态已外部化
PostCompact30 秒压缩后恢复工作状态
Stop60 秒会话结束时的外部化
PreToolUse (Bash)10 秒Bash 校验——git 产物隔离
PreToolUse (Write/Edit/NotebookEdit/apply_patch)10 秒计划引用隔离、frontmatter 检查

分发器

已安装的钩子条目通过绝对脚本路径调用分发器。设置模板携带 ${HARNESS_ROOT} 令牌—— python "${HARNESS_ROOT}/apothem/hooks/dispatch.py" <event> [<message-name>] ——安装程序在安装时将其渲染为 harness 根目录的真实路径 (Claude Code 和 Qwen Code 将分发器物化于 <harness-root>/apothem/hooks/ 下;Codex 则在 <harness-root>/hooks/ 下)。 分发器是一个独立的标准库脚本:它会自行引导 sys.path, 因此宿主上无需可导入的 apothem 包。从源码检出运行时,模块形式 python -m apothem.hooks.dispatch <event>(配合 PYTHONPATH=src) 为开发运行相同的代码。分发器加载 hooks/lib/resolve_root.py 进行生态根目录解析,并委托给 hooks/emit_hook_context.pyhooks/session_start_bootstrap.py

消息上下文

每个事件的 Markdown 上下文位于 src/apothem/hooks/messages/ 下:

  • postcompact.mdprecompact.mdstop.md
  • pretooluse-bash.mdpretooluse-write.mdpretooluse-edit.mdpretooluse-notebookedit.md

每个上下文文件在其事件触发且其上下文参数在设置文件中注册时由分发器加载。

生成的钩子消息清单

NameDescriptionSource
postcompactPost-compaction Blind Bootstrap (CM-24 §6.2). Restore working state from durable files; conversation context is now compressed.src/apothem/hooks/messages/postcompact.md
posttooluse-proactive-compactionProactive-compaction tracker for PostToolUse tool calls.src/apothem/hooks/messages/posttooluse-proactive-compaction.md
precompactPre-compaction protocol (CM-24 §2.3). Externalize all in-conversation state BEFORE the harness compresses context.src/apothem/hooks/messages/precompact.md
pretooluse-askuserquestion-recommendedCall-time (Recommended)-marker guard for AskUserQuestion tool calls.src/apothem/hooks/messages/pretooluse-askuserquestion-recommended.md
pretooluse-bash-plan-guardPlans-Discipline write guard for Bash tool calls (companion to pretooluse-write-plan-guard.md).src/apothem/hooks/messages/pretooluse-bash-plan-guard.md
pretooluse-bashCM-7 git-artifact isolation + M12 numeric-prefix discipline + M15 human-only authorship.src/apothem/hooks/messages/pretooluse-bash.md
pretooluse-conformity> Advisory: this hook reports; it does not block. Mechanical enforcement runs in CI.src/apothem/hooks/messages/pretooluse-conformity.md
pretooluse-dependency-guardDependency-manifest supply-chain guard (advisory).src/apothem/hooks/messages/pretooluse-dependency-guard.md
pretooluse-edit-header-guardSPDX-header inject guard for Edit tool calls.src/apothem/hooks/messages/pretooluse-edit-header-guard.md
pretooluse-editCodebase isolation (Edit scope).src/apothem/hooks/messages/pretooluse-edit.md
pretooluse-eval-guardDynamic-eval / unsafe-deserialization guard — advisory prompt-injection defense.src/apothem/hooks/messages/pretooluse-eval-guard.md
pretooluse-notebookeditCodebase isolation (notebook scope).src/apothem/hooks/messages/pretooluse-notebookedit.md
pretooluse-write-header-guardSPDX-header inject guard for Write tool calls.src/apothem/hooks/messages/pretooluse-write-header-guard.md
pretooluse-write-plan-guardPlans-Discipline write guard for Write / Edit / NotebookEdit tool calls.src/apothem/hooks/messages/pretooluse-write-plan-guard.md
pretooluse-writeCodebase isolation + frontmatter compliance.src/apothem/hooks/messages/pretooluse-write.md
sessionstartSession-start conformity posture.src/apothem/hooks/messages/sessionstart.md
stopSession-end protocol (CM-14 + CM-24 §2.5 + CM-26 + CM-22 §2/§4).src/apothem/hooks/messages/stop.md

On this page