tools//Claude Code//.claude//hooks

Hooks are event-driven scripts that Claude Code runs automatically at lifecycle points. They are written in JavaScript (or shell), live in `.claude/hooks/` and are referenced from the settings.


Hooks are event-driven scripts that Claude Code runs automatically at lifecycle points. They are written in JavaScript (or shell), live in .claude/hooks/ and are referenced from the settings.

Each script receives JSON on stdin with the tool name and its input, and its exit code controls the behavior: 0 allows the action, 2 blocks it (and stdout becomes the reason shown to Claude). Each hook fires at one lifecycle point.

PreToolUseFires before a tool executes, and can block it. A matcher filters it by tool name.

PostToolUseFires after a tool succeeds, which suits linting or type-checking after edits.

StopFires when Claude finishes responding, which suits summary validation.

UserPromptSubmitFires when the user sends a message, and can intercept or transform it.

SessionStart / SessionEndFire at the start and at the end of a session.