Skip to content

Latest commit

 

History

History
63 lines (51 loc) · 11.5 KB

hooks.md

File metadata and controls

63 lines (51 loc) · 11.5 KB

Hooks: which hook prints which message

One row per hook wired in hooks/hooks.json and settings.json. Find the hook behind a message you see, the knobs that tune it, and its source file.

Searching the installed kit with plain rg or fd finds nothing, because every entry under ~/.claude/dwarves-kit is a symlink. Follow links, or name the hooks directory as the search root:

rg -L "Context ceiling" ~/.claude/dwarves-kit
rg "Context ceiling" ~/.claude/dwarves-kit/hooks

The plugin hooks/hooks.json runs every Claude Code hook except secrets-guard through hooks/anchor-root.sh, which changes to the repo root first. Codex, agy, and Devin share the same entry via hooks/anchor-root.sh --runtime <codex|agy|devin> --event <PreToolUse|Stop> <guard> and hooks/entry-normalize.jq, wired by hooks/codex-hooks.json, hooks/agy-hooks.json, and hooks/devin-hooks.json.

Two env vars apply to groups of hooks, not all of them:

  • DWARVES_KIT_DEBUG=1 prints a [dwarves-kit:<name>] trace line to stderr. These hooks honor it: anti-rationalization, auto-format, codebase-index, context-readiness, permission-auto-approve, safety-gate, slop-cleaner, spec-drift-guard.
  • Hook logs live in hooks/ under the ledger root: ~/.local/state/dwarves-kit/logs/hooks/<hook>.log by default. lib/telemetry/hook-log-dir.sh resolves the root with the same precedence as the ledgers (KIT_LEDGER_DIR, then DWARVES_KIT_LOG_DIR, then [ledger].location, then the XDG default), so one setting moves both. DWARVES_KIT_LOG_DIR=/x puts the logs in /x/hooks. These hooks log there: anti-rationalization, board-row-gate, citation-guard, commit-format, safety-gate, secrets-guard, ship-gate, slop-cleaner, spec-drift-guard. On first use the helper copies any old log from ~/.claude/dwarves-kit/logs with cp -n and never deletes the old directory. The logs survive a plugin reinstall and build the eval corpus for future optimization.

A [gate] key in the committed project kit config switches a gate off. lib/gate/gate-policy.sh reads it. See lib/gate/README.md.

Hook table

Module is the install.sh --with group that enables the hook. Spine hooks always install.

