Skip to main content

Hooks

A hook is your own shell command that the agent runs at a certain moment of its work: before a tool call, after it, when the user sends a message, when a turn ends. Hooks are written in the Claude Code hooks format, so the agent reads a Claude Code hooks file as is.

tip

Ask the agent: "Add a hook: run prettier after every edit of a .ts file". It creates .explyt/hooks.json with the right entry.

Where the agent looks for hooks​

FileWhose
~/.explyt/hooks.jsonyours, for all projects
<project>/.explyt/hooks.jsonthe project's
~/.claude/settings.json, <project>/.claude/settings.json, <project>/.claude/settings.local.jsonClaude Code; only the hooks key is read
~/.codex/hooks.json, <project>/.codex/hooks.jsonCodex
hooks/hooks.json of every plugin enabled in the projecta Marketplace plugin

<project> is the session's working directory; the agent doesn't search up the tree. Claude Code and Codex files are read only if you allowed importing that tool's settings (/import-agents or otherAgents in settings). A missing file is simply skipped.

File format​

{
"hooks": {
"PreToolUse": [
{ "matcher": "Bash", "hooks": [ { "type": "command", "if": "Bash(rm *)", "command": "~/bin/no-rm.sh" } ] }
],
"PostToolUse": [
{ "matcher": "Edit|Write", "hooks": [ { "type": "command", "command": "npx prettier --write \"$(jq -r .tool_input.file_path)\"" } ] }
]
}
}

Event → list of groups with a matcher → list of hooks handlers. The agent runs only type: command handlers; http, mcp_tool, prompt and agent are skipped with a warning (make an HTTP request with curl in a command).

Handler fieldMeaning
typecommand; required
commandrequired; runs through the shell of the bash tool in the project root
argsif set, command runs directly with these arguments, without a shell
ifa condition on the call arguments for tool events: Bash(git *), Edit(*.ts)
timeoutseconds; 600 by default, 30 for UserPromptSubmit and Stop
statusMessagethe text the terminal shows while the handler runs
asyncstart without waiting; the handler's decisions have no effect

The command receives the event data as a JSON object on stdin and CLAUDE_PROJECT_DIR in the environment; ${CLAUDE_PROJECT_DIR} is substituted in command and args. Exit code 0 with a JSON object on stdout applies its fields; code 2 blocks the action with stderr as the reason (on events that can be blocked); any other code, a timeout or invalid JSON is a hook error: the agent shows a notice, and the action goes ahead.

An empty matcher or * matches everything; letters, digits, _, -, spaces, , and | make a list of exact names; anything else is a regular expression.

Events​

EventWhenWhat it can do
SessionStarta session started, resumed, forked or was cleared, and after a summaryadd context
SessionEndthe session endedobserve
UserPromptSubmitthe user's message reached the agentadd context, block the message
PreToolUsebefore a tool callallow, deny, ask, add context
PermissionRequestbefore a confirmation questionallow, deny
PostToolUse, PostToolUseFailureafter a tool calladd context, replace the output (PostToolUse)
PostToolBatchafter the tool calls of one model turnadd context
Stopthe turn ended normallycontinue the turn with a reason
StopFailurethe turn ended with an errorobserve
SubagentStart, SubagentStopa subagent started or finishedadd context for the subagent (at start)
PreCompactbefore a context summary or a clearing of old tool outputsblock it
PostCompactafter a successful summary or clearingobserve

For PreCompact and PostCompact the matcher is manual for /compact and auto for automatic compaction. Notification, PreModelSwitch, PostModelSwitch and other Claude Code events that have no matching moment here are skipped with a warning that suggests what to use instead. Inside a subagent only PreToolUse, PermissionRequest, PostToolUse, PostToolUseFailure, PostToolBatch, PreCompact and PostCompact fire.

Tool names​

