Agent hooks are user-defined commands that a coding agent like Claude Code or Codex runs automatically at fixed points in its lifecycle, such as before a tool call, when it needs permission, or when it stops. They give deterministic control (always format, always notify, block a command) instead of relying on the model to remember. Claude Code reads hooks from settings.json; Codex reads them from hooks.json.
Agent hooks are user-defined commands that a coding agent runs automatically at specific events in its lifecycle, such as before a tool runs, after it succeeds, when a permission decision is needed, or when the agent finishes responding. Because the agent always runs them, hooks give you deterministic behavior: a formatter that always runs after an edit, a notification that always fires, a check that always blocks a dangerous command.
Claude Code's docs describe hooks as "user-defined shell commands" that run "at specific points in Claude Code's lifecycle." Codex has the same concept with a very similar set of event names.
Which events can hooks use?
Common events in both Claude Code and Codex:
Claude Code also has a Notification event (with matchers such as permission_prompt and idle_prompt) and many others; the hooks reference lists them all.
Example
This Claude Code hook runs Prettier on every file Claude edits or writes. It goes in ~/.claude/settings.json (all projects) or .claude/settings.json (one project):
{
"hooks": {
"PostToolUse": [
{
"matcher": "Edit|Write",
"hooks": [
{ "type": "command", "command": "f=$(jq -r '.tool_input.file_path') && npx prettier --write --ignore-unknown \"$f\"" }
]
}
]
}
}The hook receives JSON about the event on stdin, here the edited file path, and can return JSON to influence what happens next. Type /hooks in Claude Code to see configured hooks.
How are Codex hooks different?
Codex reads hooks from ~/.codex/hooks.json (or $CODEX_HOME/hooks.json), from .codex/hooks.json in a trusted project, or inline under [hooks] in config.toml. The main difference is trust: Codex skips new or changed non-managed hooks until you review and trust them in /hooks, and ties that trust to the hook's current hash. See the Codex hooks guide.
Why hooks matter
Hooks are how other tools plug into coding agents without changing them. Notification scripts, policy checks and menu bar apps all use them. Allowbar, for example, adds its own entries to ~/.claude/settings.json and ~/.codex/hooks.json to receive permission requests on the Mac, leaves other hooks untouched, and goes through Codex's trust step like any other hook.
Related
Sources
Frequently asked questions
Where do I put Claude Code hooks?
In a settings file: ~/.claude/settings.json for all projects, .claude/settings.json for one project (can be committed), or .claude/settings.local.json for one project without committing. Plugins, skills and subagents can also define hooks.
Why is my Codex hook not running?
Codex skips new or changed non-managed hooks until you trust them. Run /hooks in the Codex CLI to review and trust the hook.
Can a hook block a command?
Yes. A PreToolUse hook can block a tool call before it runs in Claude Code, and a PermissionRequest hook can return an allow or deny decision.