Claude Code Hooks SDK banner
beyondcode beyondcode

Claude Code Hooks SDK

Git community intermediate

Description

[](https://packagist.org/packages/beyondcode/claude-hooks-sdk) [](https://github.com/beyondcode/claude-hooks-sdk/actions/workflows/run-tests.yml) [](https://packagist.org/packages/beyondcode/claude-hooks-sdk)

Installation

Terminal
claude install-skill https://github.com/beyondcode/claude-hooks-sdk

README

Claude Hooks SDK

[](https://packagist.org/packages/beyondcode/claude-hooks-sdk) [](https://github.com/beyondcode/claude-hooks-sdk/actions/workflows/run-tests.yml) [](https://packagist.org/packages/beyondcode/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](https://docs.anthropic.com/en/docs/claude-code/hooks).

Installation

You can install the package via composer:

composer require beyondcode/claude-hooks-sdk

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:

toolName() === 'Bash') {
    $command = $hook->toolInput('command', '');
    
    // Check for potentially dangerous commands
    if (str_contains($command, 'rm -rf')) {
        // Block the tool call with feedback
        $hook->response()->block('Dangerous command detected. Use caution with rm -rf commands.');
    }
}

// Allow other tool calls to proceed
$hook->success();

Step 2: Register your hook in Claude Code

    undefined

...