tool_name is the name as in Claude Code: Bash, Read, Write, Edit (also matches MultiEdit), Grep, Glob, LS, Agent (and Task), WebFetch, WebSearch, TodoWrite, AskUserQuestion, Skill; an MCP server tool is mcp__<server>__<tool>. A matcher also matches the agent's own tool name (bash, edit, …). There is no notebook tool: NotebookEdit matches nothing.

Approving project hooks​

Hooks from a project file (.explyt/hooks.json, .claude/settings*.json, .codex/hooks.json) run only after you approve them.

A new file waits in the same startup question that approves project MCP servers (MCP servers). A checked row allows the file, an unchecked one denies it, and a dismissed question leaves it waiting. The answer is stored along with the answers about servers and survives edits to the file; you can change it with the a key on the file's row in /hooks.

The hooks.projectFiles setting changes the rule for files without an answer:

  • ask (default) asks the question;
  • allow runs them without a question;
  • deny never runs them and never asks.

When nobody can answer (a run without a UI, a subagent, an IDE without forms, the bypassPermissions and afk modes), a file without an answer doesn't run under ask.

Your global hooks (~/.explyt/hooks.json) don't need approval.

Plugin hooks​

The hooks/hooks.json of a Marketplace plugin runs in every project where the plugin is enabled, without a question: enabling a plugin is consent to all of its parts, as with its MCP servers. So before installing, look at hooks/hooks.json in the plugin's repository; the source link is on its catalog page. You can turn off a plugin's file only with your own setting, its plugin:<id>/hooks.json ID in the global hooks.disabledFiles; disabling the plugin removes its hooks. A plugin hook command gets ${PLUGIN_ROOT} (the installation directory) and ${PLUGIN_DATA} (the plugin's data directory) substituted, and besides them CLAUDE_PLUGIN_OPTION_<KEY> in the environment for each plugin variable, secrets included. An invalid plugin hooks file shows up in /hooks as a problem of the plugin. How the hooks file is described in the plugin format is covered in the format reference.

What a hook can do without asking you​

An approved project hook (or any project hook under allow) can skip confirmation: an allow answer to PreToolUse or PermissionRequest runs the call without a question in the default and paranoid modes. Calls that the confirmation table marks as "always ask", such as sudo, still ask; deny blocks in any mode. Hook files are protected paths: writing to .explyt/hooks.json, .codex/hooks.json and .explyt/plugins.json (enabling a plugin there runs its hooks) asks for confirmation in the default and paranoid modes.

Settings​

KeyLevelDefaultMeaning
hooks.enabledglobal onlytruefalse turns off all hooks
hooks.disabledFilesboth[]IDs of files that don't run; a project entry turns off only project files, global and plugin files only the global one
hooks.projectFilesglobal onlyaskwhat a project file without an answer does: ask, allow, deny

/hooks shows the file IDs (global:.explyt/hooks.json, project:.claude/settings.json, plugin:<id>/hooks.json, …). disableAllHooks from Claude Code and Codex files is not read; turn off the file through hooks.disabledFiles instead. Settings levels are described in Settings.

The /hooks command​

/hooks in the terminal shows each file, its hooks, state and approval; the command doesn't exist in an IDE session.

When changes take effect​

Hook files and the hooks.* keys are read once at session start: an edit applies after /reload or in a new terminal session, and in the IDE in a new chat. Switches and approvals in /hooks apply at once.

Differences from Claude Code​

  • The default Stop timeout is 30 s, not 600.
  • updatedInput, continue: false, stopReason, onFailure and defer are not read; asyncRewake works as plain async; once is not read.
  • PreModelSwitch and PostModelSwitch are not supported.
  • Context added by a hook is cut at 10,000 characters with a marker.
  • permission_mode in the input can be paranoid or afk; StopFailure always passes error: "unknown".

A Codex hook turned off in its config.toml runs here; turn off the file through hooks.disabledFiles. A matcher on apply_patch catches nothing; match Write and Edit instead.