AgentStack
SKILL verified MIT Self-run

Codex Cli Hooks

skill-narumiruna-skills-codex-cli-hooks · by narumiruna

Use when designing, implementing, reviewing, or debugging Codex CLI hooks, including `hooks.json`, `.codex/hooks.json`, feature-flag setup, matcher behavior, event-specific stdin/stdout payloads, and hook scripts for `SessionStart`, `PreToolUse`, `PostToolUse`, `UserPromptSubmit`, or `Stop`.

No reviews yet
0 installs
5 views
0.0% view→install

Install

$ agentstack add skill-narumiruna-skills-codex-cli-hooks

✓ scanned · ✓ verified — works with Claude Code, Cursor, and more.

Security review

✓ Passed

No issues found. Passed automated security review. · v0.1.0 How review works →

  • Prompt-injection patterns
  • Secret / credential exfiltration
  • Dangerous shell & filesystem operations
  • Untrusted network calls
  • Known-malicious package signatures

What it can access

  • Network access No
  • Filesystem access No
  • Shell / process execution No
  • Environment & secrets No
  • Dynamic code execution No

From automated source analysis of v0.1.0. “Used” means the capability is present in the source — more access means more to trust, not that it’s unsafe.

Are you the author of Codex Cli Hooks? Claim this listing to set pricing, connect Stripe payouts, and keep 70% of every sale.
Sign up to claim

About

Codex CLI Hooks

Overview

Design Codex hooks from the current workspace outward: enable the feature flag, choose the right config layer, then implement the smallest hook that proves the event contract before adding policy logic.

Treat hooks as workflow guardrails, not absolute enforcement. Current runtime support is intentionally partial, especially for shell interception.

Workflow

  1. Confirm hooks are actually available.

Check config.toml for: ``toml [features] codex_hooks = true `` Remember hooks are currently disabled on Windows.

  1. Choose the config layer.

Prefer ~/.codex/hooks.json for personal defaults and /.codex/hooks.json for repo-specific behavior. Matching hooks from multiple files all run; higher-precedence config does not replace lower-precedence hooks.

  1. Choose the event before writing code.

Use SessionStart for startup or resume context, PreToolUse for pre-Bash checks, PostToolUse for post-Bash review, UserPromptSubmit for prompt gating or augmentation, and Stop for continue-or-stop logic at the end of a turn.

  1. Start with a minimal handler.

First make the hook emit a tiny valid response for the chosen event. Only after that should you add regex matchers, policy checks, file I/O, or transcript parsing.

  1. Resolve repo-local commands from the git root.

Prefer commands like: ``bash /usr/bin/python3 "$(git rev-parse --show-toplevel)/.codex/hooks/pre_tool_use.py" `` Do not assume Codex started from the repo root.

  1. Choose between a custom script and codhc.

Write a custom hook script when the hook must inspect payload fields, branch on runtime state, or emit event-specific JSON. Prefer uvx codhc when the hook only needs to run an existing CLI check and map its exit status into a Codex-compatible response, especially for Stop.

Event Selection

  • SessionStart: inject startup or resume context.
  • PreToolUse: inspect an upcoming Bash command and optionally deny it.
  • PostToolUse: review Bash output after the command already ran.
  • UserPromptSubmit: inspect or block the prompt before it is sent.
  • Stop: stop the turn or force one more continuation pass.

Read references/events.md before implementing event-specific stdout formats or blocker behavior.

Matcher Rules

  • Use matcher only where runtime honors it.
  • For PreToolUse and PostToolUse, current tool_name is only Bash.
  • For SessionStart, matcher applies to startup or resume.
  • For UserPromptSubmit and Stop, matcher is currently ignored.
  • Use "*", "", or omit matcher to match everything supported by that event.

Implementation Rules

  • Keep hooks.json small and explicit. Favor one matcher group per intent.
  • Expect concurrent execution when multiple command hooks match the same event.
  • Assume every hook receives one JSON object on stdin.
  • Validate stdout shape per event. Some events accept plain text, some ignore it, and Stop requires JSON.
  • Use uvx codhc for simple Stop-hook validation commands such as ruff, pytest, or project-specific check scripts.
  • Write a custom hook script instead of codhc when the hook must read payload fields, compute custom continuation reasons, or produce non-Stop event shapes.
  • Pass codhc commands as argv, not a single shell string. Use uvx codhc ruff check --fix, not uvx codhc "ruff check --fix".
  • Prefer systemMessage or hook-specific structured output over ad hoc print debugging.
  • Treat unsupported fields as fail-open. Parsed does not mean enforced.

Known Runtime Limits

  • PreToolUse and PostToolUse currently only support Bash payloads.
  • Shell interception is incomplete for richer execution paths.
  • Hooks do not currently intercept MCP, Write, WebSearch, or other non-shell tools.
  • PostToolUse cannot undo side effects from a command that already ran.
  • PreToolUse is useful for policy guardrails, not a hard security boundary.
  • codhc is a thin command wrapper, not a general hook framework or policy engine.
  • codhc is most useful for Stop hooks that wrap an existing command; do not treat it as the default solution for every hook event.

Debugging Checklist

  • Verify the feature flag is enabled.
  • Verify the hook file is in an active config layer.
  • Verify the event supports the matcher you wrote.
  • Verify the matcher can match current runtime values.
  • Verify the command path is stable from the session cwd.
  • Verify stdout matches the event contract exactly.
  • Verify you are not depending on unsupported fields such as fail-open updates.
  • Verify behavior still makes sense when multiple matching hooks run together.

References

  • references/events.md: event matrix, supported fields, and fail-open notes.
  • references/examples.md: minimal hooks.json and hook script output examples.

Source & license

This open-source skill is cataloged on AgentStack and links to its original source — we do not rehost the code.

Install and usage instructions live in the source repository linked above.

Reviews

No reviews yet — be the first.

Versions

  • v0.1.0 Imported from the upstream source.