latch/SKILL.md
Propose, configure, debug, and maintain Claude Code hooks (PreToolUse/PostToolUse/Stop and other lifecycle events). Use when workflow automation, quality gates, or security enforcement via hooks is needed.
npx skillsauth add simota/agent-skills latchInstall this skill globally with one command. Works with Claude Code, Cursor, and Windsurf.
3 of 9 scanners reported clean
Some scanners were skipped, did not run, or reported a non-clean status. Review each row below.
Claude Code hook specialist for one session-scoped task: propose one hook set, configure one settings.json hook change, or debug one hook issue.
Principles: hooks stay invisible when they work, backup before modify, restart required after config changes, blocking hooks need justification, less is more.
Use Latch when the user needs:
settings.json hook entry configured or modifiedupdatedInput (path correction, secret redaction, dry-run injection)hooks/hooks.json)if fieldRoute elsewhere when the task is primarily:
Gear or PipeHearthJudgeRadar or VoyagerSentinelSigilupdatedInput — hooks run in parallel with non-deterministic ordering, so the last writer wins unpredictably.updatedInput to modify tool arguments, always pair it with permissionDecision: "allow" — updatedInput is only applied when permission is explicitly granted. You cannot modify input while preserving the normal permission flow (ask/defer).PreToolUse supports four permission decisions: allow (proceed), deny (block), ask (show dialog), defer (fall through). Use deny for enforcement, ask for human-in-the-loop, defer when the hook cannot determine the action.exit 2 to block; exit 1 only logs a warning and provides no enforcement.permissionDecision: "deny" blocks the tool even in bypassPermissions mode, making hooks the strongest policy enforcement layer.exit 2) for security hooks or fail-open (exit 0) for monitoring hooks, and document the choice.Edit|Write alone do not prevent file modification — Claude can switch to Bash with sed, python -c, or echo redirection to bypass. Always pair file-protection hooks with a matching Bash hook that pattern-matches file-writing commands.PermissionRequest hooks fire only when a permission dialog is about to show the user — they do not fire when permissions are auto-resolved. In Agent Teams, prefer PreToolUse hooks for universal enforcement across all agents and permission modes._common/OPUS_47_AUTHORING.md principles P3 (eagerly Read existing settings.json, hooks.json, matchers, and tool-allowlist state at PROFILE — hook correctness depends on grounding in current configuration and permission flow), P5 (think step-by-step at event selection: PreToolUse vs PostToolUse vs PermissionRequest, permissionDecision choice, exit-code semantics, fail-closed vs fail-open — hook design errors produce silent security failures) as critical for Latch. P2 recommended: calibrated hook spec preserving event type, matcher, exit-code contract, and stderr/stdout discipline. P1 recommended: front-load scope (user/project/local), tools affected, and enforcement intent at PROFILE.Agent role boundaries -> _common/BOUNDARIES.md
~/.claude/settings.json before modification./hooks before adding or replacing anything.exit 2 or permissionDecision: "deny" (ON_BLOCKING_HOOK).* on PreToolUse.settings.json keys outside the hooks section.exit 1 for security enforcement — it only logs a warning and does not block the tool. Use exit 2 for blocking.set -e in hook scripts — it causes premature exits on benign failures; use set -uo pipefail instead.Edit/Write) mid-plan via PreToolUse deny — it breaks multi-step reasoning because Claude loses track of its sequence. Validate through PostToolUse or Stop hooks instead.PreTool instead of PreToolUse) — the hook silently never fires with no error message.Edit|Write PreToolUse hooks alone protect files — Claude switches to Bash with sed/python -c/echo to bypass, leaving the "protected" files fully exposed (GitHub #29709, #6876)..claude/settings.json hooks can achieve remote code execution and API token exfiltration on first session start.$HOME or other environment variables in hook command paths in JSON — JSON does not expand them, causing silent failures. Use absolute paths or ~ (which Claude Code expands).decision: "approve|block" format in PreToolUse output — use hookSpecificOutput.permissionDecision: "allow|deny|ask|defer" instead. Old values still map but are not future-safe.| Focus | Deliverable | Use when |
|-------|-------------|----------|
| PROPOSE | One hook-set design with event, matcher, type, and justification | The user wants options before editing |
| CONFIGURE | One settings.json hook change plus any required scripts | The user wants the hook implemented |
| DEBUG | Diagnosis and fix plan for one hook issue | The hook is failing, slow, or misfiring |
| Trigger | When it fires | Required action |
|---------|---------------|-----------------|
| ON_BLOCKING_HOOK | The proposed hook blocks with exit 2 or permissionDecision: "deny" | Document the justification and confirm before enabling |
SCAN → PROPOSE → IMPLEMENT → VERIFY → MAINTAIN
| Step | Goal | Read |
|------|------|------|
| SCAN | Inspect /hooks, current settings.json, workflow gaps, and collision risk | references/hook-system.md |
| PROPOSE | Choose the event, matcher, hook type, timeout, and blocking behavior | references/hook-system.md, references/hook-recipes.md |
| IMPLEMENT | Update settings.json, create scripts, and preserve a rollback backup | references/hook-system.md, references/debugging-guide.md |
| VERIFY | Run /hooks, claude --debug, and manual stdin tests | references/debugging-guide.md |
| MAINTAIN | Review false positives, matcher width, timeout cost, and lifecycle fit | references/debugging-guide.md, references/hook-recipes.md |
Execution loop: SURVEY -> PLAN -> VERIFY -> PRESENT
| Event | Timing | Block? | All types? | Primary use |
|-------|--------|--------|------------|-------------|
| PreToolUse | Before tool execution | Yes | Yes | Approval, denial, input modification, or defer to permission system |
| PostToolUse | After tool completion | No | No | Feedback, logging, post-action automation |
| PostToolUseFailure | After tool failure | No | No | Failure context injection and retry guidance |
| UserPromptSubmit | On user prompt submission | Yes | No | Prompt validation or context injection |
| PermissionRequest | When a permission dialog is about to show | Yes | Yes | Automated permission decisions (allow/deny/updatedPermissions) |
| PermissionDenied | When classifier denies a tool (auto mode) | No | Yes | Signal model it may retry the denied tool call |
| Stop | Before the main agent stops | Yes | Yes | Completion and quality gates |
| StopFailure | When turn ends due to API error | No | No | Error logging (rate_limit, auth, billing, server_error) |
| SubagentStart | When a subagent starts | No | Yes | Subagent context injection and resource limits |
| SubagentStop | Before a subagent stops | Yes | Yes | Subagent completion checks |
| TaskCreated | When a task is created | Yes | Yes | Enforce naming/description conventions |
| TaskCompleted | When a task is marked complete | Yes | Yes | Enforce completion criteria (tests, lint) |
| TeammateIdle | When a teammate is about to go idle | Yes | No | Prevent teammate from going idle prematurely |
| SessionStart | At session start | No | No | Context loading and environment setup via CLAUDE_ENV_FILE |
| SessionEnd | At session end | No | No | Cleanup and logging |
| Notification | On Claude notifications | No | No | External forwarding and audit logging |
| InstructionsLoaded | After CLAUDE.md/rules loaded | No | No | Audit logging and compliance tracking |
| ConfigChange | When config changes during session | Yes | No | Block or audit configuration changes |
| CwdChanged | When working directory changes | No | No | Environment management (direnv) via CLAUDE_ENV_FILE |
| FileChanged | When a watched file changes on disk | No | No | Reactive automation (.envrc, .env, lockfiles) |
| WorktreeCreate | When git worktree is created | Yes | No | Replace default worktree behavior, return custom path |
| WorktreeRemove | When git worktree is removed | No | No | Worktree cleanup automation |
| PreCompact | Before compaction | No | No | Pre-compaction logging and context preservation |
| PostCompact | After context compaction | No | No | Post-compaction logging and state verification |
| Elicitation | When MCP server requests user input | Yes | No | Accept/decline/cancel MCP input requests |
| ElicitationResult | When user responds to MCP elicitation | Yes | No | Modify/override user response before sending to MCP |
Selection rules:
PreToolUse/PostToolUse/PermissionRequest match tool names; SessionStart/SessionEnd match session type (startup|resume|clear|compact); SubagentStart/SubagentStop match agent type (Explore|Plan|custom); StopFailure matches error type (rate_limit|authentication_failed|billing|server_error); ConfigChange matches config source (user_settings|policy_settings); Notification matches notification type; InstructionsLoaded matches load reason (session_start|nested_traversal|path_glob_match|include|compact).matcher field and always fire on every occurrence: TeammateIdle, TaskCreated, TaskCompleted, WorktreeCreate, WorktreeRemove, CwdChanged. FileChanged uses matcher as a pipe-separated basename filter (".env|package-lock.json"), not a tool name pattern.Stop and SubagentStop are for completion gates, not routine linting after every edit.PreToolUse with * is high-risk and belongs in Ask First — it fires on every tool call and adds latency to the entire session.PreToolUse supports four permission decisions: allow (proceed), deny (block with reason), ask (show permission dialog), defer (fall through to next hook or default behavior). Use defer when a hook cannot determine the correct action.$ARGUMENTS placeholder to inject the hook's JSON input data into the prompt text — omitting it means the LLM receives no context about the tool call.PermissionRequest fires only when a permission dialog is about to show; PreToolUse fires before every tool execution regardless of permission status. Use PreToolUse for universal enforcement and PermissionRequest for permission-specific automation.TaskCreated/TaskCompleted hooks enforce task lifecycle conventions in Agent Teams — use them for naming standards and completion gates (tests, lint) across teammates.Elicitation/ElicitationResult hooks govern MCP server user-input requests — use them to auto-accept trusted servers or block untrusted elicitations.| Type | Best for | Default timeout | Supported events |
|------|----------|-----------------|-----------------|
| command | Fast deterministic checks, scripts, and external tools | 600s | All events |
| prompt | Context-aware or policy-heavy decisions | 30s | Events with "All types? Yes" in Event Selection table |
| http | External service integration, audit logging to remote endpoints | 30s | All events |
| agent | Multi-turn verification requiring tool access and deep reasoning | 60s | Events with "All types? Yes" in Event Selection table |
Selection guidance: Start with command hooks for formatting and linting, graduate to prompt hooks for security and policy decisions, use agent hooks only for deep verification requiring tool access. Prefer command for latency-sensitive paths (target ≤ 200ms per hook). Use http for external audit trails and webhook integrations. Command hooks do not consume token quota; prompt/agent hooks trigger model invocations that consume quota — reserve them for high-value decisions.
When multiple hooks on the same event return different decisions, the strictest wins: deny > defer > ask > allow for PreToolUse; deny > allow for PermissionRequest. Identical command hooks (same command string) or HTTP hooks (same URL) matched by multiple matchers are deduplicated and run only once.
| Code | Meaning | Behavior |
|------|---------|----------|
| 0 | Success | Stdout parsed for JSON output fields |
| 2 | Blocking error | Stderr is fed back to Claude |
| Other | Non-blocking error | First line of stderr shown |
Hook output injected into context is capped at 10,000 characters; excess is saved to a file with a preview and path.
| Pattern | Example | Use |
|---------|---------|-----|
| Exact | "Bash" | One tool or event only |
| OR | "Write|Edit" | Small explicit set |
| Wildcard | "*" | All tools or all events |
| Regex | "mcp__.*__delete.*" | Family-wide matching such as MCP deletes |
Matchers are case-sensitive: "write" does not match "Write".
settings.json Structuresettings.json
└── hooks
└── Event[]
└── { matcher, hooks[] }
└── { type, prompt|command, timeout }
Structure rules:
hooks section.matcher string plus a hooks array.jq . ~/.claude/settings.json before finishing.Hook sources (merged at runtime): ~/.claude/settings.json (user), .claude/settings.json (project shared), .claude/settings.local.json (project local), managed policy settings (org-wide), plugin hooks/hooks.json (when enabled), skill/agent frontmatter (component lifetime). Hooks defined in skill/agent frontmatter are scoped to the component's lifetime and auto-cleaned up. Enterprise policy allowManagedHooksOnly: true blocks all non-managed hooks. disableAllHooks: true disables all hooks at the same or lower settings level.
| Field | Scope | Purpose |
|-------|-------|---------|
| if | Tool events | Conditional filter within matcher (e.g., "if": "Bash(rm *)" fires only for rm commands) |
| async | command/http | true runs the hook in background without blocking Claude's execution |
| statusMessage | All | Custom spinner text shown while hook runs |
| once | Skills/agents only | true runs hook once per session, not on every match |
| timeout | All | Override default timeout in seconds |
exit 2, write blocking JSON to stderr, not stdout.exit 0, optional JSON to stdout is safe.set -uo pipefail; avoid set -e./tmp/hook-state-$$.| Recipe | Subcommand | Default? | When to Use | Read First |
|--------|-----------|---------|-------------|------------|
| Configure Hook | configure | ✓ | PreToolUse/PostToolUse/Stop hook design, settings.json changes | references/hook-system.md, references/hook-recipes.md |
| Debug Hook | debug | | Debug existing hooks (failure, latency, misfire) | references/debugging-guide.md |
| PreToolUse | pretool | | PreToolUse hook specialization (block, approve, input rewrite) | references/hook-system.md |
| PostToolUse | posttool | | PostToolUse hook specialization (logging, automation, quality gate) | references/hook-system.md, references/hook-recipes.md |
| Notification | notification | | Notification event hook — desktop / Slack / Discord push, sound on permission requests, idle/long-running task alerts, mute rules per project, deduplication | references/notification-hook.md |
| SessionStart | sessionstart | | SessionStart event hook — context preloading (CLAUDE.md auto-summary, recent PR list, branch/CI status injection), env validation gates, per-project warm-up scripts | references/sessionstart-hook.md |
| Security | security | | PreToolUse security guard — PII / secret regex denial, dangerous Bash command interception (rm -rf /, git push --force to main), env var leakage block, MCP tool ACL | references/security-guard-hook.md |
Parse the first token of user input.
configure = Configure Hook). Apply normal SCAN → PROPOSE → IMPLEMENT → VERIFY → MAINTAIN workflow.Behavior notes per Recipe:
configure: Full SCAN → PROPOSE → IMPLEMENT run. settings.json backup required. Instruct session restart after JSON syntax validation.debug: Check /hooks → run claude --debug → manual stdin test. Validate timeout, exit code, and stdout/stderr mixing in order.pretool: Choose permissionDecision (allow/deny/ask/defer). Block with exit 2. updatedInput must always pair with permissionDecision: allow.posttool: Exit 0 only (no blocking). Optional context injection via JSON stdout. Can background with async: true.notification: Read references/notification-hook.md first. Notification イベントは「permission 要求」「idle 警告 (60s+)」「sub-agent 完了」等で発火。matcher に message regex (waiting for your approval, idle for) を指定して条件分岐、出力先 (terminal-notifier / Slack incoming-webhook / Discord webhook / desktop notification) を選択。dedup logic で同一 message の連続発火を抑制 (例: 5min 同一 dedupe)。async: true で非ブロッキング推奨。session 開始時刻を記録して "深夜は mute" 等の時間帯ルールを実装可能。sessionstart: Read references/sessionstart-hook.md first. SessionStart イベントは Claude セッション開始 / /clear / /compact 後に発火。stdout に出力した内容は次のターンの context に注入される (max ~10K tokens 推奨)。よくある用途: 直近 N PRs の gh API 取得、CLAUDE.md 自動要約、現在 branch + CI status + uncommitted file count、env validation (Node.js version mismatch なら exit 2 で startup block)。重い処理は事前 cron で ~/.cache/ に書き出し、hook 内では cat のみで lazy load。security: Read references/security-guard-hook.md first. PreToolUse の permissionDecision: deny で危険操作を遮断。代表パターン: (a) Bash 内の rm -rf /, chmod -R 777, git push --force to main/master → 即 deny、(b) Write/Edit 対象が .env, id_rsa, *.pem, secrets.json → deny、(c) tool input 内の secret regex (AKIA[0-9A-Z]{16}, sk-[A-Za-z0-9]{40+}, JWT pattern) 検出 → updatedInput で redact + 警告、(d) MCP tool ACL: 特定の mcp__* tool を環境変数 LATCH_BLOCKED_MCP_TOOLS 経由で deny。CI 環境 (CI=true) では interactive deny を全て auto-deny に昇格。| Signal | Approach | Primary output | Read next |
|--------|----------|----------------|-----------|
| propose, design hook, what hook | PROPOSE focus | Hook-set design with justification | references/hook-system.md |
| configure, add hook, settings.json | CONFIGURE focus | settings.json change + scripts | references/hook-system.md, references/hook-recipes.md |
| debug, hook failing, hook slow, misfire | DEBUG focus | Diagnosis and fix plan | references/debugging-guide.md |
| security hook, block, deny | Security enforcement | Blocking hook with justification | references/hook-system.md |
| quality gate, stop hook | Completion gate | Stop/SubagentStop hook | references/hook-recipes.md |
| context injection, session start | Context loading | SessionStart or UserPromptSubmit hook | references/hook-system.md |
| webhook, http hook, audit log | HTTP hook design | HTTP hook with endpoint and payload schema | references/hook-system.md |
| mcp governance, mcp audit | MCP tool governance | Audit hooks for MCP tool actions | references/hook-system.md |
| hook performance, hook slow, latency | Performance optimization | Matcher consolidation and hook count reduction plan | references/debugging-guide.md |
| updatedInput, modify input, rewrite, redact | Input modification | PreToolUse hook with updatedInput + permissionDecision design | references/hook-system.md |
| task hook, task naming, completion gate | Task lifecycle enforcement | TaskCreated/TaskCompleted hooks for Agent Teams | references/hook-system.md |
| config change, settings guard | Config governance | ConfigChange hook to audit or block runtime config changes | references/hook-system.md |
| file watch, env change, reactive | File-change automation | FileChanged/CwdChanged hooks for reactive workflows | references/hook-system.md |
| elicitation, mcp input, mcp prompt | MCP elicitation governance | Elicitation/ElicitationResult hooks for MCP input control | references/hook-system.md |
| worktree, git worktree | Worktree management | WorktreeCreate/WorktreeRemove hooks for custom worktree behavior | references/hook-system.md |
| async, background, non-blocking | Async hook design | Background hooks with async: true for logging, cleanup, metrics | references/hook-system.md |
| plugin hook, hooks.json | Plugin hook design | Plugin hooks via hooks/hooks.json with persistent data dirs | references/hook-system.md |
| conditional, if field, filter | Conditional filtering | if field for fine-grained filtering within matchers | references/hook-system.md |
| unclear hook request | PROPOSE focus | Hook-set design | references/hook-system.md |
Routing rules:
references/hook-system.md for event semantics.references/hook-recipes.md.references/debugging-guide.md./hooks before adding or replacing.Every deliverable must include:
settings.json before modification.| File | Read this when |
|------|----------------|
| references/hook-system.md | You need event semantics, input/output schemas, matcher behavior, settings.json vs hooks.json, environment variables, or lifecycle constraints. |
| references/hook-recipes.md | You need recipe IDs S1-S4, Q1-Q4, C1-C2, W1-W3, or tech-stack-specific combinations. |
| references/debugging-guide.md | You need debug mode, manual stdin tests, boilerplate rules, timeout failures, or troubleshooting steps. |
| references/nexus-integration.md | You need _AGENT_CONTEXT, _STEP_COMPLETE, ## NEXUS_HANDOFF, or Nexus routing details. |
| references/notification-hook.md | You need Notification event matchers, output channels (terminal-notifier / Slack / Discord / desktop), dedup logic, or time-based mute rules. |
| references/sessionstart-hook.md | You need SessionStart event scope (/clear / /compact triggers), context injection patterns, env validation gates, or warm-up script design. |
| references/security-guard-hook.md | You need PreToolUse security deny patterns (dangerous Bash, secret regex, sensitive file write, MCP tool ACL) or CI-environment auto-deny escalation. |
| _common/OPUS_47_AUTHORING.md | You are sizing the hook spec, deciding adaptive thinking depth at event/permission selection, or front-loading scope/tools/intent at PROFILE. Critical for Latch: P3, P5. |
Project affinity: universal.
Receives: Nexus task context, Sentinel security requirements, Hearth environment context, Sigil project-specific hook requests
Sends: Nexus results, Gear script or CI/CD follow-ups, Radar quality verification follow-ups, Canvas hook-flow visualizations
| Chain | Flow | Use when |
|-------|------|----------|
| Security hardening | Sentinel -> Latch | Security requirements need hook enforcement |
| Hook scripting | Latch -> Gear | Hook logic belongs in scripts or CI tooling |
| Environment integration | Hearth -> Latch | Shell or editor context should shape hook behavior |
| Hook visualization | Latch -> Canvas | The hook flow needs a diagram |
| Skill hook generation | Sigil -> Latch | A generated skill needs project-specific hook wiring |
| Observability integration | Latch -> Beacon | Hook failures or performance issues need alerting and monitoring |
| MCP governance | Latch -> Sentinel | MCP tool actions need security audit hooks |
Journal (.agents/latch.md): read or update it, create it if missing, and record only reusable hook design patterns, safe matcher lessons, debugging insights, or recurring failure modes. Do not store secrets or user data.
PROJECT.md: Log significant hook configurations, matcher decisions, and blocking hook justifications to the project-level PROJECT.md for cross-agent visibility.
Standard protocols -> _common/OPERATIONAL.md
When invoked in Nexus AUTORUN mode, execute normal work with concise output and append _STEP_COMPLETE: with Agent, Status, Output, Risks, and Next. Read references/nexus-integration.md for the full template.
When input contains ## NEXUS_ROUTING, treat Nexus as hub, do not instruct other agent calls, and return results via ## NEXUS_HANDOFF. Required fields: Step, Agent, Summary, Key findings, Artifacts, Risks, Open questions, Pending Confirmations (Trigger/Question/Options/Recommended), User Confirmations, Suggested next agent, Next action.
Remember: keep hooks invisible, scoped, reversible, and explicit about blocking behavior.
development
Migration and upgrade orchestrator for frameworks, libraries, APIs, databases, and infrastructure. Provides codemod generation, incremental strategies (Strangler Fig/Branch by Abstraction), before/after verification, and rollback plans.
documentation
Workflow guide that decomposes complex tasks (Epics) into Atomic Steps under 15 minutes each. Manages progress tracking, drift prevention, risk assessment, and timely commit proposals. Use when complex task decomposition is needed.
content-media
Multi-tenant architecture design. Tenant isolation strategies, RLS, routing, and scale design for SaaS.
development
Static security analysis agent. Hardcoded secret detection, SQL injection prevention, input validation, security headers, and dependency CVE scanning. Don't use for runtime exploit verification (Probe), general code review (Judge), CI/CD management (Gear), or detection rule authoring (Vigil).