Configs2026年4月8日·1 分钟阅读

Claude Code Hooks — Automate Pre/Post Task Actions

Complete guide to Claude Code hooks for automating actions before and after tool calls. Set up linting, testing, notifications, and custom validation with shell commands.

What Are Claude Code Hooks?

Hooks are shell commands Claude Code runs automatically before or after tool calls. Automate linting, testing, notifications, and validation — not reliant on Claude remembering.

TL;DR: Claude Code automation hooks. Run shell commands before/after tool calls (lint/tests/block/notify). Configured in settings.json. Enforced at the harness level.

Event Types

PreToolUse (before tool), PostToolUse (after tool), Notification (status change), Stop (on completion).

Practical Examples

  1. Auto-format on write
  2. Run related tests after edits
  3. Block writes to protected files
  4. TypeScript type-check
  5. Desktop notification on completion

Hooks vs CLAUDE.md

Hooks = shell commands, 100% executed; CLAUDE.md = text instructions, best-effort compliance.

🙏

来源与感谢

讨论

登录后参与讨论。
还没有评论,来写第一条吧。

相关资产