Skip to main content

Customize Hooks

"I want KMGraph to automatically do X. How do I wire that up?"

KMGraph registers shell scripts with Claude Code's lifecycle events — you can add, disable, or replace any of them. You need KMGraph installed with hooks/hooks.json present (Claude Code only).

How hooks work

KMGraph registers shell scripts with Claude Code's lifecycle events via hooks/hooks.json. The events are:

EventWhen it fires
SessionStartWhen Claude Code opens a session
PreToolUseBefore a tool is called
PostToolUseAfter a tool returns
StopWhen Claude Code ends a response
NotificationWhen a notification is sent

The master script scripts/hooks-master.sh routes each event to sub-scripts in scripts/.

View the configuration

cat hooks/hooks.json

Disable a specific hook

To disable the post-tool lesson check (which prompts to capture lessons after certain tool uses), comment it out in scripts/hooks-master.sh:

# Disable lesson check
# source "${SCRIPT_DIR}/post-tool-lesson-check.sh"

Add custom behavior

Create a new script in scripts/ and add a source call in hooks-master.sh at the appropriate event branch:

# In hooks-master.sh, under the PostToolUse branch:
source "${SCRIPT_DIR}/my-custom-hook.sh"

After changes, start a new Claude Code session — the SessionStart hook output confirms the configuration took effect.

Disable all hooks

Remove or rename hooks/hooks.json:

mv hooks/hooks.json hooks/hooks.json.disabled

Reload Claude Code for the change to take effect.

Re-enable hooks

mv hooks/hooks.json.disabled hooks/hooks.json

Individual hook scripts

ScriptWhat it doesSafe to disable?
post-tool-lesson-check.shPrompts for lesson capture after solvingYes
platform-file-change-check.shDetects changes to CLAUDE.md / AGENTS.mdYes
pre-commit-knowledge-gate.shBlocks commits that skip knowledge captureYes (reduces automation)
session-end-prompt.shPrompts for session summary on Stop; Codex CLI-compatibleYes
plan-mirror.shMirrors plan files from ~/.claude/plans/ to docs/plans/Yes
notification-dispatch.shSends webhook notificationsYes (if webhook not configured)