Skip to content
Skills Library
AI & agents · Building & coding

Codex CLI Hooks

/Codex CLI Hooks

This skill should be used when the user asks to "create a Codex hook", "configure Codex CLI hooks", "add a PreToolUse hook for Codex", "block commands in Codex", "create a stop hook", "set up SessionStart hooks", "write Codex hooks.json", or mentions Codex CLI hook events (SessionStart, PreToolUse, PostToolUse, UserPromptSubmit, Stop). Covers the Codex CLI hooks extensibility framework, configuration, event types, input/output wire format, and common patterns.

Repository
plexium ↗
Licence
Apache-2.0
Last repository change
30.09.2026

Assessment and security

90/ 100Class: good
Format15 / 25
Frontmatter with name and description, valid name, description up to 1,024 characters, name matching the folder.
Discoverability25 / 25
Description explains when to use the skill, has a reasonable length and uses third person.
Content35 / 35
At least 150 words and at most 500 lines, headings, step lists, examples or code.
Hygiene15 / 15
No placeholders such as TODO, no Windows paths, with a licence.
Riskno signals detected in the scan
Files in this package
10
Scripts
5
HTML comments
0
URLs in SKILL.md
1
Deprecation

No signals detected. Repository changed on 30.09.2026, without references to retired models or APIs.

Licence

Apache-2.0, otwarta: można używać i zmieniać, z zachowaniem licencji i informacji o zmianach.

What to check before installing
  • 5 scripts in this package. Review them before installing, as Claude may execute them.

Scripts: examples/pre_tool_use_policy.py, examples/session_start.py, examples/stop_continue.py, scripts/test-hook.sh, scripts/validate-hooks.sh

What it does and when to use it

This skill should be used when the user asks to "create a Codex hook", "configure Codex CLI hooks", "add a PreToolUse hook for Codex", "block commands in Codex", "create a stop hook", "set up SessionStart hooks", "write Codex hooks.json", or mentions Codex CLI hook events (SessionStart, PreToolUse, PostToolUse, UserPromptSubmit, Stop). Covers the Codex CLI hooks extensibility framework, configuration, event types, input/output wire format, and common patterns.

Triggers from the description

create a Codex hookconfigure Codex CLI hooksadd a PreToolUse hook for Codexblock commands in Codexcreate a stop hookset up SessionStart hookswrite Codex hooks.json
Original author description

This skill should be used when the user asks to "create a Codex hook", "configure Codex CLI hooks", "add a PreToolUse hook for Codex", "block commands in Codex", "create a stop hook", "set up SessionStart hooks", "write Codex hooks.json", or mentions Codex CLI hook events (SessionStart, PreToolUse, PostToolUse, UserPromptSubmit, Stop). Covers the Codex CLI hooks extensibility framework, configuration, event types, input/output wire format, and common patterns.

How it works

  1. Prerequisites
  2. Hook Discovery
  3. Config Structure
  4. Supported Events
  5. Common I/O Fields
  6. Quick Reference by Event
  7. Important Limitations
  8. Additional Resources
Original SKILL.md headings · 151 lines, 670 words
SKILL.md preview
---
name: Codex CLI Hooks
description: This skill should be used when the user asks to "create a Codex hook", "configure Codex CLI hooks", "add a PreToolUse hook for Codex", "block commands in Codex", "create a stop hook", "set up SessionStart hooks", "write Codex hooks.json", or mentions Codex CLI hook events (SessionStart, PreToolUse, PostToolUse, UserPromptSubmit, Stop). Covers the Codex CLI hooks extensibility framework, configuration, event types, input/output wire format, and common patterns.
---

# Codex CLI Hooks

Hooks are an extensibility framework for OpenAI's Codex CLI that inject custom scripts into the agentic loop. They enable command interception, prompt filtering, session customization, and turn continuation.

## Prerequisites

Hooks require enabling the feature flag in `config.toml`:

