The allow-key paragraph said a version bump on one side stops the hook deploying; apm 0.28.0 matches the grant version-blind (the 2026-09-19 correction in gates.md and ADR-0019). The sync gate now covers every plugin shipping hooks or bin. The Copilot section said apm packages deploy no hooks to Copilot. apm 0.28.0 shapes and deploys hooks per target: .github/hooks/ for copilot (unverified on Copilot CLI) and .codex/hooks.json for codex. Replaced it with an "Other runtimes" table, and noted the spurious "parked" warning (#208). Refs #190 Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_012CqgnwEGtmfsjcoG9QwByN
9.3 KiB
Hooks
Reference for this plugin's hook definitions: where to edit them, what apm does with them, and what the host ends up reading.
Where to edit
Author hooks in plugins/kyberforge/.apm/hooks/*.json. .apm/ is the only content source and
apm install is the only supported install path (ADR-0024) — there is no generated mirror at the
plugin root and no per-plugin plugin.json, so .apm/hooks/ is both where you edit and what ships.
apm merges every *.json in that directory into a single hook definition and writes the event
bindings into each target the consuming project enables: .claude/settings.json for Claude Code,
and per-target files for Copilot and Codex (see "Deployed shape" and "Other runtimes" below). Scripts a
hook invokes live in the same directory, alongside the JSON that references them.
Hook file structure
The shape Claude Code reads, and therefore the shape to author under .apm/hooks/:
{
"hooks": {
"PostToolUse": [
{
"matcher": "Bash",
"hooks": [
{ "type": "command", "command": "echo 'tool used'" }
]
}
]
}
}
Events (partial list): PreToolUse, PostToolUse, Notification, Stop, and SessionStart
(verified end-to-end by the hook below). Claude Code's plugin hook set is larger — SessionEnd,
UserPromptSubmit, PreCompact and SubagentStop also exist — and this repo's vendored corpus does
not enumerate it anywhere: docs/research/docs/claude-code-plugins/configuration.md:100 describes
the file as "Event handlers (PreToolUse, PostToolUse, etc.)", and agent-definition.md:53 covers
only the per-agent hooks field, not the plugin-level set. Treat the five names above as the ones
this repo has verified, not as the schema. Check Claude Code's own hooks documentation before wiring
an event not listed here.
Referencing a script — use the .apm/ path
Use ${CLAUDE_PLUGIN_ROOT} to reference scripts inside this plugin; the plugin runs from a cache or
apm_modules/ path after install, not its original repo location. Address the script at its
.apm/ path:
"command": "${CLAUDE_PLUGIN_ROOT}/.apm/hooks/check-apm-current.sh"
The obvious-looking ${CLAUDE_PLUGIN_ROOT}/hooks/check-apm-current.sh does not work, and fails
quietly enough to be worth spelling out. apm resolves the placeholder against the installed package
root, and there is no hooks/ directory there at all — the package's content is .apm/. apm prints
Hook script not found: .../hooks/check-apm-current.sh and then deploys the hook anyway, pointing at
a path with no file behind it.
tests/test-apm-current-hook.sh pins the reference so a well-meaning "simplification" back to
hooks/ fails the suite rather than silently disabling the hook.
Deployed shape
At install, apm merges the event bindings into .claude/settings.json, copies the referenced script
to .claude/hooks/<pkg>/ (preserving its executable bit, preserving the .apm/hooks/ subpath), and
rewrites command to a ${CLAUDE_PROJECT_DIR}-relative path. Ownership of its own entries is
tracked in a .claude/apm-hooks.json sidecar, so an uninstall removes them without touching
hand-authored hooks. Both .claude/hooks/ and the sidecar are gitignored install output.
Note that apm's executable-trust gate is off unless the consuming project's apm.yml has an
executables: block — without one, package hooks deploy with no prompt. The grant is
version-blind: apm also matches an allow key such as kyberforge#<version> by its bare package
name, so a version bump on one side does not stop the hook deploying (verified against apm 0.28.0;
the correction is recorded in ADR-0019 and docs/spec/gates.md). This repo still keeps each key at
<name>#<version> as a record of which version was reviewed, and check-executables-allow-sync is
the pre-push gate that holds every plugin shipping .apm/hooks/ or bin/ to that.
apm 0.28.0 prints "parked pending approval" for a granted package even when it deploys the hook (holocron#208). Check for the deployed script and settings entry, not the warning.
The SessionStart hook
check-apm-current.sh keeps an apm-consumed install level with its remote: it runs apm outdated,
and if anything is behind, runs apm update --yes and returns reloadSkills: true so the running
session picks up the redeployed content. Rationale, measurements, and the failure modes are in
ADR-0019.
Where it looks for the lockfile. The hook resolves a project directory as ${CLAUDE_PROJECT_DIR}
when the host exports it (Claude Code does, for SessionStart hooks) and the current directory
otherwise, then exits silently unless that directory holds an apm.lock.yaml — which is what makes
it inert in any project that does not consume packages through apm. Both apm invocations run
against the same resolved directory. The earlier spelling checked a bare apm.lock.yaml against the
session's cwd, so a session opened in a subdirectory of an apm-consuming repo no-opped silently.
Keep the cwd fallback: a host that sets no CLAUDE_PROJECT_DIR must still get inert-but-harmless
behaviour, not an unset-variable error.
The timeout in hooks.json must exceed the script's own budget. The script spends at most
timeout 60 apm outdated plus timeout 300 apm update; the hook entry declares timeout: 380, the
sum plus a buffer. Set it lower and a slow remote gets the hook SIGKILLed mid-apm update, leaving a
partially redeployed .claude/skills/ and emitting no notice — precisely the silent failure the hook
exists to prevent. tests/test-apm-current-hook.sh pins the relationship (host timeout > sum of the
script's internal timeouts) rather than the literal, so raising either side alone fails the suite.
Staleness is detected by matching apm's summary line, and both spellings count. apm outdated
has no --json or otherwise machine-readable output (verified against apm 0.28.0), so the hook
greps its text. apm prints 1 outdated dependency found in the singular when exactly one package is
behind and N outdated dependencies found otherwise; matching only the plural silently misses a
one-package drift. Because a mocked apm would keep a reworded release invisible, the test suite
stages a genuinely outdated dependency against the real apm — a local git repo reached through
url.<path>.insteadOf rewrites, so it needs no network — and replays that genuine output through the
hook.
Other runtimes
An earlier version of this section said Copilot loads no hooks from an apm package, because nothing
pointed Copilot at a hooks file and apm wrote only a Claude-shaped definition. That no longer holds:
apm 0.28.0 shapes and deploys hooks per target itself, with no plugin.json pointer involved.
Sources: docs/research/infra-packages/enforcement-hooks.md on the research/enforcement-hooks
branch, and the delivery guard hook work.
| Target | Where apm writes the hook | Status |
|---|---|---|
copilot |
One file per hook, .github/hooks/<pkg>-<name>.json, with the script under .github/hooks/scripts/<pkg>/.apm/hooks/. Event names are renamed to camelCase and version: 1 is added. |
Unverified. Entries keep Claude's nested matcher group with command/timeout. Copilot's docs accept command/timeout as aliases for bash/powershell, but don't document the nested group, so whether Copilot CLI runs the hook is untested until a Copilot account exists. |
codex |
Merged into .codex/hooks.json, with the script under .codex/hooks/<pkg>/.apm/hooks/. Claude's event names and shape are kept. |
apm skips the target unless .codex/ already exists, and Codex runs project hooks only after a human trusts them. |
Only enabled targets get a hook: this repo's root apm.yml targets claude alone, so nothing lands
in .github/hooks/ or .codex/ here. VS Code's Copilot reads both .github/hooks/ and
.claude/settings.json, so a package installed for both claude and copilot runs each hook
twice there.
The SessionStart hook is Claude-only in practice. check-apm-current.sh answers with Claude
Code's reloadSkills output and reads ${CLAUDE_PROJECT_DIR}, so on another runtime it at most
runs the update without reloading anything.
Symlinks under .apm/ do not survive, and nothing reports it
Do not author any file under plugins/kyberforge/.apm/ as a symlink. apm's copy path filters
symlinks out silently: ignore_non_content() in apm_cli/security/gate.py is a
shutil.copytree ignore callback that drops every entry answering is_symlink(), commented
"Excludes symlinks (security)". The file never reaches the consumer's install, and no warning is
printed at any point.
No gate catches this. The pre-push check that used to read the .apm/ tree and fail on the
offending path was deleted along with the content mirror, and the decision was taken not to replace
it (ADR-0024 consequence 7). This document is the only thing standing between a symlink and silent
content loss. No symlink exists under any .apm/ today; add one and it is dropped on deploy with
nothing reporting it. Replace it with a regular file.
The old exemption for .apm/<category>/<name>/tests/ no longer applies either. That directory was
exempt only because the mirror excluded it; apm deploys it like any other content (ADR-0024
consequence 2), so a symlink there loses content the same as anywhere else.