Skip to main content
Reference

Hooks Reference

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

Hooks let you automatically run custom logic at specific moments in the Qoder CLI CN lifecycle — for example validating before tool calls, injecting context at session start, or triggering external processes on file changes. This page is the complete Hooks reference.

Event types

Hooks can bind to the following events:
EventWhen it fires
PreToolUseBefore a tool call.
PostToolUseAfter a tool call succeeds.
PostToolUseFailureAfter a tool call fails.
UserPromptSubmitWhen the user submits a prompt.
SessionStartSession start.
SessionEndSession end.
StopWhen the main Agent stops responding.
StopFailureWhen the stop process fails.
SubagentStartSubagent start.
SubagentStopSubagent stop.
PreCompactBefore context compaction.
PostCompactAfter context compaction.
NotificationWhen a notification is produced.
ConfigChangeWhen configuration changes.
InstructionsLoadedAfter project instructions load.
CwdChangedWhen the working directory changes.
FileChangedWhen a file changes.
WorktreeCreateWhen a Worktree is created.
WorktreeRemoveWhen a Worktree is removed.
ElicitationWhen an information elicitation is initiated.
ElicitationResultWhen an elicitation result returns.
TaskCreatedWhen a task is created.
TaskCompletedWhen a task completes.
PermissionRequestWhen a permission request is raised.
PermissionDeniedWhen a permission is denied.
TeammateIdleWhen a collaborator goes idle.
SetupAt initial installation.
Each event's matcher field, additional stdin input fields, blocking support, and available hookSpecificOutput fields vary by event.

Hook types

Each Hook specifies its execution type via type:
TypeDescription
commandRun a shell command.
httpSend an HTTP request.
promptAn independent single-turn model call for judgment; the model returns { ok, reason }, and ok=false blocks.
agentLaunch a subagent for validation, returning { ok, reason } via StructuredOutput; ok=false blocks.
The complete fields of each type (such as http's url/headers, and the return contracts of prompt and agent) vary by type; for configuration, see "Definition structure" below.

Definition structure

Hooks are configured per event in the hooks group of settings.json. Each event maps to a set of Hook definitions:
{
  "hooks": {
    "PreToolUse": [
      {
        "matcher": "Bash",
        "hooks": [
          { "type": "command", "command": "./scripts/check.sh" }
        ]
      }
    ]
  }
}
Hook definition (group) fields:
FieldDescription
matcherThe matching rule (see below), deciding which targets this Hook group applies to.
hooksAn array of Hooks, each with a type and the corresponding parameters.
Besides type and type-specific parameters, a single Hook entry also supports fields such as name, timeout, if, and async (background execution without blocking the main flow).

Matching rules

matcher decides which targets (such as tool names) a Hook applies to:
  • Empty or *: matches everything.
  • Exact value: such as Bash, matching only that target.
  • Pipe |: multiple values, such as Bash|Edit|Write.
  • Regex: regular expression matching is supported.
Finer-grained if conditions can be written as "ToolName" or "ToolName(arg_glob)", where arg_glob matches tool arguments with a glob pattern.

Input and exit codes

Input (stdin)

A Hook receives a JSON payload via stdin containing the current context (the fields below are common to all events; each event also has its own fields):
FieldDescription
session_idThe current session ID.
transcript_pathThe session transcript file path.
cwdThe current working directory.
hook_event_nameThe triggered event name.
permission_modeThe current permission mode.
agent_idThe triggering Agent ID (if applicable).
agent_typeThe Agent type (if applicable).

Exit codes

command-type Hooks control the flow via exit codes:
Exit codeMeaning
0Success. stdout may output JSON for the CLI to parse.
2Block. stderr content is returned to the Agent as feedback (only for events that support blocking).
OtherA non-blocking error, recorded without interrupting the flow.
With exit code 0, the Hook can return JSON via stdout for finer control; available fields include continue, stopReason, suppressOutput, systemMessage, decision, reason, and hookSpecificOutput.

Hooks in plugins

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

Next steps