register-hook

Create executable hook scripts with error handling and register them in settings.json.

4|Updated Sep 25, 2025
One-click install
npx skills add https://github.com/cowwoc/styler --skill register-hook
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: register-hook
Source: https://github.com/cowwoc/styler/tree/main/.claude/skills/register-hook
Command: npx skills add https://github.com/cowwoc/styler --skill register-hook

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes scripts (resource) and references (resource) components.

What problem does it solve?

This Skill automates the creation and registration of hook scripts with standardized error handling and proper placement in settings.json, reducing setup mistakes and manual configuration time.

Core Features & Use Cases

  • Create Hook Script: Includes mandatory error handling pattern and a safe shebang.
  • Set Permissions: Ensure the script is executable.
  • Register in settings.json: Add the hook with the correct matcher and trigger.
  • Restart Reminder: Warn when changes require a Claude restart.
  • Test Instructions: Provide steps to verify the hook executes correctly.

Quick Start

Use the register-hook.sh script to create a hook named "log-bash-commands" with trigger "PreToolUse" and matcher "Bash", and provide the script content as needed. The script would include: #!/bin/bash set -euo pipefail trap 'echo "ERROR in log-bash-commands.sh at line $LINENO: Command failed: $BASH_COMMAND" >&2; exit 1' ERR JSON_INPUT=$(cat) COMMAND=$(echo "$JSON_INPUT" | jq -r '.tool_input.command // empty') echo "[$(date -Iseconds)] $COMMAND" >> /tmp/bash-log.txt

Frequently Asked Questions about register-hook

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I create a bash hook script with proper error handling?

Create a bash hook script with mandatory error handling by starting with `#!/bin/bash`, adding `set -euo pipefail` to exit on errors, and implementing an ERR trap that logs the line number and failed command before exiting. This pattern ensures hooks fail safely and provide debugging information when issues occur.

How do I register a hook in settings.json with a tool matcher?

Register a hook in settings.json by specifying the trigger event (SessionStart, UserPromptSubmit, PreToolUse, PostToolUse, or PreCompact), the script path, and a matcher to filter when it runs. Valid matcher syntax targets specific tools; PreToolUse hooks commonly use matchers like 'Bash' to run only for particular tool invocations.

What steps do I need to follow to set up a new hook from start to finish?

Create a bash script with error handling and executable permissions, add it to settings.json with the correct trigger and matcher configuration, restart Claude to activate the hook, and verify execution by testing the trigger condition. The register-hook.sh script automates these steps and provides test instructions.

Do I need to restart Claude after registering a hook?

Yes, changes to settings.json require a Claude restart to take effect. The hook registration process includes a restart reminder to alert you that the new hook won't execute until you restart.

What permissions and syntax requirements apply to hook scripts?

Hook scripts must be executable and follow bash best practices: use `set -euo pipefail` for strict error handling, include an ERR trap for error reporting, and employ valid matcher syntax when registering. These requirements prevent silent failures and ensure hooks behave predictably across environments.

Can I use hook scripts to run commands before tool execution?

Yes, the PreToolUse trigger allows hooks to run before a tool executes. You can use tool matchers to filter which tools trigger the hook—for example, a 'Bash' matcher runs your hook only before bash commands, enabling selective tool monitoring or preprocessing.