hook-authoring

Author CommonJS event hooks with validated runtime and payload handling.

Updated Mar 31, 2026
One-click install
npx skills add https://github.com/terrene-foundation/kailash-coc-claude-rb --skill hook-authoring-terrene-foundation
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: hook-authoring
Source: https://github.com/terrene-foundation/kailash-coc-claude-rb/tree/main/.claude/skills/hook-authoring
Command: npx skills add https://github.com/terrene-foundation/kailash-coc-claude-rb --skill hook-authoring-terrene-foundation

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

Hook authoring and auditing across Claude Code, Codex, and Gemini is easy to get subtly wrong—leading to missed enforcement, inconsistent event taxonomies, incorrect path resolution, or unsafe halts without proper structured handoff.

Core Features & Use Cases

  • Single-script, multi-runtime hook behavior: Author one .claude/hooks/<name>.js that works consistently across CC, Codex, and Gemini by validating COC_RUNTIME and normalizing hook payloads.
  • Deterministic halt discipline: Ensure all halting branches use lib/instruct-and-wait.js::emit() with the required six fields, and enforce the mandatory timeout fallback (setTimeout{continue: true}process.exit(1)).
  • Security and enforcement correctness: Prevent weak “regex-only” block severity by requiring structural/AST/process-state evidence for severity: "block", and maintain Codex gap coverage via the MCP guard bijection and validator-13 predicate shapes.
  • Portability across CLIs: Resolve project directory safely using CLAUDE_PROJECT_DIR || GEMINI_PROJECT_DIR || payload.cwd so Codex works without a project-dir env var.
  • Audit-ready regression safety: Pair detectors with required audit fixtures and validator/extractor constraints (including predicate-shape compatibility) to avoid silent enforcement drift.

Quick Start

Use the hook-authoring skill to author a new hook script at .claude/hooks/<name>.js, validate it against the required output discipline and timeout fallback, then register it in .claude/settings.json for Claude Code and in the appropriate manifest for Codex/Gemini.

Frequently Asked Questions about hook-authoring

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

FAQPage Schema
How do I write hooks that enforce guardrails across Claude Code, Codex, and Gemini?

Author a single CommonJS script that validates `COC_RUNTIME` and normalizes stdin via `parseHook()`, ensuring portable hook behavior and consistent event payload handling across all three CLIs.

How do I safely halt tool execution in a Claude Code hook?

Use `emit()`-based halts with six required fields and a mandatory timeout fallback (`setTimeout` → `{continue: true}` → `process.exit(1)`) to ensure deterministic halt discipline.

Why do my Codex hooks fail to resolve the project directory?

Codex lacks a project-dir env var; resolve paths safely using `CLAUDE_PROJECT_DIR || GEMINI_PROJECT_DIR || payload.cwd` to maintain portability across CLIs.

When should I use severity "block" in runtime validation hooks?

Use severity "block" only when you have structural, AST, or process-state evidence; weak regex-only matching is insufficient for safe tool enforcement and guardrails.

What's the best way to prevent silent enforcement drift in codegen hooks?

Pair detectors with audit fixtures and validator/extractor constraints using validator-13 predicate shapes and Codex MCP-guard bijection to maintain regression safety.

Does hook authoring require registering scripts in settings manifests?

Yes, after authoring and validating `.claude/hooks/<name>.js`, register it in `.claude/settings.json` for Claude Code and the appropriate manifest for Codex/Gemini.