Download the PHP package beyondcode/claude-hooks-sdk without Composer
On this page you can find all versions of the php package beyondcode/claude-hooks-sdk. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download beyondcode/claude-hooks-sdk
More information about beyondcode/claude-hooks-sdk
Files in beyondcode/claude-hooks-sdk
Package claude-hooks-sdk
Short Description A PHP SDK for building Claude Code hooks.
License MIT
Homepage https://github.com/beyondcode/claude-hooks-sdk
Informations about the package claude-hooks-sdk
Claude Hooks SDK
A Laravel-inspired PHP SDK for building Claude Code hook responses with a clean, fluent API. This SDK makes it easy to create structured JSON responses for Claude Code hooks using an expressive, chainable interface.
Claude Code hooks are user-defined shell commands that execute at specific points in Claude Code's lifecycle, providing deterministic control over its behavior. For more details, see the Claude Code Hooks documentation.
Installation
You can install the package via composer:
Usage
Creating a Claude Hook
Here's how to create a PHP script that Claude Code can use as a hook:
Step 1: Create your PHP hook script
Create a new PHP file (e.g., validate-code.php
) using the SDK:
Step 2: Register your hook in Claude Code
- Run the
/hooks
command in Claude Code - Select the
PreToolUse
hook event (runs before tool execution) - Add a matcher (e.g.,
Bash
to match shell commands) - Add your hook command:
php /path/to/your/validate-code.php
- Save to user or project settings
Your hook is now active and will validate commands before Claude Code executes them!
Hook Types and Methods
The SDK automatically creates the appropriate hook type based on the input:
Response Methods
All hooks provide a fluent response API:
Example Hooks
Code Formatter Hook
Automatically format PHP files after edits:
Security Validator Hook
Prevent modifications to sensitive files:
Notification Handler Hook
Custom notification handling:
Testing
Changelog
Please see CHANGELOG for more information on what has changed recently.
Security Vulnerabilities
Please review our security policy on how to report security vulnerabilities.
Credits
- Marcel Pociot
- All Contributors
License
The MIT License (MIT). Please see License File for more information.