Saved image — no attribution recorded
— saved image
18 Claude Code Hook Ideas for Context Engineers | Hook | What It Does | Why It Matters | |---|---|---| | Auto-format context files | PostToolUse on Edit\|Write — run a linter/formatter on .md, .yaml, .jsonl files | Keep your modular context architecture (CLAUDE.md, rules, skills) consistently formatted across your project | | Dynamic context injection at startup | SessionStart — pull open GitHub issues, recent PRs, or tickets and inject as context | Auto-load the right context so Claude starts every session informed about what's in flight | | Context re-injection after compaction | SessionStart with matcher compact — re-inject critical project state | Long sessions lose state during compaction. A hook restores architectural decisions and in-progress work automatically | | Guard protected files | PreToolUse on Edit\|Write — block edits to .env, credentials, secrets, sensitive schemas | Hard-block accidental credential or data exposure at the hook level before Claude even touches the file | | Block dangerous shell commands | PreToolUse on Bash — deny rm -rf, git push --force, DROP TABLE, etc. | Safety net when Claude operates autonomously in dontAsk mode | | Auto-run tests after code changes | PostToolUse (async) on Write\|Edit — run test suite in background | Tests run while Claude keeps working. Results arrive next turn with no idle time | | LLM-powered quality gate on Stop | Stop with type: "prompt" — Haiku checks if the task is actually complete | Prevents Claude from stopping prematurely. "Did you actually finish all subtasks?" | | Agent-based verification gate | Stop with type: "agent" — subagent reads files and verifies changes are correct | The verifier can grep for broken imports, missing exports, or incomplete definitions before Claude calls it done | | Skill/config change auditing | ConfigChange with matcher skills — log every change to .claude/skills/ | Track when skills or settings are modified mid-session so nothing drifts silently | | Auto-approve safe read operations | PermissionRequest on Read\|Glob\|Grep — auto-allow with behavior: "allow" | Eliminate permission friction for read-only exploration during deep codebase research | | Rewrite Bash commands before execution | PreToolUse on Bash — use updatedInput to inject env vars or modify commands | Auto-prefix commands with your runtime setup, or redirect logs to a standard location across repos | | Inject repo-specific context per subagent | SubagentStart — add additionalContext based on agent type | When Claude spawns an Explore agent, inject project-specific constraints and conventions automatically | | Persist env vars for the session | SessionStart — write to $CLAUDE_ENV_FILE | Source your runtime, set NODE_ENV, configure API keys once. Every Bash command Claude runs inherits them | | Prompt validation and context enrichment | UserPromptSubmit — scan prompts and inject additional context | Auto-detect what module the user is asking about and inject relevant docs as additional context | | Background deploy watcher | PostToolUse (async) on Bash — detect deploy commands and track status | After Claude runs a deploy, monitor it in the background and report back when it succeeds or fails | | Prevent premature task completion | TaskCompleted — run tests or lint before allowing a task to close | Enforce that code passes validation before any task is marked complete in agent teams | | Worktree hooks for parallel experiments | WorktreeCreate/WorktreeRemove — custom setup/teardown | Spin up isolated copies of your repo with the right env, tear down cleanly when done | | HTTP webhook to external dashboard | Any event with type: "http" — POST to your own endpoint | Stream Claude's activity (tool usage, session length, errors) to a dashboard for observability |
Note from Claude Sonnet 5
Table titled '18 Claude Code Hook Ideas for Context Engineers' listing hook names, what each does, and why it matters, covering context injection, guardrails, testing, and observability hooks.