external/skills/hook-development/SKILL.md
Use when the user wants to create Codex workflow hooks (pre/post run gates, tool-use validators, stop checks) or needs guidance on hook scripts and hooks.json configuration.
npx skillsauth add troykelly/codex-skills hook-developmentInstall this skill globally with one command. Works with Claude Code, Cursor, and Windsurf.
3 of 9 scanners reported clean
Some scanners were skipped, did not run, or reported a non-clean status. Review each row below.
Codex CLI does not provide Claude-style hook events. To replicate hook behavior, implement a hook runner (wrapper script or CI job) that:
codex exec.codex exec --json output to detect tool usage.hooks.json configuration to decide which hooks to run.This skill defines a Codex hook contract and provides utilities for validating, testing, and linting hooks.
This repository ships a reference runner at scripts/codex-hook-runner (installed by install.sh) that implements the contract described below. Hooks are enabled by default in codex-autonomous; set CODEX_DISABLE_HOOKS=1 to disable.
Use an LLM (Codex or another model) to make contextual decisions.
{
"type": "prompt",
"prompt": "Validate this operation. Return approve|deny with a reason."
}
Use shell scripts for fast, repeatable checks.
{
"type": "command",
"command": "bash ${CODEX_HOOK_ROOT}/scripts/validate-write.sh",
"timeout": 30
}
Define hooks in a single hooks.json. This format is consumed by your hook runner.
{
"hooks": {
"PreToolUse": [
{
"matcher": "Write|Edit",
"hooks": [
{
"type": "command",
"command": "bash ${CODEX_HOOK_ROOT}/scripts/validate-write.sh"
}
]
}
],
"Stop": [
{
"matcher": "*",
"hooks": [
{
"type": "prompt",
"prompt": "Review transcript at $TRANSCRIPT_PATH. Block if tests were not run after code changes."
}
]
}
]
}
}
If your runner prefers a direct format, you can omit the hooks wrapper and use events at top level. scripts/validate-hook-schema.sh supports both.
Your hook runner chooses which events to emit. Recommended events:
SessionStart: before running CodexUserPromptSubmit: after prompt is assembled but before executionPreToolUse: before a tool call (requires --json parsing)PostToolUse: after a tool call (requires --json parsing)Stop: before accepting the final responseSessionEnd: after the run completesSubagentStop: for worker processes spawned by worker-dispatchHook scripts receive JSON on stdin and return decisions via exit code:
Recommended output shape for decision hooks:
{
"decision": "allow|deny|ask",
"reason": "short explanation",
"systemMessage": "optional context for the main agent"
}
{
"event": "PreToolUse",
"hook_event_name": "PreToolUse",
"tool_name": "Write",
"tool_input": {"file_path": "..."},
"tool_result": {"stdout": "..."},
"session_id": "...",
"transcript_path": "...",
"cwd": "...",
"approval_policy": "on-request",
"sandbox_mode": "workspace-write"
}
Your runner may add additional fields as needed.
The hook runner should set:
CODEX_PROJECT_ROOT: repository rootCODEX_HOOK_ROOT: directory containing hooks.json and scriptsCODEX_ENV_FILE: path to a file for exporting environment variables (optional)Use these helper scripts while developing hooks:
scripts/validate-hook-schema.sh: validate hooks.json structurescripts/hook-linter.sh: lint hook scriptsscripts/test-hook.sh: run hooks with sample inputsreferences/patterns.md for common hook patternsreferences/advanced.md for advanced techniquesreferences/migration.md for migrating from script-only gates to prompt-based hooksexamples/ for sample hooksdata-ai
Defines behavior protocol for spawned worker agents. Injected into worker prompts. Covers startup, progress reporting, exit conditions, and handover preparation.
development
Defines context handover format when workers hit turn limit. Posts structured handover to GitHub issue comments enabling replacement workers to continue seamlessly.
data-ai
Use to spawn isolated worker processes for autonomous issue work. Creates git worktrees, constructs worker prompts, and handles worker lifecycle.
tools
Entry point for ALL work requests - triages scope from trivial to massive, asks clarifying questions, and routes to appropriate planning skills. Use this when receiving any new work request.