Skip to main content
Reference

Hooks reference

Hook event types, matching rules, execution methods, input and output, and exit codes

Hooks allow you to automatically execute custom logic at specific points in the Qoder CLI lifecycle—for example, validating before a tool call, injecting context at the start of a session, or triggering external processes on file changes. This page is the complete reference for Hooks. For a usage guide, see Hook.

Event Types

Hooks can be bound to the following events:
EventTrigger
PreToolUseBefore a tool call.
PostToolUseAfter a successful tool call.
PostToolUseFailureAfter a failed tool call.
UserPromptSubmitWhen the user submits a prompt.
SessionStartWhen a session starts.
SessionEndWhen a session ends.
StopWhen the main agent stops responding.
StopFailureWhen the stop process fails.
SubagentStartWhen a subagent starts.
SubagentStopWhen a subagent stops.
PreCompactBefore context compression.
PostCompactAfter context compression.
NotificationWhen a notification is generated.
ConfigChangeWhen configuration changes.
InstructionsLoadedAfter loading project instructions.
CwdChangedWhen the working directory changes.
FileChangedWhen a file changes.
WorktreeCreateWhen a worktree is created.
WorktreeRemoveWhen a worktree is removed.
ElicitationWhen an elicitation is initiated.
ElicitationResultWhen elicitation results are returned.
TaskCreatedWhen a task is created.
TaskCompletedWhen a task is completed.
PermissionRequestWhen a permission request is initiated.
PermissionDeniedWhen permission is denied.
TeammateIdleWhen a collaborator is idle.
SetupDuring initial installation.
For each event's matcher fields, additional stdin input fields, blocking support, and available hookSpecificOutput fields, see the "Event Catalog" section in Hook.

Hook Types

Each Hook specifies its execution method via type:
TypeDescription
commandExecutes a shell command.
httpSends an HTTP request.
promptMakes an independent single-turn model call for decision-making; the model returns { ok, reason }, and ok=false blocks.
agentStarts a subagent for validation, returning { ok, reason } via StructuredOutput, and ok=false blocks.
For the complete fields of each type (such as url/headers for http, and the return conventions for prompt and agent), see the "Hook Entry Types" section in Hook.

Definition Structure

Hooks are configured by event within the hooks group in settings.json. Each event corresponds to a set of Hook definitions:
{
  "hooks": {
    "PreToolUse": [
      {
        "matcher": "Bash",
        "hooks": [
          { "type": "command", "command": "./scripts/check.sh" }
        ]
      }
    ]
  }
}
Hook definition (group) fields:
FieldDescription
matcherMatching rules (see below), determining which targets this group of Hooks applies to.
hooksAn array of Hooks, each containing type and corresponding parameters.
In addition to type and type-specific parameters, a single Hook entry also supports fields such as name, timeout, if, and async (executes in the background without blocking the main process). For the complete list, see the "Hook Entry Types" section in Hook.

Matching Rules

matcher determines which targets (such as tool names) the Hook applies to:
  • Empty or *: Matches all.
  • Exact value: Such as Bash, matches only that target.
  • Pipe |: Multiple values, such as Bash|Edit|Write.
  • Regex: Supports regular expression matching.
More granular if conditions can be written as "ToolName" or "ToolName(arg_glob)", where arg_glob uses glob patterns to match tool parameters.

Input and Exit Codes

Input (stdin)

A Hook receives a JSON object via stdin containing the current context (the following are common fields for all events; for event-specific fields, see the "Event Catalog"):
FieldDescription
session_idThe current session ID.
transcript_pathThe path to the session log file.
cwdThe current working directory.
hook_event_nameThe name of the triggered event.
permission_modeThe current permission mode.
agent_idThe ID of the triggered Agent (if applicable).
agent_typeThe Agent type (if applicable).

Exit Codes

command type Hooks control the flow via exit codes:
Exit CodeMeaning
0Success. stdout can output JSON for the CLI to parse.
2Block. stderr content is returned as feedback to the Agent (only effective for events that support blocking; see the "Event Catalog" for event-by-event details).
OtherNon-blocking error; logged but does not interrupt the flow.
When the exit code is 0, JSON can be returned via stdout for more granular control. For the complete fields (continue, stopReason, suppressOutput, systemMessage, decision, reason, hookSpecificOutput), see the "Writing Hook Scripts" section in Hook.

Hooks in Plugins

Plugins can include Hooks, configured in hooks/hooks.json under the plugin directory, following the same format as the hooks group in settings.json. See Plugin Reference.

Next Steps