Skip to content
Apothem
Reference

Hooks

Tool event handlers that fire on SessionStart, PreToolUse, and Stop, loading message contexts enforcing git isolation and plan discipline.

Hooks fire on tool events and load message contexts that the assistant treats as additional system prompts. Wiring lives in the Claude Code settings.json hook block, the Codex hooks.json hook file, and the Qwen Code settings.json hooks map.

EventTimeoutPurpose
SessionStart30 secondsRead memory, check plan state, report readiness
PreCompact30 secondsVerify state externalized before compaction
PostCompact30 secondsRestore working state after compaction
Stop60 secondsSession-end externalization
PreToolUse (Bash)10 secondsBash validation — git artifact isolation
PreToolUse (Write/Edit/NotebookEdit/apply_patch)10 secondsPlan-reference isolation, frontmatter checks

Dispatcher

Installed hook entries invoke the dispatcher by absolute script path. The settings templates carry the ${HARNESS_ROOT} token — python "${HARNESS_ROOT}/apothem/hooks/dispatch.py" <event> [<message-name>] — which the installer renders to the harness root's real path at install time (Claude Code and Qwen Code materialize the dispatcher under <harness-root>/apothem/hooks/; Codex under <harness-root>/hooks/). The dispatcher is a standalone stdlib script: it bootstraps its own sys.path, so no importable apothem package is needed on the host. From a source checkout, the module form python -m apothem.hooks.dispatch <event> (with PYTHONPATH=src) runs the same code for development. The dispatcher loads hooks/lib/resolve_root.py for ecosystem-root resolution and delegates to hooks/emit_hook_context.py and hooks/session_start_bootstrap.py.

Message contexts

Per-event Markdown contexts live under src/apothem/hooks/messages/:

  • postcompact.md, precompact.md, stop.md
  • pretooluse-bash.md, pretooluse-write.md, pretooluse-edit.md, pretooluse-notebookedit.md

Each context file is loaded by the dispatcher when its event fires and its context argument is registered in the settings file.

Generated Hook Message Inventory

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