Skip to content

Commit 65163a8

Browse files
committed
Update hook example with both output examples
Enhanced the README hook example with both ways to handle output.
1 parent c44a6aa commit 65163a8

File tree

1 file changed

+23
-8
lines changed

1 file changed

+23
-8
lines changed

README.md

Lines changed: 23 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -225,16 +225,31 @@ use BeyondCode\ClaudeHooks\Hooks\UserPromptSubmit;
225225

226226
$hook = ClaudeHook::create();
227227

228-
// Check for sensitive patterns
229-
if (str_contains($hook->prompt(), 'password') || str_contains($hook->prompt(), 'secret')) {
230-
// Block the prompt
231-
$hook->response()->block('Security policy violation: Please rephrase without sensitive information.');
228+
// Ask Claude Code - what is my secret-code?
229+
// It should respond with ABC123 thanks to our injected prompt
230+
231+
if ($hook instanceof UserPromptSubmit) {
232+
$prompt = $hook->prompt();
233+
$lowerPrompt = strtolower($prompt);
234+
235+
// Add context via your script and output the "fancy" way
236+
if (str_contains($lowerPrompt, 'secret-code')) {
237+
$contextReminder = "\n\n🔍 Your secret code is 'ABC123'";
238+
$modifiedPrompt = $prompt . $contextReminder;
239+
240+
$hook->response()->merge(['prompt' => $modifiedPrompt])->continue();
241+
return;
242+
}
243+
244+
// Add context via your script and output directly to stdout
245+
if (str_contains($lowerPrompt, 'laravel')) {
246+
echo PHP_EOL . PHP_EOL . 'Remember, this is a Laravel project, so use laravel-boost mcp server and related tools.';
247+
return;
248+
}
232249
}
233250

234-
// Add context via stdout
235-
echo "Current time: " . date('Y-m-d H:i:s') . "\n";
236-
echo "Project status: Active development\n";
237-
$hook->success();
251+
// For all other hook types, allow them to proceed
252+
$hook->response()->continue();
238253
```
239254

240255

0 commit comments

Comments
 (0)