# Everything Claude Code Hook Types Explained: 6 Event-Driven Extension Points

> Discover Claude Code hook types like PreToolUse and SessionEnd. Extend Claude Code sessions with 6 event-driven extension points for custom Node.js scripts.

- Repository: [WorldFlowAI/everything-claude-code](https://github.com/WorldFlowAI/everything-claude-code)
- Tags: deep-dive
- Published: 2026-09-07

---

**Everything Claude Code provides six distinct hook event types—`PreToolUse`, `PostToolUse`, `PreCompact`, `SessionStart`, `Stop`, and `SessionEnd`—that enable custom Node.js scripts to run at specific moments in a Claude Code session.**

The hook system in WorldFlowAI/everything-claude-code transforms Claude Code from a static assistant into a programmable development environment. Each hook type fires at a precise lifecycle moment, letting you enforce policies, automate formatting, persist state, and inject contextual awareness.

## PreToolUse Hooks: Intercept Before Tool Execution

**`PreToolUse`** hooks execute immediately before any tool invocation—`Bash`, `Write`, `Edit`, or any other Claude Code tool. This is the primary enforcement point for safety policies and workflow guardrails.

According to the source code in [[`hooks/hooks.json`](https://github.com/WorldFlowAI/everything-claude-code/blob/main/hooks/hooks.json)](https://github.com/WorldFlowAI/everything-claude-code/blob/main/hooks/hooks.json#L5-L13), these hooks evaluate a **matcher expression** against the incoming tool request:

```json
{
  "matcher": "tool == \"Bash\" && tool_input.command matches \"(npm run dev|pnpm( run)? dev|yarn dev|bun run dev)\"",
  "hooks": [{ "type": "command", "command": "node -e \"...\""}],
  "description": "Block dev servers outside tmux"
}

```

Typical `PreToolUse` use cases include:

- Blocking dangerous commands outside protected environments
- Validating file paths before destructive operations
- Suggesting context compaction when token limits approach

The [[`scripts/hooks/suggest-compact.js`](https://github.com/WorldFlowAI/everything-claude-code/blob/main/scripts/hooks/suggest-compact.js)](https://github.com/WorldFlowAI/everything-claude-code/blob/main/scripts/hooks/suggest-compact.js) helper runs from `PreToolUse` hooks to recommend manual compaction before hitting context limits.

## PostToolUse Hooks: React to Completed Operations

**`PostToolUse`** hooks trigger after a tool finishes execution, making them ideal for cleanup, formatting, and notification tasks.

From [`hooks/hooks.json#L92-L99`](https://github.com/WorldFlowAI/everything-claude-code/blob/main/hooks/hooks.json#L92-L99):

```json
{
  "matcher": "tool == \"Edit\" && tool_input.file_path matches \"\\\\.(ts|tsx|js|jsx)$\"",
  "hooks": [{ "type": "command", "command": "node -e \"...\""}],
  "description": "Auto‑format JS/TS files with Prettier after edits"
}

```

Common `PostToolUse` patterns include:

- Running **Prettier** or **ESLint** on modified files
- Logging pull request URLs to external systems
- Scanning for debugging artifacts like `console.log` statements

## PreCompact Hooks: Preserve State Before Context Reduction

**`PreCompact`** fires right before Claude Code performs context compaction—the process of summarizing conversation history to free token capacity.

The [[`scripts/hooks/pre-compact.js`](https://github.com/WorldFlowAI/everything-claude-code/blob/main/scripts/hooks/pre-compact.js)](https://github.com/WorldFlowAI/everything-claude-code/blob/main/scripts/hooks/pre-compact.js) script handles critical state preservation:

- Saving unsaved file buffers
- Recording conversation checkpoints
- Stashing ephemeral data that compaction would destroy

This hook type is essential for long-running sessions where context loss would disrupt workflow continuity.

## SessionStart Hooks: Initialize New Sessions

**`SessionStart`** executes at the beginning of every Claude Code session, providing the entry point for project detection and context restoration.

The implementation in [`hooks/hooks.json#L68-L76`](https://github.com/WorldFlowAI/everything-claude-code/blob/main/hooks/hooks.json#L68-L76) uses a universal matcher to always run initialization:

```json
{
  "matcher": "*",
  "hooks": [{ "type": "command", "command": "node \"${CLAUDE_PLUGIN_ROOT}/scripts/hooks/session-start.js\""}],
  "description": "Load previous context and detect package manager on new session"
}

```

The [[`scripts/hooks/session-start.js`](https://github.com/WorldFlowAI/everything-claude-code/blob/main/scripts/hooks/session-start.js)](https://github.com/WorldFlowAI/everything-claude-code/blob/main/scripts/hooks/session-start.js) performs two critical functions:

1. **Context restoration** — reloads prior session data for continuity
2. **Package manager detection** — identifies `npm`, `pnpm`, `yarn`, or `bun` for tool-aware behavior

## Stop Hooks: Final Checks After Every Response

**`Stop`** hooks run after each Claude Code response completes—every "stop" token from the LLM. Unlike session-scoped hooks, this fires repeatedly throughout interaction.

Primary use cases focus on **immediate feedback loops**:

- Scanning modified files for `console.log` or `debugger` statements
- Triggering quick validations on recent edits
- Updating status indicators in external tools

The frequency of `Stop` hooks demands lightweight, fast-executing commands to avoid interrupting the development flow.

## SessionEnd Hooks: Persist and Analyze Completed Sessions

**`SessionEnd`** triggers when the Claude Code session terminates, serving as the cleanup and analysis phase.

From [`hooks/hooks.json#L134-L142`](https://github.com/WorldFlowAI/everything-claude-code/blob/main/hooks/hooks.json#L134-L142):

```json
{
  "matcher": "*",
  "hooks": [{ "type": "command", "command": "node \"${CLAUDE_PLUGIN_ROOT}/scripts/hooks/session-end.js\""}],
  "description": "Persist session state on end"
}

```

Execution splits across two scripts:

- **[[`scripts/hooks/session-end.js`](https://github.com/WorldFlowAI/everything-claude-code/blob/main/scripts/hooks/session-end.js)](https://github.com/WorldFlowAI/everything-claude-code/blob/main/scripts/hooks/session-end.js)** — persists final session state to disk
- **[[`scripts/hooks/evaluate-session.js`](https://github.com/WorldFlowAI/everything-claude-code/blob/main/scripts/hooks/evaluate-session.js)](https://github.com/WorldFlowAI/everything-claude-code/blob/main/scripts/hooks/evaluate-session.js)** — analyzes the complete session for extractable patterns, useful command sequences, and optimization opportunities

## Hook Architecture and Matcher Expressions

All hook types share a common structure defined in the JSON schema. Each entry contains:

| Field | Purpose |
|-------|---------|
| `matcher` | Boolean expression evaluated against tool context |
| `hooks` | Array of commands to execute when matcher is true |
| `description` | Human-readable explanation of the hook's intent |

Matcher expressions access variables like `tool`, `tool_input`, and session state, enabling fine-grained conditional logic without writing custom code for every scenario.

## Summary

- **Six hook event types** provide complete session lifecycle coverage in Everything Claude Code
- **PreToolUse** and **PostToolUse** bracket tool execution for enforcement and cleanup
- **PreCompact** preserves state before context reduction occurs
- **SessionStart** and **SessionEnd** handle initialization and persistence
- **Stop** enables per-response validation and feedback
- All hooks are declared in [[`hooks/hooks.json`](https://github.com/WorldFlowAI/everything-claude-code/blob/main/hooks/hooks.json)](https://github.com/WorldFlowAI/everything-claude-code/blob/main/hooks/hooks.json) with matcher-based conditional execution

## Frequently Asked Questions

### What is the difference between PreToolUse and PostToolUse hooks?

**`PreToolUse`** runs before any tool executes, allowing you to block, modify, or validate the incoming request. **`PostToolUse`** runs after tool completion, making it suitable for formatting, logging, and cleanup tasks that depend on the operation's result.

### Can multiple hooks fire for the same event?

Yes. The `hooks` array in each definition supports multiple command objects. Additionally, if multiple top-level entries have matchers that evaluate to true for the same event, all matching hooks execute in declaration order.

### How do I debug a hook that isn't triggering?

Verify your matcher expression syntax against the variables available in that hook context—`tool` and `tool_input` for tool-related hooks, session variables for lifecycle hooks. Test matchers incrementally and check that the hook file path resolves correctly from `${CLAUDE_PLUGIN_ROOT}`.

### What happens if a hook command fails?

Hook execution failures are logged but typically do not block the main Claude Code flow. For `PreToolUse` hooks specifically, a failing command may prevent the underlying tool from executing depending on implementation details in the hook handler.