Keyboard shortcuts

Press ← or → to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Claude Code Hooks Reference

Disclaimer: This document reflects our current understanding of Claude Code’s hook system. It is a working reference for symposium development, not a substitute for the official docs. Details may be outdated or incomplete — always consult the primary sources.

Primary sources: Hooks reference · Hooks guide · Extending Claude Code

Hooks are user-defined shell commands, HTTP endpoints, or LLM prompts that execute at specific points in the agent lifecycle. They provide deterministic control — actions always happen rather than relying on the model.

Hook Types

TypeDescription
commandShell script; communicates via stdin/stdout/exit codes
httpPOSTs JSON to a URL endpoint; supports header interpolation with $VAR_NAME
promptSingle-turn LLM evaluation returning {ok: true/false, reason}
agentSpawns a subagent with tool access (Read, Grep, Glob) for up to 50 turns

Events

EventTriggerCan block?Matcher target
SessionStartSession begins/resumesNostartup, resume, clear, compact
SessionEndSession terminates (1.5s default timeout)Noclear, resume, logout, etc.
UserPromptSubmitUser submits prompt, before processingYes (exit 2)None
PreToolUseBefore tool callYesTool name regex (Bash, Edit|Write, mcp__.*)
PostToolUseAfter tool succeedsNoTool name regex
PostToolUseFailureTool failsNoTool name regex
PermissionRequestPermission dialog appearsYesTool name regex
PermissionDeniedAuto-mode classifier denialNo (retry: true available)Tool name regex
StopMain agent finishes respondingYesNone
StopFailureTurn ends on API errorNo (output ignored)rate_limit, authentication_failed, etc.
SubagentStartSubagent spawnedNoAgent type
SubagentStopSubagent finishesYesAgent type
NotificationSystem notificationNopermission_prompt, idle_prompt, etc.
TaskCreatedTask createdYes (exit 2 rolls back)None
TaskCompletedTask completedYes (exit 2 rolls back)None
TeammateIdleTeammate about to go idleYesNone
ConfigChangeConfig file changes during sessionYes (except policy_settings)Config source
CwdChangedDirectory changeNoNone
FileChangedWatched file changesNoBasename
WorktreeCreateGit worktree createdYes (non-zero fails)None
WorktreeRemoveGit worktree removedNoNone
PreCompactBefore compactionNomanual, auto
PostCompactAfter compactionNomanual, auto
InstructionsLoadedCLAUDE.md loadedNoLoad reason
ElicitationMCP server requests user inputYesMCP server name
ElicitationResultMCP elicitation resultYesMCP server name

Configuration

Settings merge with precedence (highest first): Managed → Command line → Local → Project → User.

FileScope
Managed policy (MDM, registry, server, /etc/claude-code/)Organization-wide
.claude/settings.local.jsonSingle project, gitignored
.claude/settings.jsonSingle project, committable
~/.claude/settings.jsonAll projects (user)

CLAUDE_CONFIG_DIR moves the user level as a whole: when it is set, Claude Code reads $CLAUDE_CONFIG_DIR/settings.json and $CLAUDE_CONFIG_DIR/.claude.json and ignores ~/.claude/settings.json and ~/.claude.json, so symposium writes its global hooks and user-level MCP servers there. Verified against Claude Code 2.1.284 with the variable set: a hook and an MCP server left in the ~/ files were ignored, while symposium’s hooks under $CLAUDE_CONFIG_DIR fired (hook_started/hook_response for SessionStart in claude -p --output-format stream-json --verbose) and claude mcp list showed its server.

Configuration structure

{
  "hooks": {
    "PreToolUse": [
      {
        "matcher": "Bash",
        "hooks": [
          {
            "type": "command",
            "command": "./validate.sh",
            "if": "Bash(rm *)",
            "timeout": 60,
            "statusMessage": "Validating...",
            "async": false,
            "shell": "bash"
          }
        ]
      }
    ]
  }
}
  • matcher: regex matched against event-specific values (tool name, session source, notification type).
  • if: permission-rule syntax for additional filtering on tool events (e.g., Bash(git *), Edit(*.ts)).

Input Schema (stdin)

Base fields (all events)

{
  "session_id": "string",
  "transcript_path": "string",
  "cwd": "string",
  "permission_mode": "default|plan|auto|bypassPermissions|...",
  "hook_event_name": "string"
}

PreToolUse additions

  • tool_name: string
  • tool_input: object with tool-specific fields (command for Bash, file_path/content for Write, etc.)
  • tool_use_id: string

PostToolUse additions

  • tool_name, tool_input, tool_use_id (same as PreToolUse)
  • tool_response: string (tool output)

Stop additions

  • stop_hook_active: boolean
  • last_assistant_message: string

Output Schema (stdout)

Output is capped at 10,000 characters.

Plain text on stdout (anything that is not JSON) is added to the context on SessionStart and UserPromptSubmit; on the other events it does not reach the model. Symposium reads a format = "claude" plugin hook’s stdout the same way.

Universal fields

FieldTypeDescription
continuebooleanfalse stops Claude entirely
stopReasonstringMessage for user when continue is false
systemMessagestringWarning shown to user
suppressOutputbooleanOmits stdout from debug log

PreToolUse decision output

{
  "hookSpecificOutput": {
    "hookEventName": "PreToolUse",
    "permissionDecision": "allow|deny|ask|defer",
    "permissionDecisionReason": "string",
    "updatedInput": { "command": "safe-cmd" },
    "additionalContext": "string"
  }
}

Decision precedence across parallel hooks: deny > defer > ask > allow. The allow decision does not override deny rules from settings. updatedInput replaces the entire tool input; if multiple hooks return it, the last to finish wins (non-deterministic).

SessionStart output

{
  "hookSpecificOutput": {
    "hookEventName": "SessionStart",
    "additionalContext": "string",
    "reloadSkills": true
  }
}

reloadSkills makes Claude Code rescan the skill and command directories after the SessionStart hooks complete. Skill discovery runs before they finish, so symposium sets it on every SessionStart response; without it, the skills its sync installs are missing until the next session.

Exit Codes

CodeMeaning
0Success; stdout parsed as JSON. For SessionStart and UserPromptSubmit, stdout that is not JSON is added to the context as plain text
2Blocking error — action blocked, stderr fed to Claude
OtherNon-blocking warning, action proceeds

Execution Behavior

  • All matching hooks run in parallel.
  • Identical handlers deduplicated by command string or URL.
  • Default timeouts: 600s (command), 30s (prompt), 60s (agent), 1.5s (SessionEnd, overridable via CLAUDE_CODE_SESSIONEND_HOOKS_TIMEOUT_MS).

Environment Variables

VariableDescription
CLAUDE_PROJECT_DIRAbsolute path to project root
CLAUDE_ENV_FILEFile for persisting env vars (SessionStart, CwdChanged, FileChanged only)
CLAUDE_CODE_REMOTE"true" in remote web environments

Enterprise Controls

  • allowManagedHooksOnly: true — blocks user/project/plugin hooks.
  • allowedHttpHookUrls — restricts HTTP hook destinations.
  • disableAllHooks: true — disables everything.
  • PreToolUse deny blocks even in bypassPermissions mode.

MCP Server Registration

In addition to hooks, symposium registers itself as an MCP server in the agent’s MCP configuration. This provides an alternative integration path alongside the hook-based approach.

Configuration structure

The entry goes under mcpServers - but not in the settings.json that carries hooks. Claude Code does not read mcpServers from a settings file at either scope; entries written there are silently ignored (claude mcp list shows nothing, and a session sees no tools). MCP has its own two files:

{
  "mcpServers": {
    "symposium": {
      "command": "/path/to/symposium",
      "args": ["mcp"]
    }
  }
}
  • Project-level: <project>/.mcp.json
  • User-level: ~/.claude.json (or $CLAUDE_CONFIG_DIR/.claude.json)

Confirmed against the CLI: claude mcp add -s project writes the former, -s user the latter.

A remote entry needs an explicit type ("http" or "sse") next to its url. Without it Claude Code drops the entry at both scopes: claude mcp get reports no such server. A stdio entry is read without one. Confirmed against Claude Code 2.1.305.

A server in a project .mcp.json starts out pending approval - Claude asks before trusting a server a repository supplies. Symposium deliberately does not pre-approve its own entries (that would mean overriding a trust prompt on the user’s behalf); approve once via /mcp, or add the name to enabledMcpjsonServers in your own settings if you want it standing.

Registration is idempotent — if the entry already exists with the correct values, no changes are made. If the entry exists but has stale values (e.g. the binary moved), it is updated in place.

Plugin Delivery

A plugin enabled with use --global reaches Claude Code as a skills-directory plugin: symposium copies the compiled plugin directory into the user skills directory, ~/.claude/skills/<plugin>/ ($CLAUDE_CONFIG_DIR/skills/<plugin>/ when that variable is set, in which case Claude Code ignores ~/.claude/skills/). Claude Code loads every folder there that holds .claude-plugin/plugin.json as the plugin <plugin>@skills-dir, in place, in every project. Its skills are invoked as /<plugin>:<skill>.

Nothing is written to settings.json, known_marketplaces.json or installed_plugins.json. A user who runs claude plugin disable <plugin>@skills-dir gets an enabledPlugins entry that symposium never touches.

Verified against Claude Code 2.1.284 by asking the agent (claude plugin list --json, claude plugin details, and the system/init event of claude -p):

  • The plugin is listed in the first session after symposium sync, and claude plugin list shows it without a prior session.
  • An edit at the same version is picked up by the next session: the copy is read in place, and nothing is cached under ~/.claude/plugins/cache/.
  • Removing the directory removes the plugin, with no residue and no error.
  • A plugin written during the SessionStart hook (symposium’s auto-sync) loads in the next session, or after /reload-plugins in the current one.
  • A plain SKILL.md folder of the user’s own next to it is unaffected.

The alternative, registering the staging root as a directory marketplace (extraKnownMarketplaces plus enabledPlugins), also loads in place, but Claude Code then writes ~/.claude/plugins/known_marketplaces.json and installed_plugins.json entries of its own that outlive the registration.

Project scope

Every other plugin that applies to the project reaches Claude Code the same way, one level down: symposium copies the compiled directory from the project staging root (<project>/.symposium/plugins/<plugin>/) into <project>/.claude/skills/<plugin>/ and adds a .gitignore containing * inside it. Claude Code loads it as a project-scoped <plugin>@skills-dir, in that project only. Nothing is written to any settings file.

Claude Code looks for these plugins only in the directory it starts in. Its documentation says so: unlike plain skills, it does not search parent directories for plugins, and the fix it gives is to launch from the repository root or /cd there. Symposium installs them at the workspace root and leaves that rule as it is. The alternatives were weighed in #353: a local marketplace enabled from settings.local.json, which Claude Code reads at the git root, means writing the user’s settings and managing Claude Code’s plugin cache; linking the plugins into each session’s directory from the SessionStart hook comes too late for that session, since plugins load before the hook runs.

Verified against Claude Code 2.1.284, logged out and offline (the system/init event of claude -p, claude plugin list --json, and the TUI’s / completion):

  • Started at the workspace root, a trusted folder, it loads each one as a project-scope <plugin>@skills-dir and offers its skills as /<plugin>:<skill>, with no bare duplicate.
  • Started in a member crate, it loads none of them, and claude plugin list is empty there. The per-skill copies symposium wrote before were found from there, since plain skills are searched in parent directories.
  • Only in a folder the user has trusted. Untrusted, claude -p loads none of them and claude plugin list shows (suppressed)@skills-dir, while plain project skills still load. In the TUI session that accepts the trust prompt they load only after /reload-plugins; later sessions load them at start.
  • Repository B, with the same profile, does not see repository A’s plugins. Two repositories carrying a plugin of the same name with different content, open at the same time, each load their own.
  • The .gitignore inside the directory does not affect loading.
  • An edit at the same version is picked up by the next session, and removing the directory leaves nothing listed and no error.
  • A plugin written during the SessionStart hook loads in the next session, or after /reload-plugins in the current one.
  • A user-level plugin of the same name shadows the project one, and claude plugin list reports it.

The Copilot CLI (1.0.89) and Goose (1.54.0) read <project>/.claude/skills/ too, and take the skills inside <plugin>/skills/ as plain project skills, as they took the per-skill copies before. Configured in the same project, each lists every skill once, from its own copy in .agents/skills/.