Skip to content

Commit a1a06f7

Browse files
infracoreclaude
andcommitted
LED-234: Document conditional hook patterns for Claude Code
Add section showing if field usage for PreToolUse and PreCommit hooks with path_matches and input_contains conditions. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent 99210d9 commit a1a06f7

File tree

1 file changed

+49
-0
lines changed

1 file changed

+49
-0
lines changed

hooks/index.html

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,55 @@ <h2>PATH Shim Integration</h2>
6161
<pre><code>delimit activate
6262
# Adds ~/.delimit/shims to PATH via shell profile</code></pre>
6363

64+
<h2>Conditional Hooks (Claude Code)</h2>
65+
<p>Claude Code supports an <code>if</code> field on hooks that lets Delimit fire governance checks only when they matter. This keeps hooks invisible during normal coding and active only when API specs are touched.</p>
66+
67+
<h3>PreToolUse: Lint only on spec edits</h3>
68+
<p>This hook fires only when an Edit or Write targets an OpenAPI or Swagger file:</p>
69+
<pre><code>{
70+
"hooks": {
71+
"PreToolUse": [
72+
{
73+
"type": "command",
74+
"command": "npx delimit-cli hook pre-tool $TOOL_NAME",
75+
"matcher": "Edit|Write",
76+
"if": "Edit && (path_matches('**/openapi*') || path_matches('**/swagger*') || path_matches('**/*.yaml') || path_matches('**/*.yml'))"
77+
}
78+
]
79+
}
80+
}</code></pre>
81+
82+
<h3>PreToolUse: Governance on commit/push</h3>
83+
<p>This hook fires only when a Bash command contains <code>git commit</code> or <code>git push</code>:</p>
84+
<pre><code>{
85+
"hooks": {
86+
"PreToolUse": [
87+
{
88+
"type": "command",
89+
"command": "npx delimit-cli hook pre-commit",
90+
"matcher": "Bash",
91+
"if": "Bash && (input_contains('git commit') || input_contains('git push'))"
92+
}
93+
]
94+
}
95+
}</code></pre>
96+
97+
<h3>SessionStart: No condition needed</h3>
98+
<p>The session-start hook always fires to show governance status and ledger context:</p>
99+
<pre><code>{
100+
"hooks": {
101+
"SessionStart": [
102+
{
103+
"type": "command",
104+
"command": "npx delimit-cli hook session-start"
105+
}
106+
]
107+
}
108+
}</code></pre>
109+
110+
<h3>Automatic installation</h3>
111+
<p>Running <code>delimit setup</code> or <code>delimit activate</code> installs these conditional hooks automatically. Existing hooks without <code>if</code> conditions are upgraded in place.</p>
112+
64113
<h2>Cross-Model Compatibility</h2>
65114
<p>Hooks work the same way regardless of whether changes are made by:</p>
66115
<ul>

0 commit comments

Comments
 (0)