create-hooks

Create and manage Claude Code hooks across nine lifecycle events.

20|1|Updated Sep 30, 2025
One-click install
npx skills add https://github.com/ronnycoding/.claude --skill create-hooks
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: create-hooks
Source: https://github.com/ronnycoding/.claude/tree/main/skills/create-hooks
Command: npx skills add https://github.com/ronnycoding/.claude --skill create-hooks

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill requires jq, prettier.

What problem does it solve?

This Skill eliminates the need for manual, repetitive tasks and provides deterministic control over Claude Code's lifecycle, ensuring consistent behavior and security.

Core Features & Use Cases

  • Automated Code Formatting: Automatically run tools like Prettier or Black after Claude Code edits files.
  • File Protection & Validation: Block modifications to sensitive files or validate commands before execution.
  • Session Logging & Cleanup: Log session starts/ends, or clean up temporary files after tool use.
  • Use Case: Configure a PostToolUse hook to automatically format all JavaScript/TypeScript files whenever Claude Code makes an edit, ensuring consistent code style without manual intervention.

Quick Start

Create a hook to automatically run prettier --write on any .js or .ts file after Claude Code edits it.

Frequently Asked Questions about create-hooks

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

FAQPage Schema
How do I automate code formatting after Claude Code edits files?

Create a PostToolUse hook that triggers Prettier or similar formatters on modified files. Configure the hook in ~/.claude/settings.json with a matcher for your file types (.js, .ts, etc.), and Claude Code will automatically format code after each edit without manual intervention.

What are Claude Code hooks and what lifecycle events do they support?

Hooks are user-defined shell commands that execute at nine Claude Code lifecycle events: PreToolUse, PostToolUse, UserPromptSubmit, Notification, Stop, SubagentStop, PreCompact, SessionStart, and SessionEnd. They enable deterministic automation for tasks like validation, formatting, logging, and security checks.

Can I block Claude Code from modifying sensitive files?

Yes. Use a PreToolUse hook with file matchers to intercept tool execution before it happens. Return exit code 2 to block the operation, enabling file protection and validation before Claude Code makes changes to sensitive files.

How do I set up event-driven automation in Claude Code?

Define hooks in ~/.claude/settings.json with event triggers, file matchers, and shell commands. Claude Code passes event data as JSON stdin to your hook script; parse it with jq and execute your automation logic. Exit code 0 succeeds; code 2 blocks PreToolUse events.

What dependencies do I need to use Claude Code hooks effectively?

Hooks require jq for JSON parsing and Prettier for code formatting (optional, depending on use case). Both are standard tools; jq parses the JSON event data hooks receive, and Prettier formats code in PostToolUse workflows.

Can I log Claude Code sessions and clean up temporary files automatically?

Yes. Use SessionStart and SessionEnd hooks to log session lifecycle events, and PostToolUse hooks to clean up temporary files after tool execution. Combine multiple hooks across different events to orchestrate complex automation workflows.