Definition
Agent hooks are commands that an AI coding agent such as Claude Code or Codex runs automatically at set points in its lifecycle, for example when a session starts, before or after a tool call, on a permission request, or when a turn stops.
Also called: hooks, Claude Code hooks, Codex hooks, lifecycle hooks.
Each hook is tied to an event, can be limited to certain tools with a matcher, and receives the event's details as JSON. Most hooks are shell commands, though Claude Code also supports HTTP, prompt and MCP tool hooks. Hooks are used to log activity, block risky commands, run checks when a turn ends, or tell another app what the agent is doing. Because a hook runs with your account's access, only add hooks you trust.
| Claude Code | Codex | |
|---|---|---|
| Where they're set | "hooks" in ~/.claude/settings.json or a project's .claude/settings.json | ~/.codex/config.toml ([[hooks.<Event>]]) or ~/.codex/hooks.json, and the same in a project's .codex/ |
| Example events | SessionStart, UserPromptSubmit, PreToolUse, PostToolUse, PermissionRequest, Notification, Stop, SubagentStop, SessionEnd | SessionStart, UserPromptSubmit, PreToolUse, PermissionRequest, PostToolUse, Stop, Interrupt, SessionEnd |
| Before a hook runs | it runs once it's in settings (not in folders Claude doesn't trust yet, or with "disableAllHooks": true) | you review and trust it with /hooks; Codex records trust against the hook's hash, so a changed hook needs trusting again |
Both tools read their hooks when a session starts, so a new or changed hook takes effect in the next chat.
In Pairbar
Pairbar's live status installs hooks for Claude and Codex (Settings → Integrations, off until you install them). They run a small helper that passes only metadata (the chat's id, folder, event and a short tool summary such as "Bash · git push") over a private socket on your Mac, so a chat waiting for approval shows Needs you at once. Install backs up the file and adds only Pairbar's entries; Uninstall removes exactly them. See set up live status hooks.
Frequently asked questions
- Are Claude Code hooks and Codex hooks the same?
- They're the same idea with similar event names, but configured separately: Claude Code in
settings.json, Codex inconfig.tomlorhooks.json, and Codex runs a non-managed hook only after you trust it. - Can a hook slow the agent down?
- Yes, a synchronous hook makes the agent wait for it. Claude Code can run a hook with
"async": trueso it carries on without waiting. - Why isn't my hook running?
- Start a new session first. In Claude Code check the folder is trusted and
disableAllHooksisn't set; in Codex trust the hook with/hooksand checkhooks = falseisn't set under[features].
Related
- GuideSet up live status hooks for Claude and CodexTurn on instant status from Claude Code and Codex hooks: what Install writes, what is sent, how to check events arrive, repair and uninstall.
- Use caseKnow the moment Claude Code or Codex stops to ask for your approvalOptional hooks for Claude and Codex show Needs you the instant a chat asks for approval, the tool a chat is running, and when it finishes.
- DocsIntegrationsLive status for Claude and Codex through their hooks, Pairbar's tools for their chats (the plugin, the `pairbar` command, the tool reference, who's calling, agent activity), and agent actions: second opinions, reviews, helper chats, handoffs, workflow runs and drafts, and check-ins that agents ask for and you approve, with budgets and guardrails
- GlossaryPermission modeThe Claude Code setting that decides which actions Claude may take in a session without asking you first.