Codex Rules & Hooks
Rules and hooks give teams stronger control over what Codex may do and how workflows are checked.
1. Rules
Rules are policy checks, often written with Starlark-style prefix rules, that allow, block, or require approval for command patterns.
What They Solve
Rules help prevent destructive commands, unsafe network usage, credential exposure, or unreviewed production changes.
Format: Starlark prefix_rule()
Rules usually match command prefixes and define what action should happen.
Compound Commands
Be careful with compound commands. A safe prefix can become unsafe if chained with another shell command.
Sources And Enterprise Enforcement
Rules may come from user config, project config, or managed enterprise policy. Managed rules should be treated as non-bypassable.
2. Hooks
Hooks run scripts at lifecycle events.
What They Solve
Hooks can enforce formatting, run checks, collect diagnostics, or integrate with internal systems.
Lifecycle Events
Events may include pre-command, post-command, session start, or task completion depending on the surface and configuration.
Configuration Format
Keep hook configuration explicit and version controlled when it affects team workflows.
Script Input And Output
Hooks should receive structured input and return structured output when possible.
Common Uses
- Block unsafe commands.
- Run linters before handoff.
- Attach audit metadata.
- Notify internal systems.
Trust Model
Hooks execute code. Treat them as trusted project or organization infrastructure.
Rules vs Hooks vs AGENTS.md
- Rules enforce command policy.
- Hooks run lifecycle automation.
- AGENTS.md communicates coding and workflow instructions.
Next Steps
Continue with Computer Use.