Scut

Contributing

Codex Hook Implementation

Codex · hooks

Codex command-hook payloads, parity boundaries, and formatter behavior.

Codex command hooks run as subprocesses. Scut models payloads in hooks/codex and wires handlers under scut codex hook.

Codex hooks are trust-gated. Project-local hooks only run after the project .codex/ layer is trusted. The doctor command reports that as an informational reminder rather than trying to mutate trust state.

Payload design

Common input fields include:

  • session_id
  • turn_id
  • cwd
  • hook_event_name
  • model
  • permission_mode

Tool payloads use json.RawMessage because Bash, apply_patch, file-edit tools, and MCP tools all use different JSON shapes.

Event inventory

CommandEventMatcher inputCurrent behavior
session-startSessionStartsourceReturns placeholder additional context.
subagent-startSubagentStartagent_typeReturns placeholder subagent context.
pre-tool-usePreToolUsetool_name and aliasesDecodes payload and returns empty output.
permission-requestPermissionRequesttool_name and aliasesDecodes payload and returns empty output.
post-tool-usePostToolUsetool_name and aliasesFormats changed Go/Markdown/MDX files.
pre-compactPreCompacttriggerDecodes payload and returns empty output.
post-compactPostCompacttriggerDecodes payload and returns empty output.
user-prompt-submitUserPromptSubmitunusedReturns placeholder prompt context.
subagent-stopSubagentStopagent_typeDecodes payload and returns empty output.
stopStopunusedDecodes payload and returns empty output.

All leaf command structs embed hidden trailing positional args for forward compatibility with future Codex invocation arguments.

Formatter extraction

The Codex PostToolUse formatter extracts file paths from direct file_path fields, patch text in command, patch, or input, and apply_patch hunks. It supports add, update, delete, and move hunk headers.

The formatter only runs when it can identify changed files. Invalid or unrelated tool input is ignored rather than blocking the agent.

Relative patch paths are resolved against cwd. Added, updated, and moved files are candidates for formatting; deleted files are skipped.

Parity boundaries

Codex and Claude Code hook ecosystems are not identical. Scut only exposes Codex events that are currently documented for Codex command hooks. Claude-only events such as PostToolUseFailure, worktree hooks, task hooks, and MCP elicitation hooks remain under scut claude.

scut intentionally writes Codex hook configuration to hooks.json, not inline [hooks] TOML tables. This keeps the config writer JSON-only, narrows ownership, and avoids producing mixed hook representations in one Codex layer.