GPT WORLD / INDEPENDENT CODEX FIELD MANUAL Source review · 2026-07-26

Field guide / 17 min

Add guardrails with hooks and rules

Observe lifecycle events with trusted commands; control escalation with testable prefix rules.

Track
Codex CLI core
Level
Guardrails
Maturity
Mixed: hooks stable; rules experimental

Hooks run trusted command handlers at lifecycle events such as PreToolUse, PostToolUse, Stop, and SessionStart. Rules decide whether matching command prefixes are allowed, prompted, or forbidden outside the sandbox. Hooks are stable; rules remain experimental and the most restrictive matching decision wins.

CLI

Verified terminal sequence

TERMINAL / COPY WITH INTENT
  1. /hooks
  2. $codex execpolicy check --pretty --rules ~/.codex/rules/default.rules -- gh pr view 7888
A

Working principles

01

Trust exact hook code

Non-managed hooks are trusted by definition hash; changed hooks must be reviewed again.

02

Rules match argv prefixes

Write narrow prefixes with positive and negative examples; do not rely on vague shell-string matching.

03

Guardrail, not fortress

Hooks run concurrently when multiple definitions match and only command handlers execute today.

B

Field procedure

  1. 01

    Choose the enforcement surface

    Use AGENTS.md for guidance, hooks for lifecycle actions, rules for command escalation, and CI for authoritative checks.

  2. 02

    Create one hook

    Start with a read-only validation or logging command and a narrow matcher.

  3. 03

    Review it in /hooks

    Inspect source, exact command, and trust state before allowing execution.

  4. 04

    Write a prefix rule

    Include match and not_match examples and the safest decision that fits the command.

  5. 05

    Test with execpolicy

    Run codex execpolicy check before depending on the experimental rule in real work.

PASS / FAIL

Acceptance checklist

  • Hook source and hash are reviewed.
  • Matcher scope is narrow.
  • Rule examples pass.
  • CI still enforces critical invariants.

WATCH / REJECT

Failure patterns

  • Bypassing hook trust in normal interactive work.
  • Claiming prompt or agent hook handlers run today.
  • Using experimental rules as the only destructive-action defense.