Install
$ agentstack add skill-narumiruna-skills-codex-cli-hooks ✓ scanned · ✓ verified — works with Claude Code, Cursor, and more.
Security review
✓ PassedNo 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.
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
- Confirm hooks are actually available.
Check config.toml for: ``toml [features] codex_hooks = true `` Remember hooks are currently disabled on Windows.
- 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.
- 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.
- 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.
- 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.
- 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
matcheronly where runtime honors it. - For
PreToolUseandPostToolUse, currenttool_nameis onlyBash. - For
SessionStart, matcher applies tostartuporresume. - For
UserPromptSubmitandStop, matcher is currently ignored. - Use
"*","", or omitmatcherto match everything supported by that event.
Implementation Rules
- Keep
hooks.jsonsmall 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
Stoprequires JSON. - Use
uvx codhcfor simpleStop-hook validation commands such asruff,pytest, or project-specific check scripts. - Write a custom hook script instead of
codhcwhen the hook must read payload fields, compute custom continuation reasons, or produce non-Stopevent shapes. - Pass
codhccommands as argv, not a single shell string. Useuvx codhc ruff check --fix, notuvx codhc "ruff check --fix". - Prefer
systemMessageor hook-specific structured output over ad hoc print debugging. - Treat unsupported fields as fail-open. Parsed does not mean enforced.
Known Runtime Limits
PreToolUseandPostToolUsecurrently 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.
PostToolUsecannot undo side effects from a command that already ran.PreToolUseis useful for policy guardrails, not a hard security boundary.codhcis a thin command wrapper, not a general hook framework or policy engine.codhcis most useful forStophooks 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: minimalhooks.jsonand 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.
- Author: narumiruna
- Source: narumiruna/skills
- License: MIT
Install and usage instructions live in the source repository linked above.
Reviews
No reviews yet — be the first.
Write a review
Versions
- v0.1.0 Imported from the upstream source.