CodeGraph supplies separate hook adapters for Codex and Claude Code. Both can enrich a session and inspect tool activity, but their registration files and supported events are different. Treat the checked-in registration file as the contract; do not infer support from a similarly named Python module.
Choose the correct adapter
| Client | Authoritative registration | Runtime implementation | When to use it |
|---|---|---|---|
| Codex | plugins/codegraph/hooks/hooks.json |
plugins/codegraph/hooks/runtime/ through plugins/codegraph/bin/codegraph_codex_hook.py |
The CodeGraph Codex plugin is installed and the client loads its native plugin hooks. |
| Claude Code | .claude/settings.json |
.claude/hooks/ |
The repository is opened in Claude Code and repository-local hooks are allowed. |
The adapters are not interchangeable. A .claude/hooks/ file does not register a Codex event, and a Codex plugin cache must not be edited as if it were repository source.
Codex lifecycle
The current Codex registration declares these events:
| Event | Purpose | Typical boundary |
|---|---|---|
SessionStart |
Resolve project and session context before normal work. | Bounded diagnostic or context enrichment. |
UserPromptSubmit |
Add current CodeGraph context to the submitted task. | Context may degrade with an explicit diagnostic. |
PreToolUse |
Evaluate tool-use and governed financial policies before execution. | Policy and authorization decisions are fail-closed. |
PostToolUse |
Capture Bash outcomes and bounded telemetry after execution. | Reporting is normally fail-open; it cannot retroactively authorize a command. |
SubagentStart / SubagentStop |
Bind and finalize delegated execution context. | Evidence collection follows the active carrier. |
PreCompact |
Capture bounded memory before context compaction. | The configured compact barrier decides whether a failure blocks. |
Stop |
Emit diagnostics, memory, and completion-guard evidence. | Stop itself is intentionally non-blocking; authoritative SDLC gates decide closure. |
The registration also defines per-event timeouts. A timeout records an operational limit; the associated product task is evaluated by the review and acceptance evidence.
Claude Code lifecycle
The repository-local .claude/settings.json registers SessionStart, UserPromptSubmit, PreToolUse, PostToolUse, and Stop handlers from .claude/hooks/.
The shared review-pipeline policy defaults to fail-closed for a hook error that could hide a required check. An operator may enable review_pipeline.fail_open only as an explicit configuration decision. That exception keeps work recoverable and remains visible in diagnostics; missing review evidence stays in its own status.
Failure model
- Use fail-closed for authorization, destructive tool-use policy, required approval, and completion/financial gates.
- Use fail-open only for bounded enrichment or telemetry where losing the optional context is safer than blocking the whole client.
- Never interpret hook exit success as acceptance evidence for a Story, task, or release.
- Never place secrets, raw provider tokens, or unrestricted source payloads in hook diagnostics.
- Keep timeouts bounded and return an actionable recovery message naming the failed stage.
Verify Codex hooks
- Open
plugins/codegraph/hooks/hooks.jsonand confirm that the event you need is registered. - Confirm that the command points to
${PLUGIN_ROOT}/bin/codegraph_codex_hook.py(or its Windows form) and that the runtime file exists. - Start a fresh client session after installing or updating the plugin. A source checkout change alone does not update an already installed plugin cache.
- Trigger the smallest relevant event and inspect its structured diagnostic. Use the hook check to verify wiring and the product acceptance test to verify the product task.
- If a governed operation is denied, fix the named scope, permission, approval, or carrier issue instead of bypassing
PreToolUse.
Verify Claude Code hooks
- Confirm that
.claude/settings.jsonregisters the event and points to an existing file under.claude/hooks/. - Run the hook with a minimal JSON fixture through standard input.
- Check that invalid or missing project context produces an actionable diagnostic.
- Review
review_pipeline.fail_openbefore diagnosing different behavior across workstations.
Troubleshooting
| Symptom | Check | Recovery |
|---|---|---|
| Event never runs | Registration file, installed plugin version, client restart | Reinstall/update the adapter and start a new session. |
| Wrong project is selected | Project detector and session cache | Clear only the adapter’s documented cache and retry discovery. |
PreToolUse denies a command |
Permission, approval, carrier, and destructive-command policy | Correct the governing input; do not convert the denial to fail-open. |
| Enrichment times out | MCP/runtime health and event timeout | Continue with the emitted degraded-state diagnostic or restore the service. |
| Hook ran but review is missing | Review command and acceptance evidence | Run the canonical review workflow and record its result. |
Source references
plugins/codegraph/hooks/hooks.jsonplugins/codegraph/hooks/runtime/plugins/codegraph/bin/codegraph_codex_hook.py.claude/settings.json.claude/hooks/
For the review workflow itself, see Code Review and Scenario 09.