Claude Code hook input reference: Stop, Notification and UserPromptSubmit
Updated 2026-12-04
A Claude Code hook is a command that Claude Code runs at a given moment and feeds a JSON object on stdin. This page lists what is in that JSON for the three hooks that matter for notifications: Stop, Notification and UserPromptSubmit. It is based on the official hooks reference, checked on 2 December 2026. Claude Code changes quickly, so treat the official page as the authority.
Where hooks are configured
| File | Scope |
|---|---|
~/.claude/settings.json | All your projects |
.claude/settings.json | One project, can be committed and shared |
.claude/settings.local.json | One project, kept out of git |
Hooks are also read from managed policy settings, from plugins and from skill and subagent frontmatter. The structure is: event, then a matcher group, then a list of handlers.
{
"hooks": {
"Notification": [
{
"matcher": "permission_prompt|idle_prompt",
"hooks": [ { "type": "command", "command": "node ~/notify.mjs", "timeout": 10 } ]
}
]
}
}
matcher set to *, empty or left out matches everything. Other values are exact strings or regular expressions. type can be command, http, mcp_tool, prompt or agent. timeout is in seconds; the default is 600 for command hooks.
Fields every hook receives
The documented common fields are session_id, prompt_id, transcript_path, cwd, scratchpad_dir, permission_mode, effort and hook_event_name. Hooks that fire inside a subagent also get agent_id, and agent_type when the session uses --agent or the hook fires inside a subagent.
Stop
Fires when Claude finishes responding. On top of the common fields it receives:
last_assistant_message: the text of Claude's final response, so you do not have to parse the transcript file.stop_hook_active:truewhen Claude Code is already continuing because of a stop hook. Check it so your hook does not loop.background_tasksandsession_crons.
A Stop hook can keep Claude going: exit code 2, or JSON on stdout with "decision": "block" and a reason. A notification hook should do neither and exit 0.
{
"session_id": "abc123",
"transcript_path": "/home/me/.claude/projects/.../abc123.jsonl",
"cwd": "/home/me/my-project",
"permission_mode": "default",
"hook_event_name": "Stop",
"stop_hook_active": false,
"last_assistant_message": "Done. I fixed the failing test and ..."
}
That example is illustrative: field names are from the documentation, the values are made up and shortened.
Notification
Fires when Claude Code sends a notification. It receives message (the notification text), an optional title and notification_type, which says which kind fired. The matcher is matched against that type. The documented types include:
notification_type | When it fires |
|---|---|
permission_prompt | Claude needs approval for a tool use and the prompt has waited about six seconds |
idle_prompt | Claude finished about 60 seconds ago and you have not typed since |
auth_success | Authentication completed |
elicitation_dialog | An MCP server opened a form and you have not typed for about six seconds |
agent_completed, agent_needs_input | Background sessions, while the agent view is open in a terminal |
The official page lists a few more (for example usage-limit events). Notification hooks cannot block or change the notification; they can only react to it.
Two things follow for a notifier. A permission prompt only produces a notification after about six seconds, so a quick approval at the keyboard never pings. And idle_prompt is a reminder 60 seconds after the task finished, which most people do not want as a second ping.
UserPromptSubmit
Fires when you submit a prompt, before Claude processes it. It receives prompt, the submitted text. It is useful for recording when a task started, so the Stop hook can tell how long the task took and skip tasks shorter than, say, 15 seconds. Plain text on stdout from this hook is added as context for Claude, so do not print anything you do not mean Claude to read.
SubagentStop
When Claude spawns a subagent, that subagent finishing fires SubagentStop, with agent_id, agent_type, agent_transcript_path, last_assistant_message and stop_hook_active. If you only want a notification for the main task, use the Stop hook and ignore events that carry an agent_id.
Exit codes and output
| Exit code | Meaning |
|---|---|
| 0 | Success. JSON on stdout is applied. Claude never sees stderr from a hook that exits 0. |
| 2 | Blocking error; stderr is the reason. For Stop it prevents Claude from stopping. |
| anything else | Non-blocking error; Claude carries on and shows a notice. |
A notification command that fails with exit code 2 will therefore stop Claude from finishing. Make sure yours exits 0 even when the push fails (|| true).
Environment
CLAUDE_PROJECT_DIR holds the project root where the session started. Plugins also get CLAUDE_PLUGIN_ROOT and CLAUDE_PLUGIN_DATA. There is no model environment variable.
See the real payload on your machine
The quickest way to learn the fields is to log them. Add this as a Stop and a Notification hook command, trigger both, and read the file:
cat >> /tmp/hook-payloads.log; echo >> /tmp/hook-payloads.log
On Windows use a small Node script instead, because cat and /tmp are not there. Node can read stdin with fs.readFileSync(0, "utf8").
How InstantPing uses this
InstantPing's hook reads exactly these fields. It uses Stop for "done" and Notification for "waiting", records the start time from UserPromptSubmit to skip short tasks, ignores events with an agent_id and loops with stop_hook_active, and drops the 60-second idle reminder. You can see the whole setup in the hook guide.
Frequently asked questions
Does the Claude Code Stop hook receive Claude's last message?
Yes. The Stop hook input includes last_assistant_message, the text of Claude's final response, so a hook can use it without reading the transcript file.
How do I tell a subagent from the main session in a hook?
Hooks that fire inside a subagent receive an agent_id (and agent_type). The SubagentStop event always carries them. To notify only for the main task, use Stop and skip events that have an agent_id.
What does stop_hook_active mean?
It is true when Claude Code is already continuing because a stop hook told it to. A hook that keeps Claude going should check it to avoid an endless loop.
When does the Claude Code Notification hook fire for a permission prompt?
After the permission prompt has been waiting for about six seconds. Its notification_type is permission_prompt. If you approve within those seconds, no notification fires.
What happens if my notification hook exits with code 2?
Exit code 2 is a blocking error. On the Stop event it stops Claude from finishing. Any other non-zero code is a non-blocking error that only shows a notice. Make notification commands exit with 0.
How long can a Claude Code command hook run?
The default timeout is 600 seconds for command hooks. You can set a shorter timeout in seconds per handler, which is sensible for a notification.