Codex sessions
Claude Code loads a .claude/rules/*.md rule only once the session reads or edits a file the rule's paths: globs match. Codex has no equivalent, so .codex/hooks.json runs scripts/path-scoped-rules.ts after every shell command and apply_patch call. The script finds the repo files the call named, matches them against the same globs, and hands Codex the body of each newly matched rule as developer context. It gives each rule once per agent, again after a compaction, and drops that record when the session ends. The rules themselves stay the only copy.
Trust the hooks once, or they never run. Codex skips a project hook until you have reviewed that exact definition, and again after any change to it. codex exec skips it without a word. Open /hooks in a Codex session and trust the three hooks that run scripts/path-scoped-rules.ts.
Worktree sessions read the main checkout's hooks.json
Inside a git worktree, Codex loads .codex/hooks.json from the repository's main checkout, not from the worktree (openai/codex#27133). The hook command resolves the script from the session's own checkout, so a worktree always runs the script and rules it has checked out. Two things follow:
- The main checkout needs a commit that has
.codex/hooks.json. Before that, worktree sessions get no hooks at all. - Whatever
.codex/hooks.jsonthe main checkout holds is what every worktree session runs. The Codex app's "import from Claude" writes one there, so a local edit or a leftover import replaces the committed hooks everywhere, and an untracked leftover blocksgit pulluntil you move it aside. Personal Codex hooks belong in~/.codex/hooks.json, which Codex loads alongside the project's.