Skip to content

Tighten hookSpecificOutput.hookEventName schemas to the matching hook event #23993

@sushichan044

Description

@sushichan044

What issue are you seeing?

The generated hook command output JSON schemas currently allow hookSpecificOutput.hookEventName to be any value from the global hook event enum for several hook-specific output payloads.

For example, the pre-tool-use.command.output schema accepts any HookEventNameWire value for hookSpecificOutput.hookEventName, even though that hook-specific output is only valid for PreToolUse.

Affected output schemas:

  • permission-request.command.output.schema.json
  • post-tool-use.command.output.schema.json
  • pre-tool-use.command.output.schema.json
  • session-start.command.output.schema.json
  • user-prompt-submit.command.output.schema.json

This makes the published schemas less precise than the runtime contract and can mislead external hook authors or schema-driven tooling into producing invalid combinations such as a PreToolUse hook-specific output with hookEventName: "PostToolUse".

What steps can reproduce the bug?

  1. Inspect a generated hook command output schema such as codex-rs/hooks/schema/generated/pre-tool-use.command.output.schema.json.
  2. Find properties.hookSpecificOutput.properties.hookEventName.
  3. Observe that it references the global hook event enum instead of constraining the value to the matching hook event.

Current shape:

{
  "hookEventName": {
    "$ref": "#/definitions/HookEventNameWire"
  }
}

This permits unrelated hook event names inside an event-specific output payload.

What is the expected behavior?

Each hook-specific output schema should constrain hookSpecificOutput.hookEventName to the literal hook event name for that output type.

Expected shape:

{
  "hookEventName": {
    "const": "PreToolUse",
    "type": "string"
  }
}

The expected constants by schema are:

  • permission-request.command.output.schema.json: PermissionRequest
  • post-tool-use.command.output.schema.json: PostToolUse
  • pre-tool-use.command.output.schema.json: PreToolUse
  • session-start.command.output.schema.json: SessionStart
  • user-prompt-submit.command.output.schema.json: UserPromptSubmit

This should match the existing pattern used by hook command input schemas, where hookEventName is already represented as an event-specific string constant.

Additional information

I already have a potential patch that fixes this issue in my computer.

Metadata

Metadata

Assignees

No one assigned

    Labels

    CLIIssues related to the Codex CLIbugSomething isn't workinghooksIssues related to event hooks

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions