Claude Code hook
Claude Hooks SDK
PHP library for building Claude Code hooks with a fluent API.
Install
git clone https://github.com/beyondcode/claude-hooks-sdk.gitFrom the README
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 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) 4. Add your hook command: php /path/to/your/validate-code.php 5. 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.
How hooks work
- Hooks are shell commands Claude Code runs at fixed points: before or after a tool call, when you submit a prompt, when Claude stops, on notifications and at session start.
- They are set in the hooks section of ~/.claude/settings.json (or .claude/settings.json for a project), or come bundled in a plugin.
- A hook can block a tool call, add context, or run a formatter or test. Read the scripts before you install them: they run on your machine with your permissions.
Details
- Repository
- beyondcode/claude-hooks-sdk
- Type
- Hooks
- Language
- PHP
- License
- MIT
- Last updated
- 4 May 2026
FAQ
What is Claude Hooks SDK?
PHP library for building Claude Code hooks with a fluent API. It is a hook for Claude Code, from beyondcode/claude-hooks-sdk on GitHub.
How do I install Claude Hooks SDK?
Clone beyondcode/claude-hooks-sdk from GitHub and follow the setup steps in its README.
Is Claude Hooks SDK popular?
beyondcode/claude-hooks-sdk has 68 GitHub stars and 7 forks, and is included in 2 curated Claude Code lists. It was last updated on 4 May 2026.
More hooks
Claude Code Boost
165yifanzz/claude-code-boost
Claude Code Boost - Hook utilities for Claude Code with intelligent auto-approval
jev-guard
144leepokai/jev-guard
Risk-scores each tool call with session context and decides to allow, ask or deny.
agentlint
215mauhpr/agentlint
Local guardrail hooks that check proposed file edits and shell commands and block risky patterns.
Claude Code Crash Course
191emarco177/claude-code-crash-course
Hands-on crash course for Claude Code with branch-based projects on MCP, subagents, hooks, and automation.
Model Matchmaker
168coyvalyss1/model-matchmaker
Local hook that routes each prompt to a suitable model tier to save cost.
Sondera Coding Agent Hooks
231sondera-ai/sondera-coding-agent-hooks
Hooking implementations and supporting tools for various coding agents (Claude, Cursor, Gemini, etc)
Browse the most popular Claude Code mods, all hooks, or the skills and MCP server directories.