Support additionalContext in PreToolUse hooks or clarify Claude-style hook parity

Resolved 💬 3 comments Opened Apr 24, 2026 by jeffhuen Closed Aug 4, 2026
💡 Likely answer: A maintainer (etraut-openai, contributor) responded on this thread — see the highlighted reply below.

What variant of Codex are you using?

CLI

What version of Codex are you using?

codex-cli 0.124.0

What happened?

Codex hooks are now stable/default-enabled, and the code/release language describes them as "Claude-style lifecycle hooks" loaded from hooks.json / config layers. However, PreToolUse currently rejects hookSpecificOutput.additionalContext even though that is a common Claude-style context-injection pattern.

A minimal PreToolUse hook like this:

{
  "hooks": {
    "PreToolUse": [
      {
        "matcher": "Bash",
        "hooks": [
          {
            "type": "command",
            "command": "echo '{\"hookSpecificOutput\":{\"hookEventName\":\"PreToolUse\",\"additionalContext\":\"Before searching raw files, use the project knowledge graph.\"}}'"
          }
        ]
      }
    ]
  }
}

produces:

PreToolUse hook returned unsupported additionalContext

The official hooks docs also state that for PreToolUse, additionalContext is parsed but not supported yet.

Why this matters

This creates a sharp compatibility trap for tools that install Claude-style hooks and expect context injection before tool use. One concrete example is Graphify:

Graphify originally installed a PreToolUse hook that injected context reminding the agent to consult graphify-out/GRAPH_REPORT.md before raw file search. That pattern works in Claude-style hook environments, but Codex rejects it.

The current workaround is to emit top-level systemMessage from PreToolUse instead:

{"systemMessage":"graphify: Knowledge graph exists..."}

That avoids the hard error, but it is not equivalent:

  • It surfaces as repeated warning-style UI noise before every intercepted tool call.
  • It is not the same documented developer-context path as additionalContext.
  • It still leaves third-party hook installers needing Codex-specific branching.

SessionStart.additionalContext and UserPromptSubmit.additionalContext are valid alternatives for some tools, but they are not equivalent to PreToolUse:

  • SessionStart is cheap but too early and easy to stale/forget during long sessions.
  • UserPromptSubmit runs on every prompt even when no tool/search is about to happen.
  • PreToolUse is the natural low-token place to inject context specifically when a tool is about to run.

Expected behavior

Ideally, PreToolUse should support:

{
  "hookSpecificOutput": {
    "hookEventName": "PreToolUse",
    "additionalContext": "..."
  }
}

and add that text as extra developer context for the next model continuation, matching the behavior already available on SessionStart, UserPromptSubmit, and PostToolUse.

If supporting this on PreToolUse is intentionally out of scope because the model has already decided to call a tool, then the docs and release wording should clarify the distinction:

  • Codex supports Claude-style hook discovery/config shape.
  • Codex does not provide full Claude Code output-field parity for every hook event.
  • PreToolUse is currently a guardrail/blocking hook, not a context-injection hook.

Suggested acceptance criteria

One of:

  1. Add PreToolUse.hookSpecificOutput.additionalContext support and inject it as extra developer context after the intercepted tool event, or
  2. Update the hooks docs and relevant examples to explicitly warn that PreToolUse.additionalContext is unsupported despite Claude-style hook config compatibility, and recommend SessionStart, UserPromptSubmit, or PostToolUse depending on intent.

Related context

View original on GitHub ↗

3 Comments

oxysoft · 3 months ago

Indexed this hook ticket in the umbrella tracker: #21753

Goal: collect the scattered Codex hook requests and bugs into one parity matrix for Full Claude Code Hook Parity (29+), while preserving this issue as the detailed thread for its specific behavior.

Necmttn · 2 months ago

Small current-main check at aaf737fa: this looks implemented now, so the remaining closeout may just be identifying the fixing release/version.

Evidence I found:

  • PreToolUseOutcome now carries additional_contexts, and run() flattens parsed hook contexts into the returned outcome.
  • parse_completed() appends parsed additionalContext into model-visible context.
  • parse_pre_tool_use() reads hookSpecificOutput.additionalContext; the unsupported-field checks reject invalid updatedInput/permissionDecision shapes, not context-only output.
  • pre-tool-use.command.output.schema.json includes hookSpecificOutput.additionalContext.
  • pre_tool_use_records_additional_context_for_shell_command asserts the follow-up model request contains the PreToolUse context as developer text.
  • The blocked-command variant also preserves the context while preventing the command from running.
  • Current docs list PreToolUse additionalContext as supported: https://developers.openai.com/codex/hooks

Closeout suggestion: link the commit/release where this shipped, then close as fixed. If 0.124.0 still rejects the exact payload from the issue, keeping a regression with that JSON shape would cover the compatibility case directly.

---

_Generated with ax._

etraut-openai contributor · 24 days ago

PreToolUse.additionalContext is implemented across schema, parsing, context, tests, and docs.