Skip to content

Hooks ​

Hooks are programs a plugin runs at points in the agent's work: before a tool call, after it, when you send a message, when the agent is about to finish. A hook can add context for the model, block an action, ask you to approve it, or make the agent keep going.

Nora reads hooks in the Claude Code format, so existing hooks work, with a few differences worth knowing.

Configure hooks ​

Put them in hooks/hooks.json in your plugin:

json
{
  "hooks": {
    "PreToolUse": [
      {
        "matcher": "Bash|Write|Edit",
        "hooks": [
          { "type": "command", "command": "${CLAUDE_PLUGIN_ROOT}/hooks/guard.sh", "timeout": 30 }
        ]
      }
    ]
  }
}
KeyMeaning
Event nameWhen the hooks run. One of the events below.
matcherA regular expression for the tool name, for tool events. Claude Code names (Bash, Read, Edit, Write, Grep, Glob) and Nora's own names (bash, read, edit, write) both work. Leave it out to match every tool.
typecommand runs a program. http posts the input to a URL.
commandThe program to run. ${CLAUDE_PLUGIN_ROOT} (or ${NORA_PLUGIN_ROOT}) is the plugin's folder.
timeoutSeconds before the hook is stopped.

How a hook talks to Nora ​

  1. Nora starts the program and writes the event as one JSON object to its standard input.
  2. The program decides with its exit code and, optionally, JSON on standard output.
The hook…Effect
exits 0 with no outputNothing changes; the work carries on.
exits 2Blocks the action. What it wrote to standard error is shown to the agent as the reason.
exits 0 and prints JSONNora reads the decision from the JSON, as described for each event.
exits with another codeThe hook failed. Nora shows the error and carries on.

Every event's input includes:

FieldMeaning
hook_event_nameThe event, for example PreToolUse.
session_idThe conversation's session.
cwdThe agent's working directory.
workspaceRootThe project's root folder.
permissionModeThe current permission mode.
timestampWhen the event happened.

Events ​

EventWhenCan it change anything?
SessionStartA session starts.No
UserPromptSubmitYou send a message.Add context, or block the message
PreToolUseBefore a tool call.Allow, block or ask you
PostToolUseAfter a tool call succeeds.Add context, or flag a problem
PostToolUseFailureAfter a tool call fails.Add context
StopThe agent is about to finish its turn.Make it keep going
SubagentStart, SubagentStopA subagent starts or finishes.SubagentStop can make it keep going
PreCompact, PostCompactAround compacting the conversation.No
NotificationNora notifies you.No
SessionEndA session ends.No

SessionStart ​

Runs when a session starts. Use it to prepare something, such as warming a cache or starting a helper.

InputMeaning
sourceHow the session started.

UserPromptSubmit ​

Runs when you send a message, before the model sees it. Has no matcher.

InputMeaning
promptThe message you sent.
OutputEffect
hookSpecificOutput.additionalContextText added to what the model sees with your message.
"decision": "block" with a reasonThe message is not sent; the reason is shown.

Example: add the current branch to every message. See git-context.

json
{
  "hookSpecificOutput": {
    "hookEventName": "UserPromptSubmit",
    "additionalContext": "Current Git branch: fix/login"
  }
}

PreToolUse ​

Runs before a tool call. The most useful hook for safety rules.

InputMeaning
tool_nameNora's tool name, such as bash, read, edit or write.
tool_inputThe call's arguments, for example command for bash and path for file tools.
tool_use_idThe call's ID.
OutputEffect
exit code 2Block the call.
permissionDecision: "deny"Block the call; permissionDecisionReason tells the agent why.
permissionDecision: "ask"Ask you first. In the app, a card with the reason appears in the conversation; the call runs only if you approve.
permissionDecision: "allow"Allow the call.
permissionDecision: "defer"Leave it to Nora's normal permissions.
json
{
  "hookSpecificOutput": {
    "hookEventName": "PreToolUse",
    "permissionDecision": "ask",
    "permissionDecisionReason": "This deletes the build folder."
  }
}

If you stop the turn while an approval is waiting, the request is withdrawn and the call does not run. See protect-secrets for a blocking hook.

PostToolUse ​

Runs after a tool call succeeds.

InputMeaning
tool_name, tool_input, tool_use_idAs for PreToolUse.
tool_responseWhat the tool returned.
OutputEffect
hookSpecificOutput.additionalContextText added for the model, for example lint results.
exit code 2 or "decision": "block"Tells the agent something is wrong with the result, with the reason.

See format-on-edit.

PostToolUseFailure ​

Runs after a tool call fails. Its input adds the error. It can return additionalContext, for example a hint about the usual cause.

Stop ​

Runs when the agent is about to end its turn. Has no matcher.

InputMeaning
stopHookActivetrue when the agent is already continuing because a Stop hook blocked it before.
lastAssistantMessageThe start of the agent's final answer.
OutputEffect
"decision": "block" with a reasonThe agent keeps working, with the reason as its next instruction.

WARNING

Check stopHookActive and let the agent stop when it is true, or a goal the agent cannot reach will loop forever. See tests-before-done.

SubagentStart and SubagentStop ​

Run when a subagent starts and finishes. Their input adds subagentType and agentId. SubagentStop can block like Stop to make the subagent keep going.

PreCompact and PostCompact ​

Run before and after Nora compacts the conversation to free context. Their input adds trigger, what caused the compaction.

Notification ​

Runs when Nora notifies you. Its input adds notificationType, such as permission_prompt when approval is needed or idle_prompt when a turn ends, and a message. Use it to forward notifications elsewhere.

SessionEnd ​

Runs when a session ends. Its input adds the reason. Use it to clean up.

Differences from Claude Code ​

Claude CodeNora
Tool names in tool_nameBash, Read, Editbash, read, edit (matchers accept both)
File path in tool_inputfile_pathpath
Stop loop flagstop_hook_activestopHookActive

Read both spellings, for example jq -r '.tool_input.path // .tool_input.file_path', and one hook works in both.

Where hooks run ​

In the app, only hooks from installed plugins run. The nora command can also run hooks you configure for yourself or for a project.

Test a hook ​

Run the script by hand with a sample input:

sh
echo '{"tool_name":"read","tool_input":{"path":"config/.env"}}' | ./hooks/protect.sh
echo $?   # 2 means blocked

Then load the plugin for a run with nora --plugin-dir ./my-plugin.

Nora for macOS 14 and later.