beyondcode

Claude Code Hooks SDK — Git skill for Claude Code

Git community intermediate

by beyondcode - A Laravel-inspired PHP SDK for building Claude Code hook responses with a clean, fluent API.

How to install Claude Code Hooks SDK

This entry records only its repository, not the path inside it, so there is no exact command to give. Open beyondcode/claude-hooks-sdk and copy the folder into ~/.claude/skills/, or the file into ~/.claude/agents/.

What Claude Code Hooks SDK does

[](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)

Alternatives in Git

  • Copilot API — Turns GitHub Copilot into an OpenAI/Anthropic API compatible server, usable with Claude Code 3.1k ★
  • Tâches Claude Code Resources — by TÂCHES - A well-balanced, "down-to-Earth" set of sub agents, skills, and commands, that are well-organized 1.6k ★
  • Push And Release — Git pull, resolve conflicts, push, fix hook errors, then release 1.6k ★

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

  1. Run the /hooks command in Claude Code
  2. Select the PreToolUse hook event (runs before tool execution)
  3. Add a matcher (e.g., Bash to match shell commands)

...