```toml
[features]
codex_hooks = true
```

Hooks are currently disabled on Windows.

## Hook Discovery

Codex discovers `hooks.json` next to active config layers. The two primary locations:

- `~/.codex/hooks.json` (global)
- `<repo>/.codex/hooks.json` (repo-local)

Multiple `hooks.json` files are merged — higher-precedence layers do not replace lower-precedence hooks.

## Config Structure

Hooks are organized in three levels: event type, matcher group, and handlers.

```json
{
  "hooks": {
    "<EventName>": [
      {
        "matcher": "<regex>",
        "hooks": [
          {
            "type": "command",
            "command": "<shell command>",
            "timeout": 600,
            "statusMessage": "optional UI message"
          }
        ]
      }
    ]
  }
}
```

Key notes:
- `timeout` defaults to 600 seconds. `timeoutSec` is an accepted alias.
- `statusMessage` is optional.
- Commands run with session `cwd` as working directory.
- For repo-local hooks, resolve paths from git root: `"$(git rev-parse --show-toplevel)/.codex/hooks/..."`

## Supported Events

| Event | Matcher Filters | Purpose |
|-------|----------------|---------|
| `SessionStart` | `startup` or `resume` | Load context at session start |
| `PreToolUse` | tool name (currently `Bash` only) | Intercept/block commands before execution |
| `PostToolUse` | tool name (currently `Bash` only) | Review command output after execution |
| `UserPromptSubmit` | not supported | Inspect/modify user prompts |
| `Stop` | not supported | Continue or inspect turns at stop |

Matcher is a regex string. Use `"*"`, `""`, or omit to match all. Multiple matching hooks run concurrently.

## Common I/O Fields

All hooks receive JSON on stdin with these shared fields:

| Field | Type | Meaning |
|-------|------|---------|
| `session_id` | `string` | Session/thread ID |
| `transcript_path` | `string \| null` | Path to transcript file |
| `cwd` | `string` | Working directory |
| `hook_event_name` | `string` | Event name |
| `model` | `string` | Active model slug |

Common JSON output fields (events vary):

```json
{
  "continue": true,
  "stopReason": "optional",
  "systemMessage": "optional warning text",
  "suppressOutput": false
}
```

Exit `0` with no output = success, Codex continues.

## Quick Reference by Event

### SessionStart
- **Input extra**: `source` (`startup` or `resume`)
- **Plain text stdout**: added as developer context
- **JSON stdout**: `additionalContext` in `hookSpecificOutput`

### PreToolUse
- **Input extra**: `turn_id`, `tool_name`, `tool_use_id`, `tool_input.command`
- **Block command**: return `{"hookSpecificOutput": {"hookEventName": "PreToolUse", "permissionDecision": "deny", "permissionDecisionReason": "..."}}` or `{"decision": "block", "reason": "..."}`
- **Also**: exit code `2` + reason on stderr

### PostToolUse
- **Input extra**: `turn_id`, `tool_name`, `tool_use_id`, `tool_input.command`, `tool_response`
- **Block**: `{"decision": "block", "reason": "..."}` replaces tool result with feedback (does NOT undo the command)
- **Stop processing**: return `continue: false`

### UserPromptSubmit
- **Input extra**: `turn_id`, `prompt`
- **Plain text stdout**: added as developer context
- **Block prompt**: `{"decision": "block", "reason": "..."}`

### Stop
- **Input extra**: `turn_id`, `stop_hook_active`, `last_assistant_message`
- **JSON stdout required** (plain text is invalid)
- **Continue turn**: `{"decision": "block", "reason": "..."}` — creates continuation prompt from `reason`
- `continue: false` takes precedence over other Stop hooks' continuation decisions

## Important Limitations

- `PreToolUse` and `PostToolUse` currently only intercept `Bash` tool calls. The model can bypass by writing scripts to disk.
- `PostToolUse` cannot undo side effects from commands that already ran.
- Several fields (`permissionDecision: "allow"/"ask"`, `updatedInput`, `suppressOutput`) are parsed but not supported — they fail open.
- `Stop` requires JSON output; plain text is invalid.

## Additional Resources

### Reference Files

- **`references/hook-events.md`** — Complete input/output schemas for each event
- **`references/wire-format.md`** — Full wire format details and edge cases
- **`references/patterns.md`** — Common hook patterns (security, logging, auto-continue)

### Examples

- **`examples/hooks.json`** — Complete configuration with all event types
- **`examples/session_start.py`** — SessionStart hook loading workspace notes
- **`examples/pre_tool_use_policy.py`** — PreToolUse blocking destructive commands
- **`examples/stop_continue.py`** — Stop hook for auto-continuation

### Scripts

- **`scripts/validate-hooks.sh`** — Validate hooks.json structure
- **`scripts/test-hook.sh`** — Test a hook script with sample input

### External Reference

Full generated schemas: [Codex GitHub repository](https://github.com/openai/codex/tree/main/codex-rs/hooks/schema/generated)
Files in this package (10)
  • SKILL.md 6 KB
  • examples/hooks.json 1 KB
  • examples/pre_tool_use_policy.py 1 KB
  • examples/session_start.py 1 KB
  • examples/stop_continue.py 1 KB
  • references/hook-events.md 6 KB
  • references/patterns.md 5 KB
  • references/wire-format.md 4 KB
  • scripts/test-hook.sh 2 KB
  • scripts/validate-hooks.sh 2 KB

Versions

The database has no other skills named Codex CLI Hooks.

Database snapshot: 13.11.2026 · package version 816d12864bd0 (SHA-256 digest of the entire package)

Downloads in the last 30 days: 0 · ranking

Report a problem with this skill: harmful content, incorrect descriptions or an author’s removal request.

Similar skills

  • 95hook-development
    This skill should be used when the user asks to "create a hook", "add a PreToolUse/PostToolUse/Stop hook", "validate tool use", "implement prompt-based hooks", "use ${CLAUDE_PLUGIN_ROOT}", "set up event-driven automation", "block dangerous commands", or mentions hook events…
  • 100create-hooks
    Expert guidance for creating, configuring, and using Claude Code hooks. Use when working with hooks, setting up event listeners, validating commands, automating workflows, adding notifications, or understanding hook types (PreToolUse, PostToolUse, Stop, SessionStart, UserPromptSubmit, etc).
  • 95hook-development
    This skill should be used when the user asks to "create a hook", "add a PreToolUse/PostToolUse/Stop hook", "validate tool use", "implement prompt-based hooks", "use ${CLAUDE_PLUGIN_ROOT}", "set up event-driven automation", "block dangerous commands", or mentions hook events…
  • 95hook-development
    This skill should be used when the user asks to "create a hook", "add a PreToolUse/PostToolUse/Stop hook", "validate tool use", "implement prompt-based hooks", "use ${CLAUDE_PLUGIN_ROOT}", "set up event-driven automation", "block dangerous commands", or mentions hook events…
  • 98hook-development
    Write Navin lifecycle hooks (hooks.json, PreToolUse, PostToolUse, UserPromptSubmit, SessionStart, Stop, SubagentStop) as shell commands that read the event JSON on stdin and block, warn or add context through exit codes and JSON output. Use when the user asks to "create a hook",…
  • 100hook-development
    Use when creating, modifying, or debugging Claude Code hooks — PreToolUse, PostToolUse, Stop, SubagentStop, SessionStart, SessionEnd, UserPromptSubmit, PreCompact, Notification. Covers the plugin `hooks/hooks.json` wrapper format vs. the user `settings.json` direct format,…

Feedback and reports

Your message goes to Bartosz Sokoliński. An email address is needed only for a reply. See the privacy policy.