hook-development

Build Claude Code hooks that emit immediate JSON and process work asynchronously.

4|Updated Dec 3, 2025
One-click install
npx skills add https://github.com/Emasoft/ghe-marketplace --skill hook-development-emasoft
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: hook-development
Source: https://github.com/Emasoft/ghe-marketplace/tree/main/plugins/ghe/skills/hook-development
Command: npx skills add https://github.com/Emasoft/ghe-marketplace --skill hook-development-emasoft

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes scripts (resource) components.

What problem does it solve?

This Skill helps developers build Claude Code hooks that never get aborted due to internal timeouts by implementing the immediate response pattern and background processing.

Core Features & Use Cases

  • Immediate Response: Output a JSON payload right after reading stdin to satisfy Claude Code's timeout.
  • Background Work: Fork a detached worker process to perform long-running tasks.
  • Data Handling: Pass input data via environment variables to the worker for safety and efficiency.
  • Use Case: Create a PreToolUse or UserPromptSubmit hook that can perform heavy computations without blocking the UI.

Quick Start

Create a hook script based on the example_hook.py and an accompanying worker script like example_worker.py, place them under scripts/, make them executable (chmod +x), and configure Claude Code to trigger on UserPromptSubmit events using this hook.

Frequently Asked Questions about hook-development

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

FAQPage Schema
Why do Claude Code hooks abort with timeout errors during long operations?

Claude Code hooks abort when they don't emit JSON output within a timeout window. Hooks must read stdin, immediately output valid JSON, then perform background work via a detached subprocess to avoid blocking the UI and triggering operation aborted errors on PreToolUse, PostToolUse, UserPromptSubmit, Stop, and SessionStart events.

How do I build a Claude Code hook that handles heavy computations without blocking?

Create a hook script that reads stdin, outputs JSON immediately to satisfy the timeout requirement, then spawns a detached worker subprocess. Pass input data via environment variables to the worker, which runs asynchronously in the background while the hook returns control to Claude Code.

Can I use environment variables to pass data between my Claude Code hook and background worker?

Yes. Environment variables are the safe and efficient method to communicate data from your hook script to the detached worker subprocess. The hook reads stdin, sets environment variables with the input data, spawns the worker detached, and returns JSON immediately.

What's the difference between responding immediately and running background work in a hook?

Immediate response means your hook outputs JSON right after reading stdin to prevent Claude Code's timeout. Background work runs asynchronously in a detached subprocess afterward. Together they let hooks perform long-running tasks—like heavy computations or API calls—without aborting.

Do I need to make my hook and worker scripts executable to use them with Claude Code?

Yes. Both your hook script and worker script must be made executable using chmod +x and placed in the scripts/ directory. Claude Code requires executable permissions to trigger the hook on events like UserPromptSubmit.

What hook events support the immediate response and background processing pattern?

PreToolUse, PostToolUse, UserPromptSubmit, Stop, and SessionStart hooks all support immediate JSON output followed by asynchronous background work. This pattern prevents timeout aborts across all hook event types.