Interactive tree · Claude Code

Claude Code Hooks — Interactive Playbook

Hover any node for a hint. Click a dotted node to open the detail panel — the map stays clean, depth lives behind the click.

ROOT Claude Code Hooks starter playbook ◆ What & why the mental model ▾ A script that always runs at a lifecycle moment Deterministic control over a probabilistic agent Always fires — CLAUDE.md, Claude may forget No need to modify Claude Code itself ◆ 6 events you'll use the surface ▾ PreToolUse — before a tool runs (block/approve) PostToolUse — after a tool succeeds (react/fix) Stop — turn ends (notify/gate) Notification — Claude needs your input SessionStart — session begins (load state) SessionEnd — session closes (cleanup) ▸ Start here first 2 hooks ▾ PostToolUse → auto-format every edited file Stop → desktop chime when turn is done ▸ Safety uses PreToolUse ▾ ⚠ Block dangerous shell (rm -rf, DROP TABLE) ⚠ Protect .env / secrets / .git from edits Auto-approve safe reads (Read/Grep/Glob) ▸ Code-quality uses PostToolUse / Stop ▾ Auto-format changed file (Prettier/gofmt/Black) Auto-lint changed file, feed errors back Typecheck after .ts change (tsc --noEmit) Gate completion on green tests (Stop) ▸ Notification uses Notification / Stop ▾ Desktop popup when Claude needs input Sound / alert when task finishes Slack / webhook ping on completion ▸ Context-inject uses SessionStart ▾ Inject project conventions / CLAUDE.md Inject git branch + recent commits Reload env vars (direnv) ▸ Logging uses PostToolUse / SessionEnd ▾ Log every Bash command with timestamp Audit config / settings changes Clean up temp files on session end ⚙ How to wire one the mechanics ▾ Put it in .claude/settings.json under hooks matcher = which tool (Bash, Edit|Write) if = finer filter: Bash(git *), Edit(*.ts) Script reads JSON payload on stdin Reply: exit 0 = allow, exit 2 = block Or stdout JSON for allow/deny + reason Inspect yours with /hooks ⚠ Safety & gotchas before you trust it ▾ Hooks run arbitrary code on your machine Project hooks run only after you trust the folder User hooks (~/.claude) always run New hooks activate next session, not current LEGEND Concept / reference Do-this Danger / gotcha Root · focal Hover a node for a hint · click a dotted node for detail.
Vòng đời hook (chính thức)
Setup (Opt-in) Session Start UserPromptSubmit EACH TURN UserPrompt Expansion (slash commands) AGENTIC LOOP PreToolUse PermissionRequest Permission Denied (auto-mode deny) [tool executes] PostToolUse / PostToolUseFailure PostToolBatch SubagentStart / SubagentStop TaskCreated TaskCompleted Stop / StopFailure TeammateIdle PreCompact PostCompact SessionEnd Notification (Async) ConfigChange (Async) WorktreeCreate (Isolation) WorktreeRemove (Teardown) CwdChanged FileChanged DirectoryAdded (Env reactive) Elicitation (MCP input) ElicitationResult (MCP input) InstructionsLoaded (Async) MessageDisplay (Display) resumed sessions
Nguồn: Claude Code docs →