Hook Event (matcher) Message prefix it prints Env knobs and config Module Source
safety-gate PreToolUse (Bash) BLOCKED: plus a reason such as "Destructive delete detected", "Do not push directly to main/master", "Force push is dangerous", "'git reset --hard' discards uncommitted work". Exits 2. none beyond the globals spine hooks/safety-gate.sh
ship-gate PreToolUse (Bash) BLOCKED: ship-gate. (missing lane gates, a spec whose last ## Review verdict is DO NOT SHIP or differs from the verdict the run ledger recorded ([gate] review_verdict), or a git push that lands on a default branch in any repo: main, master, production, or the remote HEAD branch), BLOCKED: doc-projection drift., BLOCKED: registry freshness., plus [advisory] lines on stderr. Exits 2 on a block. DWARVES_KIT_SKIP_DOC_PROJECTION=1, DWARVES_KIT_SKIP_REGISTRY_FRESHNESS=1, KIT_ALLOW_DEFAULT_PUSH=1 (session env only, never a command prefix); config lane_gates, proof_of_done, review_verdict spine hooks/ship-gate.sh
spec-drift-guard PreToolUse (Write) [dwarves-kit] '<file>' is not in any active spec. Context only, never blocks. none spine hooks/spec-drift-guard.sh
secrets-guard PreToolUse (Read|Edit|Bash) secrets-guard: plus "targets a secret file" or "appears to read a secret file". Exits 2. none spine hooks/secrets-guard.sh
commit-format PreToolUse (Bash) commit-format: plus the failed rule (length over 72, spec marker, not a Conventional Commit). Exits 2. config commit_format spine hooks/commit-format.sh
anti-rationalization Stop Rationalization detected:, Guess-fix detected during an open debug session, Completion claimed but the diff still adds an unimplemented stub. Exits 2. config understanding_gate spine hooks/anti-rationalization.sh
board-row-gate PreToolUse (Bash) BLOCKED: board-row-gate. when a commit adds a board row with no board-row-ok: line. Exits 2. DWARVES_KIT_SKIP_BOARD_ROW_GATE=1; config board_row_gate board hooks/board-row-gate.sh
backlog-stage SessionEnd; SessionStart (--surface) backlog-stage: fired detached on stderr. A no-op unless enabled. BACKLOG_STAGE_AUTO=1 (opt-in), BACKLOG_STAGE_STAGING, BACKLOG_STAGE_BACKLOG, BACKLOG_STAGE_MIN_INTERVAL, BACKLOG_STAGE_MAXCHARS, BACKLOG_STAGE_PREFILTER, BACKLOG_STAGE_EXTRACTOR, BACKLOG_STAGE_SYNC, BACKLOG_STAGE_STATE_DIR, REPO_ROOT board hooks/backlog-stage.sh
kit-update-notice SessionStart (startup) One user line: dwarves-kit <latest> is available (installed: <installed>). Run: claude plugin marketplace update dwarves-marketplace && claude plugin update kit@dwarves-marketplace, then restart Claude Code. Only when the latest release is newer. Fetches at most once per 24h (2s cap), never installs, silent on any failure. KIT_UPDATE_CHECK=0 (off), KIT_UPDATE_CHECK_URL, KIT_UPDATE_STATE_DIR update_check hooks/kit-update-notice.sh
context-readiness SessionStart [dwarves-kit] then <state> | next: <suggestion> | warn: <warnings>. none session hooks/context-readiness.sh
post-compact-reinject SessionStart (compact) [dwarves-kit post-compaction] Context was compacted. Critical rules re-injected: none session hooks/post-compact-reinject.sh
codebase-index SessionStart Silent. Debug trace [dwarves-kit:index]. Starts a background index when codebase-memory-mcp is on PATH. none cosmetic hooks/codebase-index.sh
output-offload PostToolUse (all tools) [dwarves-kit] <tool> output was large (~N tokens, over the N-token offload threshold). Full payload saved to <file>. OFFLOAD_MAX_TOKENS (default 2000), XDG_CACHE_HOME session hooks/output-offload.sh
pre-compact-backup PreCompact Backup saved: <file> on stderr. Writes <repo>/.claude/backups/. none session hooks/pre-compact-backup.sh
harvest PreCompact; SessionEnd (--lab-log) harvest: staged N new ..., harvest: staged a LAB_LOG draft ..., harvest: fired detached ... on stderr. HARVEST_LEDGER, HARVEST_GLOSSARIES, HARVEST_EXTRACTOR, HARVEST_FUZZY_THRESHOLD, HARVEST_MAXCHARS, HARVEST_LABLOG_DRAFT, HARVEST_STOP_TRIGGER, HARVEST_STOP_N, HARVEST_STATE_DIR, HARVEST_MIN_INTERVAL, HARVEST_SYNC, HARVEST_SWEEP_CHILD, REPO_ROOT session hooks/harvest.sh (bash plus jq), hooks/harvest_lib.py (the sweep ledger helpers and operator verbs)
citation-guard Stop citation-guard: unresolved citations: on stderr, only in strict mode. Otherwise it logs. CITATION_GUARD_STRICT=1, CITATION_GUARD_ROOT, CITATION_GUARD_LOG session hooks/citation-guard.sh
context-budget UserPromptSubmit User line: Context budget: this session holds Nk tokens of live context, at or past the 200k budget, then Context ceiling: ... at or past the 250k ceiling. Model line: CONTEXT BUDGET: and CONTEXT CEILING:. KIT_CTX_WARN_TOKENS (default 200000), KIT_CTX_STRONG_TOKENS (default 250000); legacy percent-of-window mode only when KIT_CTX_WARN_PCT or KIT_CTX_STRONG_PCT is set (window from KIT_CTX_WINDOW) session hooks/context-budget.sh
batch-debt-warn PreToolUse (Bash) Batch-debt warning: on the second gh pr merge of a session with no lane START in the ledger. Once per session. none session hooks/batch-debt-warn.sh
context-hints UserPromptSubmit Session time: <elapsed> elapsed, <idle> since your last prompt. and Maybe-relevant skills:. CONTEXT_HINTS_SKILLMAP, CONTEXT_HINTS_STATE, CONTEXT_HINTS_NOW, CONTEXT_HINTS_TEMPORAL=0 advisor hooks/context-hints.sh
tool-policy-guard PreToolUse (all tools) tool-policy-guard: <tool> is DENIED by policy (exit 2) or is policy-controlled (warning). Silent without a policy file. KIT_TOOL_POLICY (default ~/.claude/dwarves-kit/tool-policy.json) advisor hooks/tool-policy-guard.sh
auto-format PostToolUse (Write|Edit) Silent. Runs prettier, gofmt, ruff or black, or rustfmt by file type. RUSTFMT_TOOLCHAIN (default stable) cosmetic hooks/auto-format.sh
slop-cleaner Stop [dwarves-kit:slop-check] These recently modified files may have unnecessary complexity:. Context only. DWARVES_KIT_SESSION_MARKER cosmetic hooks/slop-cleaner.sh
notification Notification A desktop notice titled dwarves-kit: "Claude needs permission to proceed", "Claude is waiting for your input", or "Claude needs your attention". none cosmetic hooks/notification.sh
permission-auto-approve PermissionRequest Silent. Approves a Bash command only when it is single, simple and read-only. Debug trace [dwarves-kit:permission]. none cosmetic hooks/permission-auto-approve.sh
money-gate PreToolUse (Edit|Write|MultiEdit) money-gate: edit in a financial repo touches <terms>: confirm before applying. Inert unless MONEY_GATE_REPOS is set. MONEY_GATE_REPOS, MONEY_GATE_STRICT, MONEY_GATE_LOG money_gate hooks/money-gate.sh
prose-rag UserPromptSubmit Prior-note recall from bin/prose-rag hook. Dormant unless enabled. PROSE_RAG_INJECT=1 prose_rag hooks/prose-rag.sh

Files in hooks/ that are not hook events

File Role
hooks/anchor-root.sh Single hook entry for all four runtimes. For Claude Code (anchor-root.sh <hook>), changes to the repo root, exports DWARVES_KIT_INVOCATION_CWD, checks [modules], and execs the hook. For Codex, agy, and Devin (anchor-root.sh --runtime <codex|agy|devin> --event <PreToolUse|Stop> <hook>), normalizes stdin with hooks/entry-normalize.jq, runs the guard under a watchdog (DEVKIT_ENTRY_TIMEOUT, default 28s), fails closed on blocking guards (and fails open to ${TMPDIR:-/tmp}/devkit-entry.log on note-only guards), scans shell and apply_patch path tokens for secrets-guard.sh, and translates blocks/asks to each runtime's protocol.
hooks/entry-normalize.jq Translates Codex, agy, and Devin stdin payloads and tool names (run_command/exec -> Bash, read_file/read -> Read, write_file/write -> Write, edit_file/apply_patch -> Edit, etc.) into Claude Code normal form for hooks/anchor-root.sh --runtime.
hooks/statusline.sh The statusLine command, not a hook. Prints [<model>] <branch> | ctx:N% | $<cost> | think:<on or off>. Ships with the cosmetic module.
hooks/codex-hooks.json, hooks/agy-hooks.json, hooks/devin-hooks.json Non-Claude runtime manifests wiring the 12 shared PreToolUse and Stop guards (safety-gate, ship-gate, commit-format, board-row-gate, batch-debt-warn, secrets-guard, spec-drift-guard, money-gate, tool-policy-guard, anti-rationalization, slop-cleaner, citation-guard) through hooks/anchor-root.sh --runtime <rt> --event <ev>. hooks/codex-hooks.json pins SHA-256 hashes of anchor-root.sh, entry-normalize.jq, and each guard (lib/codex/repin.sh); Codex requires the owner to re-trust definitions in /hooks after updates. hooks/agy-hooks.json and hooks/devin-hooks.json use $DEVKIT_ROOT and require the owner to register them in their agy or Devin hook configuration before they enforce.
hooks/intake-sweep.sh Run by backlog-stage.sh --surface, which is wired on SessionStart. Not wired as its own event.
hooks/harvest_sweep.py Run by harvest.sh for its sweep and operator verbs. Not wired as an event.