claude_hooks 1.1.0 → 1.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.agents/skills/ci-monitoring/SKILL.md +103 -0
- data/.agents/skills/run-tests/SKILL.md +45 -0
- data/.claude/settings.local.json +21 -0
- data/AGENTS.md +46 -0
- data/CHANGELOG.md +43 -0
- data/README.md +156 -21
- data/docs/API/COMMON.md +7 -1
- data/docs/API/CONFIG_CHANGE.md +39 -0
- data/docs/API/CWD_CHANGED.md +34 -0
- data/docs/API/ELICITATION.md +44 -0
- data/docs/API/ELICITATION_RESULT.md +43 -0
- data/docs/API/FILE_CHANGED.md +37 -0
- data/docs/API/INSTRUCTIONS_LOADED.md +30 -0
- data/docs/API/MESSAGE_DISPLAY.md +38 -0
- data/docs/API/PERMISSION_DENIED.md +37 -0
- data/docs/API/PERMISSION_REQUEST.md +11 -8
- data/docs/API/POST_COMPACT.md +30 -0
- data/docs/API/POST_TOOL_BATCH.md +39 -0
- data/docs/API/POST_TOOL_USE_FAILURE.md +31 -0
- data/docs/API/PRE_COMPACT.md +10 -2
- data/docs/API/PRE_TOOL_USE.md +5 -1
- data/docs/API/SETUP.md +37 -0
- data/docs/API/STOP_FAILURE.md +19 -0
- data/docs/API/SUBAGENT_START.md +40 -0
- data/docs/API/TASK_COMPLETED.md +43 -0
- data/docs/API/TASK_CREATED.md +43 -0
- data/docs/API/TEAMMATE_IDLE.md +40 -0
- data/docs/API/USER_PROMPT_EXPANSION.md +43 -0
- data/docs/API/WORKTREE_CREATE.md +39 -0
- data/docs/API/WORKTREE_REMOVE.md +33 -0
- data/docs/PROMPT_BASED_HOOKS.md +386 -0
- data/docs/external/claude-hooks-reference.md +2406 -854
- data/docs/mitts/ideabox.md +12 -0
- data/docs/mitts/prd.md +417 -0
- data/docs/mitts/setup.md +303 -0
- data/docs/mitts/task.md +44 -0
- data/lib/claude_hooks/base.rb +25 -0
- data/lib/claude_hooks/config_change.rb +28 -0
- data/lib/claude_hooks/cwd_changed.rb +28 -0
- data/lib/claude_hooks/elicitation.rb +61 -0
- data/lib/claude_hooks/elicitation_result.rb +57 -0
- data/lib/claude_hooks/file_changed.rb +41 -0
- data/lib/claude_hooks/instructions_loaded.rb +23 -0
- data/lib/claude_hooks/message_display.rb +58 -0
- data/lib/claude_hooks/output/base.rb +46 -1
- data/lib/claude_hooks/output/config_change.rb +47 -0
- data/lib/claude_hooks/output/cwd_changed.rb +42 -0
- data/lib/claude_hooks/output/elicitation.rb +67 -0
- data/lib/claude_hooks/output/elicitation_result.rb +63 -0
- data/lib/claude_hooks/output/file_changed.rb +42 -0
- data/lib/claude_hooks/output/instructions_loaded.rb +19 -0
- data/lib/claude_hooks/output/message_display.rb +49 -0
- data/lib/claude_hooks/output/permission_denied.rb +42 -0
- data/lib/claude_hooks/output/permission_request.rb +50 -25
- data/lib/claude_hooks/output/post_compact.rb +18 -0
- data/lib/claude_hooks/output/post_tool_batch.rb +51 -0
- data/lib/claude_hooks/output/post_tool_use.rb +12 -0
- data/lib/claude_hooks/output/post_tool_use_failure.rb +42 -0
- data/lib/claude_hooks/output/pre_compact.rb +34 -3
- data/lib/claude_hooks/output/pre_tool_use.rb +8 -2
- data/lib/claude_hooks/output/session_start.rb +30 -8
- data/lib/claude_hooks/output/setup.rb +42 -0
- data/lib/claude_hooks/output/stop.rb +15 -0
- data/lib/claude_hooks/output/stop_failure.rb +19 -0
- data/lib/claude_hooks/output/subagent_start.rb +42 -0
- data/lib/claude_hooks/output/task_completed.rb +18 -0
- data/lib/claude_hooks/output/task_created.rb +18 -0
- data/lib/claude_hooks/output/teammate_idle.rb +18 -0
- data/lib/claude_hooks/output/user_prompt_expansion.rb +51 -0
- data/lib/claude_hooks/output/worktree_create.rb +60 -0
- data/lib/claude_hooks/output/worktree_remove.rb +19 -0
- data/lib/claude_hooks/permission_denied.rb +41 -0
- data/lib/claude_hooks/permission_request.rb +16 -9
- data/lib/claude_hooks/post_compact.rb +23 -0
- data/lib/claude_hooks/post_tool_batch.rb +59 -0
- data/lib/claude_hooks/post_tool_use.rb +10 -0
- data/lib/claude_hooks/post_tool_use_failure.rb +45 -0
- data/lib/claude_hooks/pre_compact.rb +7 -0
- data/lib/claude_hooks/pre_tool_use.rb +20 -2
- data/lib/claude_hooks/session_start.rb +28 -0
- data/lib/claude_hooks/setup.rb +25 -0
- data/lib/claude_hooks/stop.rb +17 -0
- data/lib/claude_hooks/stop_failure.rb +27 -0
- data/lib/claude_hooks/subagent_start.rb +23 -0
- data/lib/claude_hooks/subagent_stop.rb +5 -1
- data/lib/claude_hooks/task_completed.rb +35 -0
- data/lib/claude_hooks/task_created.rb +35 -0
- data/lib/claude_hooks/teammate_idle.rb +23 -0
- data/lib/claude_hooks/user_prompt_expansion.rb +45 -0
- data/lib/claude_hooks/version.rb +1 -1
- data/lib/claude_hooks/worktree_create.rb +27 -0
- data/lib/claude_hooks/worktree_remove.rb +19 -0
- data/lib/claude_hooks.rb +40 -0
- metadata +71 -2
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
# Elicitation API
|
|
2
|
+
|
|
3
|
+
Available when inheriting from `ClaudeHooks::Elicitation`:
|
|
4
|
+
|
|
5
|
+
Runs when an MCP server requests user input (an elicitation dialog). Can accept, decline, or cancel the request.
|
|
6
|
+
|
|
7
|
+
## Input Helpers
|
|
8
|
+
|
|
9
|
+
[📚 Shared input helpers](COMMON.md#input-helpers)
|
|
10
|
+
|
|
11
|
+
| Method | Description |
|
|
12
|
+
|--------|-------------|
|
|
13
|
+
| `mcp_server_name` | The MCP server requesting input |
|
|
14
|
+
| `message` | The message / prompt shown to the user |
|
|
15
|
+
| `mode` | Optional interaction mode |
|
|
16
|
+
| `url` | Optional URL associated with the request |
|
|
17
|
+
| `elicitation_id` | Optional unique ID for this elicitation |
|
|
18
|
+
| `requested_schema` | Optional JSON schema describing the expected response |
|
|
19
|
+
|
|
20
|
+
## Hook State Helpers
|
|
21
|
+
|
|
22
|
+
[📚 Shared hook state methods](COMMON.md#hook-state-methods)
|
|
23
|
+
|
|
24
|
+
| Method | Description |
|
|
25
|
+
|--------|-------------|
|
|
26
|
+
| `accept!(content = {})` | Accept the elicitation with optional content hash |
|
|
27
|
+
| `decline!` | Decline the elicitation |
|
|
28
|
+
| `cancel!` | Cancel the elicitation |
|
|
29
|
+
|
|
30
|
+
## Output Helpers
|
|
31
|
+
|
|
32
|
+
[📚 Shared output helpers](COMMON.md#output-helpers)
|
|
33
|
+
|
|
34
|
+
| Method | Description |
|
|
35
|
+
|--------|-------------|
|
|
36
|
+
| `output.action` | Get the chosen action: `'accept'`, `'decline'`, or `'cancel'` |
|
|
37
|
+
| `output.content` | Get the accepted content hash |
|
|
38
|
+
| `output.accepted?` | Check if the elicitation was accepted |
|
|
39
|
+
| `output.declined?` | Check if the elicitation was declined |
|
|
40
|
+
| `output.cancelled?` | Check if the elicitation was cancelled |
|
|
41
|
+
|
|
42
|
+
## Hook Exit Codes
|
|
43
|
+
|
|
44
|
+
Uses the JSON API (exit 0 / stdout). The `hookSpecificOutput.action` field controls the response.
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
# ElicitationResult API
|
|
2
|
+
|
|
3
|
+
Available when inheriting from `ClaudeHooks::ElicitationResult`:
|
|
4
|
+
|
|
5
|
+
Runs after a user has responded to an elicitation dialog. Can override the action or content before it is sent back to the MCP server.
|
|
6
|
+
|
|
7
|
+
## Input Helpers
|
|
8
|
+
|
|
9
|
+
[📚 Shared input helpers](COMMON.md#input-helpers)
|
|
10
|
+
|
|
11
|
+
| Method | Description |
|
|
12
|
+
|--------|-------------|
|
|
13
|
+
| `mcp_server_name` | The MCP server that requested input |
|
|
14
|
+
| `action` | The user's chosen action: `'accept'`, `'decline'`, or `'cancel'` |
|
|
15
|
+
| `mode` | Optional interaction mode |
|
|
16
|
+
| `elicitation_id` | Optional unique ID for this elicitation |
|
|
17
|
+
| `content` | The content the user provided (for `'accept'` action) |
|
|
18
|
+
|
|
19
|
+
## Hook State Helpers
|
|
20
|
+
|
|
21
|
+
[📚 Shared hook state methods](COMMON.md#hook-state-methods)
|
|
22
|
+
|
|
23
|
+
| Method | Description |
|
|
24
|
+
|--------|-------------|
|
|
25
|
+
| `accept!(content = {})` | Override the response with an accept + content |
|
|
26
|
+
| `decline!` | Override the response to decline |
|
|
27
|
+
| `cancel!` | Override the response to cancel |
|
|
28
|
+
|
|
29
|
+
## Output Helpers
|
|
30
|
+
|
|
31
|
+
[📚 Shared output helpers](COMMON.md#output-helpers)
|
|
32
|
+
|
|
33
|
+
| Method | Description |
|
|
34
|
+
|--------|-------------|
|
|
35
|
+
| `output.action` | Get the (possibly overridden) action |
|
|
36
|
+
| `output.content` | Get the (possibly overridden) content |
|
|
37
|
+
| `output.accepted?` | Check if the action is `'accept'` |
|
|
38
|
+
| `output.declined?` | Check if the action is `'decline'` |
|
|
39
|
+
| `output.cancelled?` | Check if the action is `'cancel'` |
|
|
40
|
+
|
|
41
|
+
## Hook Exit Codes
|
|
42
|
+
|
|
43
|
+
Uses the JSON API (exit 0 / stdout).
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
# FileChanged API
|
|
2
|
+
|
|
3
|
+
Available when inheriting from `ClaudeHooks::FileChanged`:
|
|
4
|
+
|
|
5
|
+
Runs when a watched file is created, modified, or deleted. Can update the watch paths list.
|
|
6
|
+
|
|
7
|
+
## Input Helpers
|
|
8
|
+
|
|
9
|
+
[📚 Shared input helpers](COMMON.md#input-helpers)
|
|
10
|
+
|
|
11
|
+
| Method | Description |
|
|
12
|
+
|--------|-------------|
|
|
13
|
+
| `file_path` | The path of the changed file |
|
|
14
|
+
| `event` | The type of change: `'change'`, `'add'`, or `'unlink'` |
|
|
15
|
+
| `modified?` | Convenience: `event == 'change'` |
|
|
16
|
+
| `created?` | Convenience: `event == 'add'` |
|
|
17
|
+
| `deleted?` | Convenience: `event == 'unlink'` |
|
|
18
|
+
|
|
19
|
+
## Hook State Helpers
|
|
20
|
+
|
|
21
|
+
[📚 Shared hook state methods](COMMON.md#hook-state-methods)
|
|
22
|
+
|
|
23
|
+
| Method | Description |
|
|
24
|
+
|--------|-------------|
|
|
25
|
+
| `watch_paths!(paths)` | Update the list of paths Claude Code should watch |
|
|
26
|
+
|
|
27
|
+
## Output Helpers
|
|
28
|
+
|
|
29
|
+
[📚 Shared output helpers](COMMON.md#output-helpers)
|
|
30
|
+
|
|
31
|
+
| Method | Description |
|
|
32
|
+
|--------|-------------|
|
|
33
|
+
| `output.watch_paths` | Get the configured watch paths |
|
|
34
|
+
|
|
35
|
+
## Hook Exit Codes
|
|
36
|
+
|
|
37
|
+
Non-blocking. Only `watchPaths` output is consumed.
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
# InstructionsLoaded API
|
|
2
|
+
|
|
3
|
+
Available when inheriting from `ClaudeHooks::InstructionsLoaded`:
|
|
4
|
+
|
|
5
|
+
Runs when a `CLAUDE.md` instructions file is loaded. Non-blocking — exit code is ignored.
|
|
6
|
+
|
|
7
|
+
## Input Helpers
|
|
8
|
+
|
|
9
|
+
[📚 Shared input helpers](COMMON.md#input-helpers)
|
|
10
|
+
|
|
11
|
+
| Method | Description |
|
|
12
|
+
|--------|-------------|
|
|
13
|
+
| `file_path` | Path to the loaded instructions file |
|
|
14
|
+
| `load_reason` | Why the file was loaded (e.g. `'startup'`, `'cwd_change'`) |
|
|
15
|
+
|
|
16
|
+
## Hook State Helpers
|
|
17
|
+
|
|
18
|
+
[📚 Shared hook state methods](COMMON.md#hook-state-methods)
|
|
19
|
+
|
|
20
|
+
No event-specific state methods — this hook is non-blocking.
|
|
21
|
+
|
|
22
|
+
## Output Helpers
|
|
23
|
+
|
|
24
|
+
[📚 Shared output helpers](COMMON.md#output-helpers)
|
|
25
|
+
|
|
26
|
+
No event-specific output helpers.
|
|
27
|
+
|
|
28
|
+
## Hook Exit Codes
|
|
29
|
+
|
|
30
|
+
Non-blocking. Exit code is ignored by Claude Code.
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
# MessageDisplay API
|
|
2
|
+
|
|
3
|
+
Available when inheriting from `ClaudeHooks::MessageDisplay`:
|
|
4
|
+
|
|
5
|
+
Runs when a message is about to be displayed. Can override the displayed text via `hookSpecificOutput.displayContent`.
|
|
6
|
+
|
|
7
|
+
## Input Helpers
|
|
8
|
+
|
|
9
|
+
[📚 Shared input helpers](COMMON.md#input-helpers)
|
|
10
|
+
|
|
11
|
+
| Method | Description |
|
|
12
|
+
|--------|-------------|
|
|
13
|
+
| `turn_id` | ID of the current turn |
|
|
14
|
+
| `message_id` | ID of this message |
|
|
15
|
+
| `index` | Position of this message in the turn |
|
|
16
|
+
| `final` | Whether this is the final message chunk (`true`/`false`) |
|
|
17
|
+
| `delta` | The incremental text content of this message |
|
|
18
|
+
| `message_text` | Alias for `delta` |
|
|
19
|
+
|
|
20
|
+
## Hook State Helpers
|
|
21
|
+
|
|
22
|
+
[📚 Shared hook state methods](COMMON.md#hook-state-methods)
|
|
23
|
+
|
|
24
|
+
| Method | Description |
|
|
25
|
+
|--------|-------------|
|
|
26
|
+
| `display_content!(text)` | Override the displayed text for this message |
|
|
27
|
+
|
|
28
|
+
## Output Helpers
|
|
29
|
+
|
|
30
|
+
[📚 Shared output helpers](COMMON.md#output-helpers)
|
|
31
|
+
|
|
32
|
+
| Method | Description |
|
|
33
|
+
|--------|-------------|
|
|
34
|
+
| `output.display_content` | Get the overridden display content (if set) |
|
|
35
|
+
|
|
36
|
+
## Hook Exit Codes
|
|
37
|
+
|
|
38
|
+
Exit code and output stream are ignored for MessageDisplay. The only honored output is `hookSpecificOutput.displayContent`.
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
# PermissionDenied API
|
|
2
|
+
|
|
3
|
+
Available when inheriting from `ClaudeHooks::PermissionDenied`:
|
|
4
|
+
|
|
5
|
+
Runs when a permission request is denied. Can request that Claude Code retries the request.
|
|
6
|
+
|
|
7
|
+
## Input Helpers
|
|
8
|
+
|
|
9
|
+
[📚 Shared input helpers](COMMON.md#input-helpers)
|
|
10
|
+
|
|
11
|
+
| Method | Description |
|
|
12
|
+
|--------|-------------|
|
|
13
|
+
| `tool_name` | The name of the tool whose permission was denied |
|
|
14
|
+
| `tool_input` | The input data for the tool |
|
|
15
|
+
| `tool_use_id` | The unique identifier for this tool use |
|
|
16
|
+
| `reason` | The reason the permission was denied |
|
|
17
|
+
|
|
18
|
+
## Hook State Helpers
|
|
19
|
+
|
|
20
|
+
[📚 Shared hook state methods](COMMON.md#hook-state-methods)
|
|
21
|
+
|
|
22
|
+
| Method | Description |
|
|
23
|
+
|--------|-------------|
|
|
24
|
+
| `retry!` | Request that Claude Code retry the permission request |
|
|
25
|
+
| `no_retry!` | Explicitly decline to retry (default) |
|
|
26
|
+
|
|
27
|
+
## Output Helpers
|
|
28
|
+
|
|
29
|
+
[📚 Shared output helpers](COMMON.md#output-helpers)
|
|
30
|
+
|
|
31
|
+
| Method | Description |
|
|
32
|
+
|--------|-------------|
|
|
33
|
+
| `output.retry?` | Check if a retry was requested |
|
|
34
|
+
|
|
35
|
+
## Hook Exit Codes
|
|
36
|
+
|
|
37
|
+
Exit code is ignored. Output is via `hookSpecificOutput.retry` (JSON API, exit 0 / stdout).
|
|
@@ -21,8 +21,8 @@ Hook state methods are helpers to modify the hook's internal state (`output_data
|
|
|
21
21
|
| Method | Description |
|
|
22
22
|
|--------|-------------|
|
|
23
23
|
| `allow_permission!(reason = '')` | Allow the permission request with optional reason |
|
|
24
|
-
| `deny_permission!(reason = '')` | Deny the permission request with reason |
|
|
25
|
-
| `update_input_and_allow!(updated_input, reason = '')` | Update tool input and allow
|
|
24
|
+
| `deny_permission!(reason = '', interrupt: nil)` | Deny the permission request with reason; pass `interrupt: true` to interrupt the current operation |
|
|
25
|
+
| `update_input_and_allow!(updated_input, reason = '', updated_permissions: nil)` | Update tool input and allow |
|
|
26
26
|
|
|
27
27
|
## Output Helpers
|
|
28
28
|
Output helpers provide access to the hook's output data and helper methods for working with the output state.
|
|
@@ -34,9 +34,12 @@ Output helpers provide access to the hook's output data and helper methods for w
|
|
|
34
34
|
| `output.allowed?` | Check if permission has been allowed |
|
|
35
35
|
| `output.denied?` | Check if permission has been denied |
|
|
36
36
|
| `output.input_updated?` | Check if tool input has been updated |
|
|
37
|
-
| `output.permission_decision` | Get the permission decision: 'allow' or 'deny' |
|
|
38
|
-
| `output.permission_reason` | Get the
|
|
39
|
-
| `output.updated_input` | Get the updated input (
|
|
37
|
+
| `output.permission_decision` | Get the permission decision: `'allow'` or `'deny'` (reads nested `decision.behavior`; falls back to legacy flat key) |
|
|
38
|
+
| `output.permission_reason` | Get the decision message (reads nested `decision.message`; falls back to legacy `permissionDecisionReason`) |
|
|
39
|
+
| `output.updated_input` | Get the updated input (reads nested `decision.updatedInput`; falls back to legacy flat key) |
|
|
40
|
+
| `output.behavior` | Get the raw `decision.behavior` value |
|
|
41
|
+
| `output.updated_permissions` | Get the `decision.updatedPermissions` array (if provided) |
|
|
42
|
+
| `output.interrupt?` | Check if `decision.interrupt` was set to true |
|
|
40
43
|
|
|
41
44
|
## Hook Exit Codes
|
|
42
45
|
|
|
@@ -167,8 +170,8 @@ end
|
|
|
167
170
|
When multiple PermissionRequest hooks are executed, their outputs merge with these rules:
|
|
168
171
|
|
|
169
172
|
- **Decision**: `deny` > `allow` (most restrictive wins)
|
|
170
|
-
- **Reasons**: All
|
|
171
|
-
- **Updated Input**: Last
|
|
173
|
+
- **Reasons**: All `decision.message` values are concatenated with `'; '`
|
|
174
|
+
- **Updated Input**: Last `decision.updatedInput` wins (most recent transformation)
|
|
172
175
|
|
|
173
176
|
```ruby
|
|
174
177
|
# Hook 1
|
|
@@ -193,4 +196,4 @@ merged.permission_reason # => "Reason 1; Reason 2"
|
|
|
193
196
|
- It can automatically allow or deny on behalf of the user
|
|
194
197
|
- Uses the same JSON API pattern as PreToolUse hooks
|
|
195
198
|
- Supports modifying tool inputs before execution
|
|
196
|
-
- Works with all permission modes: `default`, `plan`, `acceptEdits`, `dontAsk`, `bypassPermissions`
|
|
199
|
+
- Works with all permission modes: `default`, `plan`, `acceptEdits`, `auto`, `dontAsk`, `bypassPermissions`
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
# PostCompact API
|
|
2
|
+
|
|
3
|
+
Available when inheriting from `ClaudeHooks::PostCompact`:
|
|
4
|
+
|
|
5
|
+
Runs after transcript compaction completes. Non-blocking — use for logging or post-compaction side effects.
|
|
6
|
+
|
|
7
|
+
## Input Helpers
|
|
8
|
+
|
|
9
|
+
[📚 Shared input helpers](COMMON.md#input-helpers)
|
|
10
|
+
|
|
11
|
+
| Method | Description |
|
|
12
|
+
|--------|-------------|
|
|
13
|
+
| `trigger` | What triggered the compaction: `'auto'` or `'manual'` |
|
|
14
|
+
| `compact_summary` | The summary produced by the compaction |
|
|
15
|
+
|
|
16
|
+
## Hook State Helpers
|
|
17
|
+
|
|
18
|
+
[📚 Shared hook state methods](COMMON.md#hook-state-methods)
|
|
19
|
+
|
|
20
|
+
No event-specific state methods — this hook is non-blocking.
|
|
21
|
+
|
|
22
|
+
## Output Helpers
|
|
23
|
+
|
|
24
|
+
[📚 Shared output helpers](COMMON.md#output-helpers)
|
|
25
|
+
|
|
26
|
+
No event-specific output helpers.
|
|
27
|
+
|
|
28
|
+
## Hook Exit Codes
|
|
29
|
+
|
|
30
|
+
Non-blocking. Exit code is ignored.
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
# PostToolBatch API
|
|
2
|
+
|
|
3
|
+
Available when inheriting from `ClaudeHooks::PostToolBatch`:
|
|
4
|
+
|
|
5
|
+
Runs after a full batch of tool calls completes. Can block Claude from continuing.
|
|
6
|
+
|
|
7
|
+
## Input Helpers
|
|
8
|
+
|
|
9
|
+
[📚 Shared input helpers](COMMON.md#input-helpers)
|
|
10
|
+
|
|
11
|
+
| Method | Description |
|
|
12
|
+
|--------|-------------|
|
|
13
|
+
| `tool_calls` | Array of tool call results; each entry has `tool_name`, `tool_input`, `tool_use_id`, `tool_response` |
|
|
14
|
+
|
|
15
|
+
## Hook State Helpers
|
|
16
|
+
|
|
17
|
+
[📚 Shared hook state methods](COMMON.md#hook-state-methods)
|
|
18
|
+
|
|
19
|
+
| Method | Description |
|
|
20
|
+
|--------|-------------|
|
|
21
|
+
| `block!(reason)` | Block Claude from continuing after this batch |
|
|
22
|
+
| `add_additional_context!(context)` | Add additional context visible to Claude |
|
|
23
|
+
|
|
24
|
+
## Output Helpers
|
|
25
|
+
|
|
26
|
+
[📚 Shared output helpers](COMMON.md#output-helpers)
|
|
27
|
+
|
|
28
|
+
| Method | Description |
|
|
29
|
+
|--------|-------------|
|
|
30
|
+
| `output.blocked?` | Check if the batch was blocked |
|
|
31
|
+
| `output.decision` | Get the decision (`'block'` or nil) |
|
|
32
|
+
| `output.reason` | Get the block reason |
|
|
33
|
+
|
|
34
|
+
## Hook Exit Codes
|
|
35
|
+
|
|
36
|
+
| Exit Code | Behavior |
|
|
37
|
+
|-----------|----------|
|
|
38
|
+
| `exit 0` | Claude continues |
|
|
39
|
+
| `exit 2` | Blocks Claude; `STDERR` shown to Claude |
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
# PostToolUseFailure API
|
|
2
|
+
|
|
3
|
+
Available when inheriting from `ClaudeHooks::PostToolUseFailure`:
|
|
4
|
+
|
|
5
|
+
Runs when a tool call fails. Non-blocking — output and exit code are ignored except for `additionalContext`.
|
|
6
|
+
|
|
7
|
+
## Input Helpers
|
|
8
|
+
|
|
9
|
+
[📚 Shared input helpers](COMMON.md#input-helpers)
|
|
10
|
+
|
|
11
|
+
| Method | Description |
|
|
12
|
+
|--------|-------------|
|
|
13
|
+
| `tool_name` | The name of the tool that failed |
|
|
14
|
+
| `tool_input` | The input data for the tool |
|
|
15
|
+
| `tool_use_id` | The unique identifier for this tool use |
|
|
16
|
+
| `error` | The error message |
|
|
17
|
+
| `is_interrupt` | Whether the failure was caused by an interrupt (`true`/`false`) |
|
|
18
|
+
| `interrupt?` | Alias for `is_interrupt` |
|
|
19
|
+
| `duration_ms` | How long the tool ran before failing (milliseconds) |
|
|
20
|
+
|
|
21
|
+
## Hook State Helpers
|
|
22
|
+
|
|
23
|
+
[📚 Shared hook state methods](COMMON.md#hook-state-methods)
|
|
24
|
+
|
|
25
|
+
| Method | Description |
|
|
26
|
+
|--------|-------------|
|
|
27
|
+
| `add_additional_context!(context)` | Add additional context visible to Claude about the failure |
|
|
28
|
+
|
|
29
|
+
## Hook Exit Codes
|
|
30
|
+
|
|
31
|
+
Non-blocking. Exit code and output are ignored by Claude Code; only `additionalContext` is consumed.
|
data/docs/API/PRE_COMPACT.md
CHANGED
|
@@ -13,10 +13,13 @@ Input helpers to access the data provided by Claude Code through `STDIN`.
|
|
|
13
13
|
| `custom_instructions` | Get custom instructions (only available for manual trigger) |
|
|
14
14
|
|
|
15
15
|
## Hook State Helpers
|
|
16
|
-
No specific hook state methods are available to alter compaction behavior.
|
|
17
16
|
|
|
18
17
|
[📚 Shared hook state methods](COMMON.md#hook-state-methods)
|
|
19
18
|
|
|
19
|
+
| Method | Description |
|
|
20
|
+
|--------|-------------|
|
|
21
|
+
| `block!(reason)` | Block the compaction with a reason (top-level `decision: 'block'`) |
|
|
22
|
+
|
|
20
23
|
## Utility Methods
|
|
21
24
|
Utility methods for transcript management.
|
|
22
25
|
|
|
@@ -26,10 +29,15 @@ Utility methods for transcript management.
|
|
|
26
29
|
|
|
27
30
|
## Output Helpers
|
|
28
31
|
Output helpers provide access to the hook's output data and helper methods for working with the output state.
|
|
29
|
-
PreCompact hooks don't have any specific hook state and thus doesn't have any specific output helpers.
|
|
30
32
|
|
|
31
33
|
[📚 Shared output helpers](COMMON.md#output-helpers)
|
|
32
34
|
|
|
35
|
+
| Method | Description |
|
|
36
|
+
|--------|-------------|
|
|
37
|
+
| `output.blocked?` | Check if the compaction was blocked |
|
|
38
|
+
| `output.decision` | Get the decision (`'block'` or nil) |
|
|
39
|
+
| `output.reason` | Get the block reason |
|
|
40
|
+
|
|
33
41
|
## Hook Exit Codes
|
|
34
42
|
|
|
35
43
|
| Exit Code | Behavior |
|
data/docs/API/PRE_TOOL_USE.md
CHANGED
|
@@ -23,7 +23,10 @@ Hook state methods are helpers to modify the hook's internal state (`output_data
|
|
|
23
23
|
| `approve_tool!(reason)` | Explicitly approve tool usage |
|
|
24
24
|
| `block_tool!(reason)` | Block tool usage with feedback |
|
|
25
25
|
| `ask_for_permission!(reason)` | Request user permission |
|
|
26
|
+
| `defer_permission!` | Defer the permission decision to a later hook in the chain |
|
|
26
27
|
| `update_tool_input!(updated_input)` | Update the tool input and automatically approve the tool (sets `permissionDecision` to `'allow'`) |
|
|
28
|
+
| `update_input!(updated_input)` | Update `updatedInput` without changing the permission decision |
|
|
29
|
+
| `add_additional_context!(context)` | Add additional context visible to Claude |
|
|
27
30
|
|
|
28
31
|
## Output Helpers
|
|
29
32
|
Output helpers provide access to the hook's output data and helper methods for working with the output state.
|
|
@@ -35,9 +38,10 @@ Output helpers provide access to the hook's output data and helper methods for w
|
|
|
35
38
|
| `output.allowed?` | Check if the tool has been explicitly allowed (permission_decision == 'allow') |
|
|
36
39
|
| `output.denied?` | Check if the tool has been denied (permission_decision == 'deny') |
|
|
37
40
|
| `output.blocked?` | Alias for `denied?` |
|
|
41
|
+
| `output.deferred?` | Check if the permission decision was deferred (permission_decision == 'defer') |
|
|
38
42
|
| `output.should_ask_permission?` | Check if user permission is required (permission_decision == 'ask') |
|
|
39
43
|
| `output.input_updated?` | Check if tool input has been updated |
|
|
40
|
-
| `output.permission_decision` | Get the permission decision: 'allow'
|
|
44
|
+
| `output.permission_decision` | Get the permission decision: `'allow'`, `'deny'`, `'ask'`, or `'defer'` |
|
|
41
45
|
| `output.permission_reason` | Get the reason for the permission decision |
|
|
42
46
|
| `output.updated_input` | Get the updated input (if provided) |
|
|
43
47
|
|
data/docs/API/SETUP.md
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
# Setup API
|
|
2
|
+
|
|
3
|
+
Available when inheriting from `ClaudeHooks::Setup`:
|
|
4
|
+
|
|
5
|
+
Runs once during Claude Code startup (before any session begins). Use it to inject global context or perform one-time initialization.
|
|
6
|
+
|
|
7
|
+
## Input Helpers
|
|
8
|
+
|
|
9
|
+
[📚 Shared input helpers](COMMON.md#input-helpers)
|
|
10
|
+
|
|
11
|
+
| Method | Description |
|
|
12
|
+
|--------|-------------|
|
|
13
|
+
| `source` | Startup reason: `'init'` (first launch) or `'maintenance'` |
|
|
14
|
+
|
|
15
|
+
## Hook State Helpers
|
|
16
|
+
|
|
17
|
+
[📚 Shared hook state methods](COMMON.md#hook-state-methods)
|
|
18
|
+
|
|
19
|
+
| Method | Description |
|
|
20
|
+
|--------|-------------|
|
|
21
|
+
| `add_additional_context!(context)` | Add contextual information for Claude |
|
|
22
|
+
| `add_context!(context)` | Alias for `add_additional_context!` |
|
|
23
|
+
|
|
24
|
+
## Output Helpers
|
|
25
|
+
|
|
26
|
+
[📚 Shared output helpers](COMMON.md#output-helpers)
|
|
27
|
+
|
|
28
|
+
| Method | Description |
|
|
29
|
+
|--------|-------------|
|
|
30
|
+
| `output.additional_context` | Get the additional context that was added |
|
|
31
|
+
|
|
32
|
+
## Hook Exit Codes
|
|
33
|
+
|
|
34
|
+
| Exit Code | Behavior |
|
|
35
|
+
|-----------|----------|
|
|
36
|
+
| `exit 0` | Continues normally; `STDOUT` added as context |
|
|
37
|
+
| `exit 2` | N/A — non-blocking event |
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
# StopFailure API
|
|
2
|
+
|
|
3
|
+
Available when inheriting from `ClaudeHooks::StopFailure`:
|
|
4
|
+
|
|
5
|
+
Runs when the stop phase itself errors. Purely a logging event — output and exit code are completely ignored by Claude Code.
|
|
6
|
+
|
|
7
|
+
## Input Helpers
|
|
8
|
+
|
|
9
|
+
[📚 Shared input helpers](COMMON.md#input-helpers)
|
|
10
|
+
|
|
11
|
+
| Method | Description |
|
|
12
|
+
|--------|-------------|
|
|
13
|
+
| `error` | The error message |
|
|
14
|
+
| `error_details` | Additional error detail (stack trace, etc.) |
|
|
15
|
+
| `last_assistant_message` | The last message Claude produced before the failure |
|
|
16
|
+
|
|
17
|
+
## Hook Exit Codes
|
|
18
|
+
|
|
19
|
+
Exit code and all output are ignored. Use this hook only for logging or alerting.
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
# SubagentStart API
|
|
2
|
+
|
|
3
|
+
Available when inheriting from `ClaudeHooks::SubagentStart`:
|
|
4
|
+
|
|
5
|
+
Runs when a subagent task starts. Use it to inject context specific to the subagent or log the start.
|
|
6
|
+
|
|
7
|
+
## Input Helpers
|
|
8
|
+
|
|
9
|
+
[📚 Shared input helpers](COMMON.md#input-helpers)
|
|
10
|
+
|
|
11
|
+
The `agent_id` and `agent_type` common fields are populated for this event.
|
|
12
|
+
|
|
13
|
+
| Method | Description |
|
|
14
|
+
|--------|-------------|
|
|
15
|
+
| `agent_id` | The subagent's unique ID |
|
|
16
|
+
| `agent_type` | The subagent's type |
|
|
17
|
+
|
|
18
|
+
## Hook State Helpers
|
|
19
|
+
|
|
20
|
+
[📚 Shared hook state methods](COMMON.md#hook-state-methods)
|
|
21
|
+
|
|
22
|
+
| Method | Description |
|
|
23
|
+
|--------|-------------|
|
|
24
|
+
| `add_additional_context!(context)` | Add contextual information for the subagent |
|
|
25
|
+
| `add_context!(context)` | Alias for `add_additional_context!` |
|
|
26
|
+
|
|
27
|
+
## Output Helpers
|
|
28
|
+
|
|
29
|
+
[📚 Shared output helpers](COMMON.md#output-helpers)
|
|
30
|
+
|
|
31
|
+
| Method | Description |
|
|
32
|
+
|--------|-------------|
|
|
33
|
+
| `output.additional_context` | Get the additional context that was added |
|
|
34
|
+
|
|
35
|
+
## Hook Exit Codes
|
|
36
|
+
|
|
37
|
+
| Exit Code | Behavior |
|
|
38
|
+
|-----------|----------|
|
|
39
|
+
| `exit 0` | Continues normally; `STDOUT` added as context |
|
|
40
|
+
| `exit 2` | N/A — non-blocking event |
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
# TaskCompleted API
|
|
2
|
+
|
|
3
|
+
Available when inheriting from `ClaudeHooks::TaskCompleted`:
|
|
4
|
+
|
|
5
|
+
Runs when a teammate task completes. Can block Claude from continuing via `prevent_continue!` or exit 2.
|
|
6
|
+
|
|
7
|
+
## Input Helpers
|
|
8
|
+
|
|
9
|
+
[📚 Shared input helpers](COMMON.md#input-helpers)
|
|
10
|
+
|
|
11
|
+
| Method | Description |
|
|
12
|
+
|--------|-------------|
|
|
13
|
+
| `task_id` | The unique task ID |
|
|
14
|
+
| `task_subject` | Short title of the task |
|
|
15
|
+
| `task_description` | Optional longer description |
|
|
16
|
+
| `teammate_name` | The teammate who completed the task |
|
|
17
|
+
| `team_name` | The team name |
|
|
18
|
+
|
|
19
|
+
## Hook State Helpers
|
|
20
|
+
|
|
21
|
+
[📚 Shared hook state methods](COMMON.md#hook-state-methods)
|
|
22
|
+
|
|
23
|
+
| Method | Description |
|
|
24
|
+
|--------|-------------|
|
|
25
|
+
| `prevent_continue!(reason)` | Block Claude from continuing (`continue: false` + `stopReason`) |
|
|
26
|
+
|
|
27
|
+
There is no top-level `decision` field for this event — block via `prevent_continue!` or exit 2.
|
|
28
|
+
|
|
29
|
+
## Output Helpers
|
|
30
|
+
|
|
31
|
+
[📚 Shared output helpers](COMMON.md#output-helpers)
|
|
32
|
+
|
|
33
|
+
| Method | Description |
|
|
34
|
+
|--------|-------------|
|
|
35
|
+
| `output.continue?` | Whether Claude will continue |
|
|
36
|
+
| `output.stop_reason` | The reason Claude was stopped |
|
|
37
|
+
|
|
38
|
+
## Hook Exit Codes
|
|
39
|
+
|
|
40
|
+
| Exit Code | Behavior |
|
|
41
|
+
|-----------|----------|
|
|
42
|
+
| `exit 0` | Claude continues |
|
|
43
|
+
| `exit 2` | Blocks Claude (`continue: false`) |
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
# TaskCreated API
|
|
2
|
+
|
|
3
|
+
Available when inheriting from `ClaudeHooks::TaskCreated`:
|
|
4
|
+
|
|
5
|
+
Runs when a teammate task is created. Can block Claude from continuing via `prevent_continue!` or exit 2.
|
|
6
|
+
|
|
7
|
+
## Input Helpers
|
|
8
|
+
|
|
9
|
+
[📚 Shared input helpers](COMMON.md#input-helpers)
|
|
10
|
+
|
|
11
|
+
| Method | Description |
|
|
12
|
+
|--------|-------------|
|
|
13
|
+
| `task_id` | The unique task ID |
|
|
14
|
+
| `task_subject` | Short title of the task |
|
|
15
|
+
| `task_description` | Optional longer description |
|
|
16
|
+
| `teammate_name` | The teammate assigned to the task |
|
|
17
|
+
| `team_name` | The team name |
|
|
18
|
+
|
|
19
|
+
## Hook State Helpers
|
|
20
|
+
|
|
21
|
+
[📚 Shared hook state methods](COMMON.md#hook-state-methods)
|
|
22
|
+
|
|
23
|
+
| Method | Description |
|
|
24
|
+
|--------|-------------|
|
|
25
|
+
| `prevent_continue!(reason)` | Block Claude from continuing (`continue: false` + `stopReason`) |
|
|
26
|
+
|
|
27
|
+
There is no top-level `decision` field for this event — block via `prevent_continue!` or exit 2.
|
|
28
|
+
|
|
29
|
+
## Output Helpers
|
|
30
|
+
|
|
31
|
+
[📚 Shared output helpers](COMMON.md#output-helpers)
|
|
32
|
+
|
|
33
|
+
| Method | Description |
|
|
34
|
+
|--------|-------------|
|
|
35
|
+
| `output.continue?` | Whether Claude will continue |
|
|
36
|
+
| `output.stop_reason` | The reason Claude was stopped |
|
|
37
|
+
|
|
38
|
+
## Hook Exit Codes
|
|
39
|
+
|
|
40
|
+
| Exit Code | Behavior |
|
|
41
|
+
|-----------|----------|
|
|
42
|
+
| `exit 0` | Claude continues |
|
|
43
|
+
| `exit 2` | Blocks Claude (`continue: false`) |
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
# TeammateIdle API
|
|
2
|
+
|
|
3
|
+
Available when inheriting from `ClaudeHooks::TeammateIdle`:
|
|
4
|
+
|
|
5
|
+
Runs when a teammate goes idle. Can block Claude from continuing via `prevent_continue!` or exit 2.
|
|
6
|
+
|
|
7
|
+
## Input Helpers
|
|
8
|
+
|
|
9
|
+
[📚 Shared input helpers](COMMON.md#input-helpers)
|
|
10
|
+
|
|
11
|
+
| Method | Description |
|
|
12
|
+
|--------|-------------|
|
|
13
|
+
| `teammate_name` | The name of the idle teammate |
|
|
14
|
+
| `team_name` | The team name |
|
|
15
|
+
|
|
16
|
+
## Hook State Helpers
|
|
17
|
+
|
|
18
|
+
[📚 Shared hook state methods](COMMON.md#hook-state-methods)
|
|
19
|
+
|
|
20
|
+
| Method | Description |
|
|
21
|
+
|--------|-------------|
|
|
22
|
+
| `prevent_continue!(reason)` | Block Claude from continuing (`continue: false` + `stopReason`) |
|
|
23
|
+
|
|
24
|
+
There is no top-level `decision` field for this event — block via `prevent_continue!` or exit 2.
|
|
25
|
+
|
|
26
|
+
## Output Helpers
|
|
27
|
+
|
|
28
|
+
[📚 Shared output helpers](COMMON.md#output-helpers)
|
|
29
|
+
|
|
30
|
+
| Method | Description |
|
|
31
|
+
|--------|-------------|
|
|
32
|
+
| `output.continue?` | Whether Claude will continue |
|
|
33
|
+
| `output.stop_reason` | The reason Claude was stopped |
|
|
34
|
+
|
|
35
|
+
## Hook Exit Codes
|
|
36
|
+
|
|
37
|
+
| Exit Code | Behavior |
|
|
38
|
+
|-----------|----------|
|
|
39
|
+
| `exit 0` | Claude continues |
|
|
40
|
+
| `exit 2` | Blocks Claude (`continue: false`) |
|