claude_hooks 1.2.0 → 1.3.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/CHANGELOG.md +27 -0
- data/README.md +152 -221
- data/docs/1.0.0_MIGRATION_GUIDE.md +6 -7
- data/docs/API/DIRECTORY_ADDED.md +34 -0
- data/docs/external/claude-hooks-reference.md +271 -107
- data/example_dotclaude/hooks/entrypoints/session_end.rb +5 -22
- data/example_dotclaude/hooks/entrypoints/user_prompt_submit.rb +4 -26
- data/example_dotclaude/hooks/{handlers/pre_tool_use/github_guard.rb → github_guard.rb} +7 -13
- data/example_dotclaude/settings.json +1 -1
- data/lib/claude_hooks/cli.rb +84 -149
- data/lib/claude_hooks/directory_added.rb +24 -0
- data/lib/claude_hooks/output/base.rb +2 -0
- data/lib/claude_hooks/output/directory_added.rb +21 -0
- data/lib/claude_hooks/version.rb +1 -1
- data/lib/claude_hooks.rb +2 -0
- metadata +6 -5
- data/.claude/settings.local.json +0 -21
- data/example_dotclaude/hooks/entrypoints/pre_tool_use.rb +0 -25
|
@@ -169,18 +169,17 @@ merged_output.output_and_exit # Handles everything automatically
|
|
|
169
169
|
|
|
170
170
|
## Simplified Entrypoint Pattern
|
|
171
171
|
|
|
172
|
+
> [!NOTE]
|
|
173
|
+
> As of 1.2.1, `CLI.entrypoint` is deprecated in favour of `CLI.run_hook`. The examples below use the current API. `CLI.entrypoint` still works (with a deprecation warning) but will be removed in a future minor version.
|
|
174
|
+
|
|
172
175
|
### For Single Hooks
|
|
173
176
|
```ruby
|
|
174
177
|
#!/usr/bin/env ruby
|
|
175
178
|
require 'claude_hooks'
|
|
176
179
|
require_relative '../handlers/my_hook'
|
|
177
180
|
|
|
178
|
-
# Super simple - just
|
|
179
|
-
ClaudeHooks::CLI.
|
|
180
|
-
hook = MyHook.new(input_data)
|
|
181
|
-
hook.call
|
|
182
|
-
hook.output_and_exit
|
|
183
|
-
end
|
|
181
|
+
# Super simple - just 1 line!
|
|
182
|
+
ClaudeHooks::CLI.run_hook(MyHook)
|
|
184
183
|
```
|
|
185
184
|
|
|
186
185
|
### For Multiple Hooks with Merging
|
|
@@ -190,7 +189,7 @@ require 'claude_hooks'
|
|
|
190
189
|
require_relative '../handlers/hook1'
|
|
191
190
|
require_relative '../handlers/hook2'
|
|
192
191
|
|
|
193
|
-
ClaudeHooks::CLI.
|
|
192
|
+
ClaudeHooks::CLI.run_hook do |input_data|
|
|
194
193
|
hook1 = Hook1.new(input_data)
|
|
195
194
|
hook2 = Hook2.new(input_data)
|
|
196
195
|
hook1.call
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
# DirectoryAdded API
|
|
2
|
+
|
|
3
|
+
Available when inheriting from `ClaudeHooks::DirectoryAdded`:
|
|
4
|
+
|
|
5
|
+
Runs after a working directory is added mid-session via `/add-dir` or the SDK `register_repo_root` control request. Non-blocking — the directory is already added when the hook runs.
|
|
6
|
+
|
|
7
|
+
## Input Helpers
|
|
8
|
+
|
|
9
|
+
[📚 Shared input helpers](COMMON.md#input-helpers)
|
|
10
|
+
|
|
11
|
+
| Method | Description |
|
|
12
|
+
|--------|-------------|
|
|
13
|
+
| `directory` | Absolute path of the directory that was added |
|
|
14
|
+
| `source` | How the directory was added: `'slash_command'` for `/add-dir` or `'register_repo_root'` for the SDK control request |
|
|
15
|
+
|
|
16
|
+
## Hook State Helpers
|
|
17
|
+
|
|
18
|
+
[📚 Shared hook state methods](COMMON.md#hook-state-methods)
|
|
19
|
+
|
|
20
|
+
| Method | Description |
|
|
21
|
+
|--------|-------------|
|
|
22
|
+
| `system_message!` | Set a message delivered to Claude as context on the next turn (`slash_command`) or written to the debug log (`register_repo_root`) |
|
|
23
|
+
|
|
24
|
+
## Output Helpers
|
|
25
|
+
|
|
26
|
+
[📚 Shared output helpers](COMMON.md#output-helpers)
|
|
27
|
+
|
|
28
|
+
| Method | Description |
|
|
29
|
+
|--------|-------------|
|
|
30
|
+
| `output.system_message` | The configured system message |
|
|
31
|
+
|
|
32
|
+
## Hook Exit Codes
|
|
33
|
+
|
|
34
|
+
Non-blocking. Exit code is ignored; only `systemMessage` is consumed.
|