Guide for creating Claude Code hooks with proper configuration, shell commands, event handling, and security practices. Use when the user wants to create hooks, automate workflows, add event handlers, format code automatically, protect files, log actions, or mentions creating/configuring/building hooks.
Detected risks:
The 'create-hooks' skill provides a comprehensive guide for users looking to create Claude Code hooks, which are user-defined shell commands that allow for precise control over specific points in the Claude Code lifecycle. This skill addresses the need for automation and customization by enabling users to define actions that execute in response to various events, ensuring that workflows can be tailored to meet specific requirements without relying on the unpredictability of large language model (LLM) decisions. By following a structured approach, users can effectively implement hooks that enhance both the functionality and security of their coding environment.
Main features of this skill include the ability to define actions for nine distinct lifecycle events, such as PreToolUse, PostToolUse, UserPromptSubmit, and more. Each event serves a unique purpose, allowing for file protection, code formatting, session logging, and other essential tasks. Additionally, users can easily configure hooks through a JSON format in their settings, enabling seamless integration into their workflow. This skill is particularly beneficial for developers, system administrators, and anyone involved in automating tasks within Claude Code, as it empowers them to create a highly customized and efficient coding experience.
Use cases for the 'create-hooks' skill include automating code formatting and linting after edits, validating user input before execution, and logging actions for auditing purposes. Target users range from individual developers seeking to streamline their coding practices to teams looking for a way to enforce code quality standards and maintain security protocols. By utilizing the capabilities provided by this skill, users can enhance their productivity and ensure that their coding environment operates smoothly and securely.
Follow the workflow outlined in the Quick Start section, which includes identifying the event, defining the action, configuring the matcher, and testing the command.
Claude Code supports nine hook events: PreToolUse, PostToolUse, UserPromptSubmit, Notification, Stop, SubagentStop, PreCompact, SessionStart, and SessionEnd.
Shell commands must be compatible with the operating system you are using, and they should be tested independently before being registered as hooks.
Yes, some hooks like PreToolUse and UserPromptSubmit can block events by returning an exit code.
Hooks are configured in the settings.json file located at ~/.claude/settings.json.
Quick Setup:
.claude/skills/Repository
ronnycoding/.claude