Hooks generator

Generate a command hook for Codex or Claude Code. Choose a lifecycle event, add an optional matcher and copy the JSON configuration.

Hook configuration

Merge into .codex/hooks.json in your project.

{
  "hooks": {
    "Stop": [
      {
        "hooks": [
          {
            "type": "command",
            "command": "/usr/bin/printf \"%s\\n\" \"Agent hook ran\" >&2",
            "timeout": 30
          }
        ]
      }
    ]
  }
}

Choose the right event for your agent hook

Use SessionStart for setup, PostToolUse for an action after a matching tool, or Stop when an assistant turn finishes. A matcher filters the hook by the event’s documented value, which may be a tool name or a session source.

Copy the generated hook into the relevant configuration and keep your existing hooks. Test it with a command you trust and review the event and timeout in your client before enabling it.

Keep hook commands fast and deterministic—formatting a modified file or triggering a desktop notification works well, while slow network checks can stall every turn.

Common questions

When should I add a matcher to a hook?

Add a matcher when you only want the hook to fire for a specific tool or event source—for example, running a linter only after file-editing tools on PostToolUse rather than after read-only lookups.

Where do Codex and Claude Code hook configurations live?

Claude Code stores hooks in your user or project settings.json file, while Codex reads hooks from its hooks.json configuration file.