Skip to content llms.txt

Hook Interchange Format Specification

Version: 1.0.0-draft | License: CC-BY-4.0

This specification defines a provider-neutral interchange format for AI coding tool hooks. It enables hook authors to write lifecycle hooks once and deploy them across multiple AI coding tool providers through a canonical representation, capability model, and conversion pipeline.

For a user-friendly overview, see Hooks content type. This page is the full technical specification.


AI coding tools provide hook systems that let developers run custom logic at lifecycle points: before a tool executes, when a session starts, after the agent stops. These hooks enforce policy, audit actions, inject context, and customize behavior.

Every provider’s hook system is different. Event names, JSON schemas, output contracts, matcher syntax, timeout units, and configuration file layouts vary across providers. A hook written for one tool cannot run on another without manual adaptation.

This specification defines a canonical hook format that serves as an interchange representation between providers. It does not replace any provider’s native format. Instead, it provides a neutral hub through which hooks are converted: decode from a source provider’s format into canonical, then encode from canonical into a target provider’s format.

  • A canonical JSON format for hook manifests
  • An exit code contract for hook processes
  • A canonical output schema for structured hook responses
  • A typed matcher system for tool filtering
  • A registry of canonical event names with provider mappings
  • A capability model describing optional features with provider support matrices
  • A tool vocabulary mapping canonical tool names to provider-native names
  • Degradation strategies for handling capability gaps during conversion
  • Conformance levels for implementations

{
"spec": "hooks/1.0",
"hooks": [
{
"event": "before_tool_execute",
"matcher": "shell",
"handler": {
"type": "command",
"command": "./safety-check.sh",
"timeout": 10
},
"blocking": true
}
]
}
FieldTypeRequiredDescription
specstringYesMust be "hooks/1.0"
hooksarrayYesNon-empty array of hook definitions
FieldTypeRequiredDescription
eventstringYesCanonical event name (see Event Registry)
matcherstring, object, or arrayNoTool matcher expression (see Matcher Types)
handlerobjectYesHandler definition
blockingbooleanNoWhether this hook can prevent the triggering action. Default: false
degradationobjectNoPer-capability fallback strategies
provider_dataobjectNoOpaque provider-specific data, keyed by provider slug
FieldTypeRequiredDescription
typestringYes"command", "http", "prompt", or "agent"
commandstringConditionalShell command (required when type is "command")
platformobjectNoPer-OS command overrides: windows, linux, osx
cwdstringNoWorking directory relative to project root
envobjectNoEnvironment variables for the hook process
timeoutnumberNoMax execution time in seconds (default: 30)
asyncbooleanNoFire-and-forget execution. Default: false

Exit CodeNameBehavior
0SuccessAction proceeds. Stdout parsed as JSON if present
1Hook ErrorNon-blocking warning. Action proceeds
2BlockAction prevented (only when blocking: true)
OtherHook ErrorSame as exit code 1

When a hook exits 0 with JSON on stdout:

FieldTypeDescription
decisionstring"allow", "deny", or "ask"
reasonstringHuman-readable explanation
continuebooleanWhether agent continues its loop (default: true)
contextstringContext injected into agent conversation

Advanced fields (capability-specific):

  • updated_input — modified tool arguments (requires input_rewrite capability)
  • suppress_output — suppress tool output display (requires structured_output)
  • system_message — inject system prompt message (requires structured_output)

Tool vocabulary lookup:

"matcher": "shell"

Regex on tool name:

"matcher": {"pattern": "file_(read|write|edit)"}

Target MCP server/tool:

"matcher": {"mcp": {"server": "github", "tool": "create_issue"}}

Match any element:

"matcher": ["shell", "file_write", {"mcp": {"server": "github"}}]

EventDescriptionBlocking Semantic
before_tool_executeBefore any tool runsCan prevent tool execution
after_tool_executeAfter tool completesObservational only
session_startSession begins/resumesObservational; may inject context
session_endSession terminatesObservational
before_promptAfter user input, before agentCan modify/reject input
agent_stopAgent main loop endsCan trigger retry

before_compact, notification, error_occurred, subagent_start, subagent_stop, permission_request

EventOrigin Provider
before_model, after_model, before_tool_selectionGemini CLI
config_changeClaude Code
file_created, file_saved, file_deletedKiro
before_task, after_taskKiro
Canonicalclaude-codegemini-clicursorcopilot-clikiro
before_tool_executePreToolUseBeforeToolbeforeShellExecutionpreToolUsepreToolUse
after_tool_executePostToolUseAfterToolafterFileEditpostToolUsepostToolUse
before_promptUserPromptSubmitBeforeAgentbeforeSubmitPromptuserPromptSubmitteduserPromptSubmit
agent_stopStopAfterAgentstopstop

Canonicalclaude-codegemini-clicursorcopilot-clikiro
shellBashrun_shell_commandrun_terminal_cmdbashexecute_bash
file_readReadread_fileread_fileviewfs_read
file_writeWritewrite_fileedit_filecreatefs_write
file_editEditreplaceedit_fileeditfs_write
searchGrepgrep_searchgrep_searchgrepgrep
findGlobglobfile_searchglobglob
web_searchWebSearchgoogle_web_searchweb_searchweb_search
web_fetchWebFetchweb_fetchweb_fetchweb_fetch
agentAgenttaskuse_subagent

CapabilityDescriptionDefault Degradation
structured_outputJSON output with rich fieldswarn
input_rewriteModify tool arguments (safety-critical)block
llm_evaluatedLLM logic, not deterministic scriptexclude
http_handlerHTTP POST handlerwarn
async_executionFire-and-forgetwarn
platform_commandsOS-specific overrideswarn
custom_envEnvironment variableswarn
configurable_cwdWorking directorywarn

StrategyBehavior
blockConverted hook blocks action entirely instead of running with reduced functionality
warnHook runs with reduced functionality; warning emitted
excludeHook excluded from target provider’s configuration

Authors specify per-capability strategies in the degradation field. Absent strategies use safe defaults from the capability registry.


  1. Decode — Source adapter reads provider-native config → canonical manifest
  2. Validate — Check capabilities against target provider, apply degradation
  3. Encode — Target adapter writes canonical → provider-native config
  4. Verify — Re-decode output to check structural fidelity

LevelRequirements
CoreParse/produce manifests, core events, exit codes, bare string matchers, event+tool translation
Extended+ All matcher types, output schema, capability inference, degradation, extended events
Full+ Provider data round-trip, verification, all capabilities, provider-exclusive events

  • Claude Code — Richest output contract, four handler types, 25+ events
  • Gemini CLI — Unique LLM-interaction hooks (before_model, after_model)
  • Kiro — File system lifecycle hooks, spec task integration
  • Cursor — Pre-read file access control
  • Windsurf — Enterprise deployment infrastructure
  • OpenCode — Programmatic TypeScript/JavaScript extensibility
  • Copilot CLI — Conservative safety design, repository-bound hooks