Skip to content

codex not support additionalContext on PreToolUse #533

Open

Description

@inkpark

PreToolUse hook (failed)
error: PreToolUse hook returned unsupported additionalContext

Activity

  1. wlb632363 commented on Apr 24, 2026

    @wlb632363

    same problem
    graphifyy:0.5.0
    codex-cli: 0.124.0

    Image
  2. bratnieks commented on Apr 25, 2026

    @bratnieks

    Temporary fix for Codex CLI unsupported additionalContext

    If Codex CLI shows:

    PreToolUse hook (failed)
    error: PreToolUse hook returned unsupported additionalContext
    
    Ask Codex to run this:
    
    Patch my local Graphify installation for the Codex CLI hook error.
    
    Replace all Graphify hook outputs using `additionalContext` with `systemMessage`.
    
    Run:
    
    which graphify || true
    python3 -c "import graphify; print(graphify.__file__)" 2>/dev/null || true
    .venv/bin/python -c "import graphify; print(graphify.__file__)" 2>/dev/null || true
    
    rg -n 'additionalContext|hookSpecificOutput|systemMessage' \
      ~/.local/lib/python*/site-packages/graphify/__main__.py \
      .venv/lib/python*/site-packages/graphify/__main__.py \
      2>/dev/null
    
    perl -0pi -e 's/additionalContext/systemMessage/g; s/"hookSpecificOutput":
    \{"hookEventName":"PreToolUse","systemMessage":/"systemMessage":/g; s/\}\}//g' \
      ~/.local/lib/python*/site-packages/graphify/__main__.py \
      .venv/lib/python*/site-packages/graphify/__main__.py
    
    graphify codex install || true
    .venv/bin/python -m graphify codex install || true
    
    rg -n 'additionalContext|hookSpecificOutput' \
      .codex/hooks.json \
      ~/.local/lib/python*/site-packages/graphify/__main__.py \
      .venv/lib/python*/site-packages/graphify/__main__.py \
      2>/dev/null
    
    pwd
    
    Expected final check:
    
    no matches for additionalContext or hookSpecificOutput
    
    Then restart Codex CLI.
    
  3. takeItIzzy commented on Apr 27, 2026

    @takeItIzzy

    I can reproduce this on macOS with the current Codex hook behavior.

    Environment:

    • graphifyy: 0.4.32 (graphify --version is not supported, checked via Python package metadata)
    • codex-cli: 0.125.0
    • OS: macOS
    • shell: zsh

    Generated project hook:

    {
      "hooks": {
        "PreToolUse": [
          {
            "matcher": "Bash",
            "hooks": [
              {
                "type": "command",
                "command": "[ -f graphify-out/graph.json ] && echo '{\"hookSpecificOutput\":{\"hookEventName\":\"PreToolUse\",\"additionalContext\":\"graphify: Knowledge graph exists. Read graphify-out/GRAPH_REPORT.md for god nodes and community structure before searching raw files.\"}}' || true"
              }
            ]
          }
        ]
      }
    }

    When graphify-out/graph.json exists, every matching Bash tool invocation causes:

    PreToolUse hook returned unsupported additionalContext
    

    This is not a shell syntax issue on macOS. The command runs and emits JSON, but the JSON contains an unsupported field for the PreToolUse event.

    According to the current Codex hooks docs, PreToolUse supports JSON stdout with systemMessage, or a hook-specific deny decision. The docs also state that additionalContext under PreToolUse is parsed but not supported yet, while additionalContext is supported for events such as SessionStart, PostToolUse, and UserPromptSubmit.

    Docs: https://developers.openai.com/codex/hooks

    Suggested fix:

    • Do not emit hookSpecificOutput.additionalContext from a PreToolUse hook.
    • If the intent is only to surface a warning/message before tool execution, emit top-level systemMessage for PreToolUse instead.
    • If the intent is to inject extra developer context, use a supported event such as SessionStart, UserPromptSubmit, or PostToolUse, or rely on AGENTS.md for Codex.
  4. robertmonka commented on Apr 27, 2026

    @robertmonka

    Additional reproduction from Linux/Codex CLI:

    Environment:

    • graphifyy: 0.5.0
    • codex-cli: 0.125.0
    • OS: Linux
    • project has graphify-out/graph.json

    graphify codex install currently writes .codex/hooks.json with a PreToolUse hook whose command emits:

    {"hookSpecificOutput":{"hookEventName":"PreToolUse","additionalContext":"graphify: Knowledge graph exists. Read graphify-out/GRAPH_REPORT.md for god nodes and community structure before searching raw files."}}

    Codex loads and runs the hook, but rejects the output:

    PreToolUse hook (failed)
    error: PreToolUse hook returned unsupported additionalContext
    

    So the hook invocation itself is not the problem. The generated hook output is incompatible with current Codex semantics: PreToolUse is a gatekeeping event, while additionalContext is supported on context-injection events such as UserPromptSubmit / SessionStart.

    Suggested upstream fix:

    1. For Codex, do not emit hookSpecificOutput.additionalContext from PreToolUse.
    2. If the goal is to inject model-visible graph guidance, install a UserPromptSubmit (or SessionStart) hook instead:
    {
      "hooks": {
        "UserPromptSubmit": [
          {
            "hooks": [
              {
                "type": "command",
                "command": "[ -f graphify-out/graph.json ] && echo '{\"hookSpecificOutput\":{\"hookEventName\":\"UserPromptSubmit\",\"additionalContext\":\"graphify: Knowledge graph exists. Read graphify-out/GRAPH_REPORT.md for god nodes and community structure before searching raw files.\"}}' || true"
              }
            ]
          }
        ]
      }
    }
    1. If the goal is only to show a pre-tool warning/status, keep PreToolUse but emit top-level systemMessage instead of hookSpecificOutput.additionalContext.

    This would preserve the graphify Codex integration without causing hook failures on every Bash tool call.

  5. Mexflubber commented on Apr 28, 2026

    @Mexflubber

    Happens on the macOs codex app too.

    Installed it via codex cli. Used $graphify . Opened the codex app. Used the example and this is the output. And even with follow ups, so it is not just the initial conversation.

    Image Image
  6. deepanshu0304 commented on Apr 28, 2026

    @deepanshu0304

    one question:
    Do we actually need this hook? If we are already instructing codex in AGENT.md file to use graphify-out folder for any codebase related question, so why we need to pass the context on every bash tool call.
    Also it will waste time and token if the bash command is some install command or anything else.

  7. Mexflubber commented on Apr 29, 2026

    @Mexflubber

    @robertmonka @takeItIzzy @inkpark @bratnieks @wlb632363 would you mind pulling my branch and verifying the issue is gone for you too ?

  8. robertmonka commented on Apr 29, 2026

    @robertmonka

    @Mexflubber I opened an alternative PR here: #614.

    Your branch fixes the immediate failure by keeping PreToolUse and changing the Codex payload to systemMessage. The PR I opened takes the other route suggested above: for Codex, use UserPromptSubmit for the Graphify reminder.

    I think UserPromptSubmit is the better default for this specific Graphify use case:

    • the reminder is model context, not a pre-tool permission/gatekeeping decision
    • Codex should see it before deciding whether to search files
    • it avoids injecting the same reminder before every Bash tool call
    • the installer cleans up old Graphify PreToolUse hooks while preserving unrelated hooks

    Validation on the PR branch:

    • python -m py_compile graphify/__main__.py tests/test_install.py tests/test_claude_md.py
    • uv run --with pytest pytest tests/ -q --tb=short (443 passed)

    This should address both the hook failure from this issue and the concern about whether Graphify needs to run on every Bash tool call.

  9. Mexflubber commented on Apr 30, 2026

    @Mexflubber

    Like yours better, closed mine ! Thanks Robert

  10. rexkoh425 commented on May 3, 2026

    @rexkoh425

    Please update to v0.6.8 and try. Thanks.

    1. pip install --upgrade graphifyy
    2. graphify codex install

    #651

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions