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
| Type | Description |
|---|---|
command | Shell script; communicates via stdin/stdout/exit codes |
http | POSTs JSON to a URL endpoint; supports header interpolation with $VAR_NAME |
prompt | Single-turn LLM evaluation returning {ok: true/false, reason} |
agent | Spawns a subagent with tool access (Read, Grep, Glob) for up to 50 turns |
Events
| Event | Trigger | Can block? | Matcher target |
|---|---|---|---|
SessionStart | Session begins/resumes | No | startup, resume, clear, compact |
SessionEnd | Session terminates (1.5s default timeout) | No | clear, resume, logout, etc. |
UserPromptSubmit | User submits prompt, before processing | Yes (exit 2) | None |
PreToolUse | Before tool call | Yes | Tool name regex (Bash, Edit|Write, mcp__.*) |
PostToolUse | After tool succeeds | No | Tool name regex |
PostToolUseFailure | Tool fails | No | Tool name regex |
PermissionRequest | Permission dialog appears | Yes | Tool name regex |
PermissionDenied | Auto-mode classifier denial | No (retry: true available) | Tool name regex |
Stop | Main agent finishes responding | Yes | None |
StopFailure | Turn ends on API error | No (output ignored) | rate_limit, authentication_failed, etc. |
SubagentStart | Subagent spawned | No | Agent type |
SubagentStop | Subagent finishes | Yes | Agent type |
Notification | System notification | No | permission_prompt, idle_prompt, etc. |
TaskCreated | Task created | Yes (exit 2 rolls back) | None |
TaskCompleted | Task completed | Yes (exit 2 rolls back) | None |
TeammateIdle | Teammate about to go idle | Yes | None |
ConfigChange | Config file changes during session | Yes (except policy_settings) | Config source |
CwdChanged | Directory change | No | None |
FileChanged | Watched file changes | No | Basename |
WorktreeCreate | Git worktree created | Yes (non-zero fails) | None |
WorktreeRemove | Git worktree removed | No | None |
PreCompact | Before compaction | No | manual, auto |
PostCompact | After compaction | No | manual, auto |
InstructionsLoaded | CLAUDE.md loaded | No | Load reason |
Elicitation | MCP server requests user input | Yes | MCP server name |
ElicitationResult | MCP elicitation result | Yes | MCP server name |
Configuration
Settings merge with precedence (highest first): Managed → Command line → Local → Project → User.
| File | Scope |
|---|---|
Managed policy (MDM, registry, server, /etc/claude-code/) | Organization-wide |
.claude/settings.local.json | Single project, gitignored |
.claude/settings.json | Single project, committable |
~/.claude/settings.json | All 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: stringtool_input: object with tool-specific fields (commandfor Bash,file_path/contentfor 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: booleanlast_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
| Field | Type | Description |
|---|---|---|
continue | boolean | false stops Claude entirely |
stopReason | string | Message for user when continue is false |
systemMessage | string | Warning shown to user |
suppressOutput | boolean | Omits 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
| Code | Meaning |
|---|---|
0 | Success; stdout parsed as JSON. For SessionStart and UserPromptSubmit, stdout that is not JSON is added to the context as plain text |
2 | Blocking error — action blocked, stderr fed to Claude |
| Other | Non-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
| Variable | Description |
|---|---|
CLAUDE_PROJECT_DIR | Absolute path to project root |
CLAUDE_ENV_FILE | File 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
bypassPermissionsmode.
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, andclaude plugin listshows 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
SessionStarthook (symposium’s auto-sync) loads in the next session, or after/reload-pluginsin the current one. - A plain
SKILL.mdfolder 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-dirand offers its skills as/<plugin>:<skill>, with no bare duplicate. - Started in a member crate, it loads none of them, and
claude plugin listis 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 -ploads none of them andclaude plugin listshows(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
.gitignoreinside 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
SessionStarthook loads in the next session, or after/reload-pluginsin the current one. - A user-level plugin of the same name shadows the project one, and
claude plugin listreports 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/.