フィールドガイド / 17 分
Hooks と Rules で guardrails を置く
Trusted command で lifecycle、testable prefix rules で escalation を制御。
Hooks は PreToolUse、PostToolUse、Stop、SessionStart 等で trusted command handlers を実行します。Rules は sandbox 外の command prefix を allow/prompt/forbidden にします。Hooks は stable、rules は experimental、最も restrictive な match が優先です。
CLI
検証済みターミナル手順
- ›
/hooks - $
codex execpolicy check --pretty --rules ~/.codex/rules/default.rules -- gh pr view 7888
A
作業原則
Exact code を trust
Hook trust は hash。変更後は再 review。
argv prefix match
Narrow prefix と match/not_match examples。
Guardrail only
Matching hooks は並行、today は command handler のみ。
B
フィールド手順
- 01
Surface 選択
Guidance=AGENTS、lifecycle=hooks、escalation=rules、authority=CI。
- 02
One hook
Read-only validation と narrow matcher。
- 03
/hooks review
Source/command/trust。
- 04
Prefix rule
Examples と safest decision。
- 05
execpolicy test
Experimental rule を使う前に check。
PASS / FAIL
受入チェック
- Hook source/hash reviewed。
- Matcher narrow。
- Rule examples pass。
- CI enforcement remains。
WATCH / REJECT
失敗パターン
- Normal work で trust bypass。
- Prompt/agent handler supported と誤記。
- Rules only security。